o1-mini-2024-09-12· OpenAI
WildChat-4.8M (AI2)
به این کد من یک دکمه اسکرول اضافه <p> </p> <style> /* عمومی استایلها / html, body…
- User
به این کد من یک دکمه اسکرول اضافه
code - Assistant
به این کد من یک دکمه اسکرول اضافه
// متغیر برای ذخیرهی لینک فایل صوتی انتخاب شده
let selectedAudioUrl = '';
function startProgress() {
loadingContainer.style.display = 'flex'; // نمایش لودینگ
progressBar.style.width = '0%'; // ریست شدن نوار پیشرفت
progress = 0; // ریست پیشرفت
interval = setInterval(() => {
if (progress < 100) {
progress += 10;
progressBar.style.width = progress + '%';
}
if (progress === 100) {
clearInterval(interval);
if (!iframeLoadedFlag) {
retryButton.style.display = 'block';
errorMessage.style.display = 'block';
}
}
}, 1000);
}
function iframeLoaded() {
iframeLoadedFlag = true;
clearInterval(interval);
loadingContainer.style.display = 'none'; // مخفی کردن لودینگ
document.getElementById('myIframe').style.display = 'block'; // نمایش iframe
// نمایش دکمه دانلود پایین صفحه پس از بارگذاری موفق
document.getElementById('downloadButtonBottom').style.display = 'block';
}
function iframeError() {
clearInterval(interval);
retryButton.style.display = 'block';
errorMessage.style.display = 'block';
}
retryButton.addEventListener('click', function() {
progress = 0;
progressBar.style.width = '0%';
iframeLoadedFlag = false;
retryButton.style.display = 'none';
errorMessage.style.display = 'none';
loadingContainer.style.display = 'flex'; // بازگرداندن لودینگ
document.getElementById('myIframe').style.display = 'none'; // مخفی کردن iframe
loadIframe();
startProgress();
});
function loadIframe() {
const iframe = document.getElementById('myIframe');
// آدرس iframe خود را در اینجا تنظیم کنید
iframe.src = 'https://nick088-edge-tts.hf.space';
}
function handleDownload(event) {
event.preventDefault();
const iframe = document.getElementById('myIframe');
let iframeDocument;
try {
iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
} catch (error) {
console.error("دسترسی به محتوای iframe به دلیل محدودیتهای امنیتی امکانپذیر نیست.", error);
alert("دسترسی به محتوای iframe به دلیل محدودیتهای امنیتی امکانپذیر نیست.");
return;
}
try {
const links = iframeDocument.querySelectorAll('a');
if (links.length === 0) {
alert("هیچ لینک صوتی برای دانلود یافت نشد.");
return;
}
let wavFiles = [];
links.forEach((link) => {
const href = link.href;
if (href && href.toLowerCase().endsWith('.wav')) {
wavFiles.push(href);
}
});
if (wavFiles.length === 0) {
alert("هیچ فایل صوتی ساخته شده یافت نشد.");
return;
}
// محدود به دو فایل
wavFiles = wavFiles.slice(0, 2);
const audioContainer = document.getElementById('audioContainer');
audioContainer.innerHTML = '';
wavFiles.forEach((audioUrl, index) => {
const audioItem = document.createElement('div');
audioItem.classList.add('audio-item');
// تعیین برچسب بر اساس شماره پلیر
let labelText = '';
if (index === 0) {
labelText = 'خروجی صدا ';
} else if (index === 1) {
labelText = 'خروجی صدای پیشرفته';
}
audioItem.innerHTML = `
<p class="audio-label">${labelText}</p>
<audio controls class="audio-player">
<source src="${audioUrl}" type="audio/wav">
مرورگر شما از پخش این فایل صوتی پشتیبانی نمیکند.
</audio>
<button class="download-audio-button" onclick="downloadAudio('${audioUrl}')">دانلود صدا</button>
`;
audioContainer.appendChild(audioItem);
});
document.getElementById('myModal').style.display = 'block';
} catch (error) {
console.error("خطا در شناسایی صداها: ", error);
alert("خطایی در شناسایی صداها رخ داد.");
}
}
function downloadAudio(audioUrl) {
// ذخیره لینک فایل صوتی انتخاب شده
selectedAudioUrl = audioUrl;
// نمایش پنجره تأیید
document.getElementById('confirmModal').style.display = 'block';
}
// Event listener برای دکمه تایید دانلود
document.getElementById('confirmDownloadBtn').addEventListener('click', function() {
if (selectedAudioUrl) {
window.open(selectedAudioUrl, '_blank'); // باز کردن لینک در تب جدید
// بسته شدن پنجره تأیید
document.getElementById('confirmModal').style.display = 'none';
// پاک کردن متغیر بعد از استفاده
selectedAudioUrl = '';
}
});
// Event listener برای دکمه لغو دانلود
document.getElementById('cancelDownloadBtn').addEventListener('click', function() {
// بسته شدن پنجره تأیید
document.getElementById('confirmModal').style.display = 'none';
// پاک کردن متغیر
selectedAudioUrl = '';
});
// Event listeners برای دکمه دریافت صدا
document.getElementById('downloadButton').addEventListener('click', handleDownload);
document.getElementById('downloadButtonBottom').addEventListener('click', handleDownload);
// بستن پنجره مودالها با کلیک خارج از آنها
window.addEventListener('click', function(event) {
const modals = ['myModal', 'myDescriptionModal', 'confirmModal'];
modals.forEach(modalId => {
const modal = document.getElementById(modalId);
if (event.target == modal) {
modal.style.display = 'none';
}
});
});
// مدیریت پنجره توضیحات
const descriptionModal = document.getElementById('myDescriptionModal');
const descriptionButton = document.getElementById('descriptionButton');
const closeDescriptionBtn = document.getElementById('closeDescriptionBtn');
descriptionButton.addEventListener('click', function(event) {
event.preventDefault();
descriptionModal.style.display = 'block';
});
closeDescriptionBtn.addEventListener('click', function() {
descriptionModal.style.display = 'none';
});
// مدیریت پنجره بستن مودال صدا
const myModal = document.getElementById('myModal');
const closeBtn = document.getElementById('closeBtn');
closeBtn.addEventListener('click', function() {
myModal.style.display = 'none';
});
// اجرای بارگذاری iframe و آغاز لودینگ
loadIframe();
startProgress();
</script>
.iframe-container {
position: relative;
width: 100%;
height: 100vh;
overflow: hidden;
}
iframe {
width: 100%;
height: 100%;
border: none;
display: none;
position: relative;
top: 0;
/* اضافه کردن ویژگیهای sandbox و allow */
sandbox="allow-scripts allow-same-origin allow-forms allow-modals"
allow="clipboard-read; clipboard-write"
}
.loading {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-direction: column;
align-items: center;
z-index: 10000;
}
.loading-message {
margin-bottom: 20px;
font-size: 18px;
}
.progress {
width: 80%;
max-width: 400px;
height: 20px;
background-color: #ddd;
border-radius: 5px;
overflow: hidden;
}
.progress-bar {
height: 100%;
width: 0;
background-color: #4caf50;
transition: width 1s;
}
.error-message {
display: none;
color: red;
margin-top: 20px;
font-size: 16px;
text-align: center;
}
#retryButton {
display: none;
margin-top: 10px;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
background-color: #4caf50;
color: white;
border: none;
border-radius: 5px;
}
/* دکمه دانلود صدا در پایین صفحه */
.download-button-bottom {
position: fixed;
bottom: 10px;
left: 50%;
transform: translateX(-50%);
background-color: #4CAF50;
padding: 15px 50px;
border-radius: 5px;
color: white;
text-align: center;
font-size: 14px;
text-decoration: none;
z-index: 10001;
cursor: pointer;
min-width: 250px;
width: auto;
white-space: nowrap;
transition: background-color 0.3s;
display: none; /* مخفی تا زمانی که iframe بارگذاری شود */
}
.download-button-bottom:hover {
background-color: #45a049;
}
/* استایل پنجره سفارشی (modal) */
.modal {
display: none;
position: fixed;
z-index: 10002;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
}
.modal-content {
background-color: #fefefe;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
max-width: 500px;
text-align: center;
border-radius: 5px;
}
.modal-button {
margin-top: 20px;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
}
.cancel-btn {
background-color: #f44336;
color: white;
}
.image-container {
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.image-item {
margin: 10px;
text-align: center;
}
.image-item img {
width: 80px;
height: 80px;
object-fit: cover;
border-radius: 5px;
margin-bottom: 5px;
}
.image-item button {
background-color: #4CAF50;
color: white;
padding: 5px 10px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 12px;
}
.image-item button:hover {
background-color: #45a049;
}
/* استایل دکمه اسکرول */
.scroll-handle {
position: fixed;
right: 15px;
top: 50%;
transform: translateY(-50%);
z-index: 9999;
width: 45px;
height: 45px;
border-radius: 50%;
background-color: rgba(0, 0, 0, 0.4);
color: white;
border: none;
cursor: grab;
display: none; /* مخفی تا زمانی که iframe بارگذاری شود */
align-items: center;
justify-content: center;
font-size: 24px;
transition: all 0.3s;
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
.scroll-handle:active {
cursor: grabbing;
background-color: rgba(0, 0, 0, 0.6);
box-shadow: 0 3px 8px rgba(0,0,0,0.3);
}
@media (max-width: 768px) {
.scroll-handle {
right: 10px;
width: 40px;
height: 40px;
font-size: 22px;
}
}
@keyframes pulse {
0% { transform: translateY(-50%) scale(1); }
50% { transform: translateY(-50%) scale(1.1); }
100% { transform: translateY(-50%) scale(1); }
}
.scroll-handle:hover {
animation: pulse 1s infinite;
}
</style>
let progress = 0;
const progressBar = document.getElementById('progressBar');
const retryButton = document.getElementById('retryButton');
const errorMessage = document.getElementById('errorMessage');
const loadingContainer = document.getElementById('loadingContainer');
let interval;
let iframeLoadedFlag = false;
function startProgress() {
loadingContainer.style.display = 'flex';
progressBar.style.width = '0%';
progress = 0;
interval = setInterval(() => {
if (progress < 100) {
progress += 10;
progressBar.style.width = progress + '%';
}
if (progress === 100) {
clearInterval(interval);
if (!iframeLoadedFlag) {
retryButton.style.display = 'block';
errorMessage.style.display = 'block';
}
}
}, 1000);
}
function iframeLoaded() {
iframeLoadedFlag = true;
clearInterval(interval);
loadingContainer.style.display = 'none';
document.getElementById('myIframe').style.display = 'block';
// نمایش دکمه دانلود پایین صفحه پس از بارگذاری موفق
document.getElementById('downloadButtonBottom').style.display = 'block';
// نمایش دکمه اسکرول پس از بارگذاری موفق
const scrollButton = document.querySelector('.scroll-handle');
scrollButton.style.display = 'flex';
setupScrollHandle();
}
function iframeError() {
clearInterval(interval);
loadingContainer.style.display = 'flex';
retryButton.style.display = 'block';
errorMessage.style.display = 'block';
}
function loadIframe() {
fetch(siteURL, { method: 'HEAD', mode: 'no-cors' })
.then(() => {
const iframe = document.getElementById('myIframe');
iframe.src = siteURL;
iframe.onload = iframeLoaded;
iframe.onerror = iframeError;
})
.catch(() => {
iframeError();
});
}
retryButton.addEventListener('click', function() {
progress = 0;
progressBar.style.width = '0%';
iframeLoadedFlag = false;
retryButton.style.display = 'none';
errorMessage.style.display = 'none';
loadingContainer.style.display = 'flex';
document.getElementById('myIframe').style.display = 'none';
loadIframe();
startProgress();
});
// مدیریت پنجرههای مدال
const imageModal = document.getElementById('myModal');
const closeBtn = document.getElementById('closeBtn');
closeBtn.addEventListener('click', function() {
imageModal.style.display = 'none';
});
window.addEventListener('click', function(event) {
if (event.target == imageModal) {
imageModal.style.display = 'none';
}
});
// مدیریت دکمه دانلود با استفاده از alert
const downloadButton = document.getElementById('downloadButtonBottom');
downloadButton.addEventListener('click', function(event) {
event.preventDefault(); // جلوگیری از عمل پیشفرض لینک
alert('ربات تبدیل تصویر به پرامپت.');
// اگر میخواهید کار دیگری هم انجام دهید، میتوانید کدهای لازم را اینجا اضافه کنید
});
// فراخوانی عملکرد دکمه اسکرول پس از بارگذاری iframe
function setupScrollHandle() {
const scrollHandle = document.querySelector('.scroll-handle');
const iframe = document.getElementById('myIframe');
let isDragging = false;
let startY = 0;
let startScrollY = 0;
scrollHandle.addEventListener('mousedown', startDragging);
scrollHandle.addEventListener('touchstart', startDragging);
document.addEventListener('mousemove', drag);
document.addEventListener('touchmove', drag);
document.addEventListener('mouseup', stopDragging);
document.addEventListener('touchend', stopDragging);
function startDragging(e) {
isDragging = true;
startY = e.clientY || e.touches[0].clientY;
if (iframe.contentWindow) {
startScrollY = iframe.contentWindow.pageYOffset || iframe.contentWindow.scrollY;
} else {
startScrollY = 0;
}
scrollHandle.style.cursor = 'grabbing';
}
function drag(e) {
if (!isDragging) return;
e.preventDefault();
const y = e.clientY || e.touches[0].clientY;
const walk = (y - startY) * 2; // سرعت اسکرول
if (iframe.contentWindow) {
iframe.contentWindow.scrollTo(0, startScrollY - walk);
}
}
function stopDragging() {
isDragging = false;
scrollHandle.style.cursor = 'grab';
}
}
// اجرای بارگذاری iframe و آغاز لودینگ
loadIframe();
startProgress();
</script>
البته! من کد شما را با اضافه کردن یک دکمه اسکرول مشابه نمونهای که ارائه دادید، بهروزرسانی کردهام. قسمتهای اضافه شده را مشخص کردهام تا بتوانید تغییرات را بهخوبی مشاهده کنید.
<p> </p>
<style>
/* عمومی استایلها */
html, body {
margin: 0;
padding: 0;
background-color: #f0f0f0;
font-family: Arial, sans-serif;
height: 100vh;
overflow: hidden;
scroll-behavior: smooth; /* اضافه کردن اسکرول نرم */
}
/* کانتینر iframe */
.iframe-container {
position: relative;
width: 100%;
height: 100vh;
overflow: hidden;
}
iframe {
width: 100%;
height: calc(100% + 113.4px); /* تغییر ارتفاع برای مخفی کردن 3 سانتیمتر */
border: none;
display: none; /* مخفی کردن iframe تا بارگذاری شود */
position: relative;
top: -113.4px; /* مخفی کردن 3 سانتیمتر از بالای صفحه */
}
/* لودینگ و پروگرس بار */
.loading {
position: fixed; /* قرارگیری روی کل صفحه */
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-direction: column;
align-items: center;
z-index: 10000;
/* حذف پسزمینه و سایر استایلهای اضافی */
}
.loading-message {
margin-bottom: 20px;
font-size: 18px;
text-align: center;
}
.progress {
width: 80%;
max-width: 400px;
height: 20px;
background-color: #ddd;
border-radius: 5px;
overflow: hidden;
}
.progress-bar {
height: 100%;
width: 0;
background-color: #4caf50;
transition: width 1s;
}
.error-message {
display: none;
color: red;
margin-top: 20px;
font-size: 16px;
text-align: center;
}
#retryButton {
display: none;
margin-top: 10px;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
background-color: #4caf50;
color: white;
border: none;
border-radius: 5px;
}
/* دکمههای دانلود و توضیحات */
.download-button, .description-button {
display: block;
width: 100px; /* کاهش عرض دکمه */
color: white;
text-align: center;
padding: 8px; /* کاهش پدینگ */
border-radius: 5px;
cursor: pointer;
font-size: 12px; /* کاهش اندازه فونت */
transition: background-color 0.3s;
position: fixed;
top: 10px;
z-index: 10001;
text-decoration: none;
}
.download-button {
background-color: #4CAF50;
right: 10px; /* موقعیت fixed در سمت راست */
}
.description-button {
background-color: rgb(84, 110, 122);
left: 10px; /* موقعیت fixed در سمت چپ */
}
.download-button:hover, .description-button:hover {
background-color: #45a049;
}
/* دکمه دانلود در پایین صفحه */
.download-button-bottom {
position: fixed;
bottom: 10px;
left: 50%;
transform: translateX(-50%);
background-color: #4CAF50;
padding: 14px 24px; /* افزایش پدینگ عمودی و افقی برای اندازه بیشتر */
border-radius: 5px;
color: white;
text-align: center;
font-size: 16px;
text-decoration: none;
z-index: 10001;
cursor: pointer;
box-sizing: border-box; /* شامل شدن پدینگ در محاسبه عرض */
display: none; /* مخفی کردن دکمه در ابتدا */
width: 250px; /* افزایش عرض دکمه از 200px به 250px */
}
.download-button-bottom:hover {
background-color: #45a049;
}
/* پنجرههای مودال */
.modal {
display: none;
position: fixed;
z-index: 10002;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
}
.modal-content, .confirm-modal-content {
background-color: #fefefe;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
max-width: 500px;
text-align: center;
border-radius: 5px;
}
.confirm-modal-content {
max-width: 400px;
}
.modal-button {
margin-top: 20px;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
}
.cancel-btn {
background-color: #f44336;
color: white;
}
.confirm-btn {
background-color: #4CAF50;
color: white;
}
.confirm-btn:hover {
background-color: #45a049;
}
.canceled-btn {
background-color: #f44336;
color: white;
}
.canceled-btn:hover {
background-color: #d32f2f;
}
/* استایل برای نمایش صداها در مودال */
.audio-container {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 15px;
}
.audio-item {
display: flex;
flex-direction: column;
align-items: center;
margin: 20px 0;
width: 100%;
text-align: center;
}
.audio-label {
font-weight: bold;
margin-bottom: 5px;
font-size: 16px;
text-align: center;
}
.audio-player {
width: 80%;
margin-bottom: 10px;
}
.download-audio-button {
background-color: #4CAF50;
color: white;
padding: 8px 16px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
}
.download-audio-button:hover {
background-color: #45a049;
}
/* تنظیمات برای صفحات بسیار کوچک */
@media (max-width: 300px) {
.download-button-bottom {
width: 90%;
}
}
/* استایل دکمه اسکرول اضافهشده */
.scroll-handle {
position: fixed;
right: 15px;
top: 50%;
transform: translateY(-50%);
z-index: 9999;
width: 45px;
height: 45px;
border-radius: 50%;
background-color: rgba(0, 0, 0, 0.4);
color: white;
border: none;
cursor: grab;
display: none; /* مخفی تا زمانی که iframe بارگذاری شود */
align-items: center;
justify-content: center;
font-size: 24px;
transition: all 0.3s;
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
.scroll-handle:active {
cursor: grabbing;
background-color: rgba(0, 0, 0, 0.6);
box-shadow: 0 3px 8px rgba(0,0,0,0.3);
}
@media (max-width: 768px) {
.scroll-handle {
right: 10px;
width: 40px;
height: 40px;
font-size: 22px;
}
}
@keyframes pulse {
0% { transform: translateY(-50%) scale(1); }
50% { transform: translateY(-50%) scale(1.1); }
100% { transform: translateY(-50%) scale(1); }
}
.scroll-handle:hover {
animation: pulse 1s infinite;
}
</style>
<!-- دکمههای دانلود و توضیحات -->
<p style="margin: 10px;">
<a href="#" class="download-button" id="downloadButton">دانلود 📥</a>
<a href="#" class="description-button" id="descriptionButton">توضیحات</a>
</p>
<!-- پنجره سفارشی (modal) برای توضیحات -->
<div id="myDescriptionModal" class="modal">
<div class="modal-content">
<hr />
<p style="text-align: center;">نسخه پیشرفته تبدیل به صدا با <span style="color: #008080;">هوش مصنوعی </span></p>
<p style="text-align: center;">برای نمایش زبان فارسی قسمت جستجو در کادر بنویسید pers</p>
<p style="text-align: center;">برای استفاده از صدای های طبیعی </p>
<p style="text-align: center;">بعد از دریافت فایل صوتی میتونید برید قسمت تغییر صدا با استفاده از مدل های تغییر صدا فایل صوتی رو به صدا های طبیعی و صدای مورد نظر (صدای افراد مشهور) تبدیل کنید.</p>
<p style="text-align: center;"> </p>
<button class="modal-button cancel-btn" id="closeDescriptionBtn">بستن</button>
</div>
</div>
<!-- پنجره سفارشی (modal) برای نمایش صداهای دانلود شده -->
<div id="myModal" class="modal">
<div class="modal-content">
<p style="text-align: center;">صداهای شناسایی شده</p>
<div class="audio-container" id="audioContainer"><!-- پلیرهای صدا در اینجا قرار خواهند گرفت --></div>
<button class="modal-button cancel-btn" id="closeBtn">بستن</button>
</div>
</div>
<!-- پنجره تأیید دانلود -->
<div id="confirmModal" class="modal">
<div class="confirm-modal-content">
<p>برای دانلود فایل صوتی روی تایید کلیک کنید و بعد از باز شدن مرورگر سمت راست فایل کلیک کنید و بارگیری فایل را انتخاب کنید.</p>
<button class="modal-button confirm-btn" id="confirmDownloadBtn">تایید</button>
<button class="modal-button canceled-btn" id="cancelDownloadBtn">لغو</button>
</div>
</div>
<!-- لودینگ و iframe -->
<div class="iframe-container">
<div class="loading" id="loadingContainer">
<div class="loading-message">لطفاً صبر کنید...</div>
<div class="progress">
<div class="progress-bar" id="progressBar"></div>
</div>
<div class="error-message" id="errorMessage">
بارگیری زیاد طول کشید.<br />در صورت عدم بارگذاری، فیلترشکن خود را روشن کنید.
</div>
<button id="retryButton">بارگذاری مجدد</button>
</div>
<iframe id="myIframe" onload="iframeLoaded()" onerror="iframeError()"></iframe>
</div>
<!-- دکمه دانلود صدا در پایین صفحه -->
<p>
<a href="#" class="download-button-bottom" id="downloadButtonBottom">دانلود صدا 📥</a>
</p>
<!-- دکمه اسکرول اضافهشده -->
<p>
<button class="scroll-handle" title="برای اسکرول بکشید" role="button" aria-label="دکمه اسکرول">👆</button>
</p>
<script>
let progress = 0;
const progressBar = document.getElementById('progressBar');
const retryButton = document.getElementById('retryButton');
const errorMessage = document.getElementById('errorMessage');
const loadingContainer = document.getElementById('loadingContainer');
let interval;
let iframeLoadedFlag = false;
// متغیر برای ذخیرهی لینک فایل صوتی انتخاب شده
let selectedAudioUrl = '';
function startProgress() {
loadingContainer.style.display = 'flex'; // نمایش لودینگ
progressBar.style.width = '0%'; // ریست شدن نوار پیشرفت
progress = 0; // ریست پیشرفت
interval = setInterval(() => {
if (progress < 100) {
progress += 10;
progressBar.style.width = progress + '%';
}
if (progress === 100) {
clearInterval(interval);
if (!iframeLoadedFlag) {
retryButton.style.display = 'block';
errorMessage.style.display = 'block';
}
}
}, 1000);
}
function iframeLoaded() {
iframeLoadedFlag = true;
clearInterval(interval);
loadingContainer.style.display = 'none'; // مخفی کردن لودینگ
document.getElementById('myIframe').style.display = 'block'; // نمایش iframe
// نمایش دکمه دانلود پایین صفحه پس از بارگذاری موفق
document.getElementById('downloadButtonBottom').style.display = 'block';
// نمایش دکمه اسکرول پس از بارگذاری موفق
const scrollButton = document.querySelector('.scroll-handle');
scrollButton.style.display = 'flex';
setupScrollHandle(); // فراخوانی تابع تنظیمات دکمه اسکرول
}
function iframeError() {
clearInterval(interval);
retryButton.style.display = 'block';
errorMessage.style.display = 'block';
}
function loadIframe() {
const iframe = document.getElementById('myIframe');
// آدرس iframe خود را در اینجا تنظیم کنید
iframe.src = 'https://nick088-edge-tts.hf.space';
}
function handleDownload(event) {
event.preventDefault();
const iframe = document.getElementById('myIframe');
let iframeDocument;
try {
iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
} catch (error) {
console.error("دسترسی به محتوای iframe به دلیل محدودیتهای امنیتی امکانپذیر نیست.", error);
alert("دسترسی به محتوای iframe به دلیل محدودیتهای امنیتی امکانپذیر نیست.");
return;
}
try {
const links = iframeDocument.querySelectorAll('a');
if (links.length === 0) {
alert("هیچ لینک صوتی برای دانلود یافت نشد.");
return;
}
let wavFiles = [];
links.forEach((link) => {
const href = link.href;
if (href && href.toLowerCase().endsWith('.wav')) {
wavFiles.push(href);
}
});
if (wavFiles.length === 0) {
alert("هیچ فایل صوتی ساخته شده یافت نشد.");
return;
}
// محدود به دو فایل
wavFiles = wavFiles.slice(0, 2);
const audioContainer = document.getElementById('audioContainer');
audioContainer.innerHTML = '';
wavFiles.forEach((audioUrl, index) => {
const audioItem = document.createElement('div');
audioItem.classList.add('audio-item');
// تعیین برچسب بر اساس شماره پلیر
let labelText = '';
if (index === 0) {
labelText = 'خروجی صدا ';
} else if (index === 1) {
labelText = 'خروجی صدای پیشرفته';
}
audioItem.innerHTML = `
<p class="audio-label">${labelText}</p>
<audio controls class="audio-player">
<source src="${audioUrl}" type="audio/wav">
مرورگر شما از پخش این فایل صوتی پشتیبانی نمیکند.
</audio>
<button class="download-audio-button" onclick="downloadAudio('${audioUrl}')">دانلود صدا</button>
`;
audioContainer.appendChild(audioItem);
});
document.getElementById('myModal').style.display = 'block';
} catch (error) {
console.error("خطا در شناسایی صداها: ", error);
alert("خطایی در شناسایی صداها رخ داد.");
}
}
function downloadAudio(audioUrl) {
// ذخیره لینک فایل صوتی انتخاب شده
selectedAudioUrl = audioUrl;
// نمایش پنجره تأیید
document.getElementById('confirmModal').style.display = 'block';
}
// Event listener برای دکمه تایید دانلود
document.getElementById('confirmDownloadBtn').addEventListener('click', function() {
if (selectedAudioUrl) {
window.open(selectedAudioUrl, '_blank'); // باز کردن لینک در تب جدید
// بسته شدن پنجره تأیید
document.getElementById('confirmModal').style.display = 'none';
// پاک کردن متغیر بعد از استفاده
selectedAudioUrl = '';
}
});
// Event listener برای دکمه لغو دانلود
document.getElementById('cancelDownloadBtn').addEventListener('click', function() {
// بسته شدن پنجره تأیید
document.getElementById('confirmModal').style.display = 'none';
// پاک کردن متغیر
selectedAudioUrl = '';
});
// Event listeners برای دکمه دریافت صدا
document.getElementById('downloadButton').addEventListener('click', handleDownload);
document.getElementById('downloadButtonBottom').addEventListener('click', handleDownload);
// بستن پنجره مودالها با کلیک خارج از آنها
window.addEventListener('click', function(event) {
const modals = ['myModal', 'myDescriptionModal', 'confirmModal'];
modals.forEach(modalId => {
const modal = document.getElementById(modalId);
if (event.target == modal) {
modal.style.display = 'none';
}
});
});
// مدیریت پنجره توضیحات
const descriptionModal = document.getElementById('myDescriptionModal');
const descriptionButton = document.getElementById('descriptionButton');
const closeDescriptionBtn = document.getElementById('closeDescriptionBtn');
descriptionButton.addEventListener('click', function(event) {
event.preventDefault();
descriptionModal.style.display = 'block';
});
closeDescriptionBtn.addEventListener('click', function() {
descriptionModal.style.display = 'none';
});
// مدیریت پنجره بستن مودال صدا
const myModal = document.getElementById('myModal');
const closeBtn = document.getElementById('closeBtn');
closeBtn.addEventListener('click', function() {
myModal.style.display = 'none';
});
// تابع تنظیمات دکمه اسکرول اضافهشده
function setupScrollHandle() {
const scrollHandle = document.querySelector('.scroll-handle');
const iframe = document.getElementById('myIframe');
let isDragging = false;
let startY = 0;
let startScrollY = 0;
scrollHandle.addEventListener('mousedown', startDragging);
scrollHandle.addEventListener('touchstart', startDragging);
document.addEventListener('mousemove', drag);
document.addEventListener('touchmove', drag);
document.addEventListener('mouseup', stopDragging);
document.addEventListener('touchend', stopDragging);
function startDragging(e) {
isDragging = true;
startY = e.clientY || e.touches[0].clientY;
if (iframe.contentWindow) {
startScrollY = iframe.contentWindow.pageYOffset || iframe.contentWindow.scrollY;
} else {
startScrollY = 0;
}
scrollHandle.style.cursor = 'grabbing';
}
function drag(e) {
if (!isDragging) return;
e.preventDefault();
const y = e.clientY || e.touches[0].clientY;
const walk = (y - startY) * 2; // سرعت اسکرول
if (iframe.contentWindow) {
iframe.contentWindow.scrollTo(0, startScrollY - walk);
}
}
function stopDragging() {
isDragging = false;
scrollHandle.style.cursor = 'grab';
}
}
// اجرای بارگذاری iframe و آغاز لودینگ
loadIframe();
startProgress();
</script>
استایل دکمه اسکرول:
.scroll-handle هستند از کد نمونه دوم به استایلهای اصلی اضافه شدهاند.hover و active.HTML دکمه اسکرول:
scroll-handle اضافه شده است:<p>
<button class="scroll-handle" title="برای اسکرول بکشید" role="button" aria-label="دکمه اسکرول">👆</button>
</p>
جاوااسکریپت برای مدیریت اسکرول:
setupScrollHandle اضافه شده است که مسئول مدیریت رویدادهای مربوط به درگ و اسکرول داخل iframe است.iframeLoaded فراخوانی میشود تا پس از بارگذاری موفقیتآمیز iframe، دکمه اسکرول نمایش داده شود و آماده به کار باشد.نمایش دکمه اسکرول پس از بارگذاری iframe:
iframeLoaded، علاوه بر نمایش دکمه دانلود پایین صفحه، دکمه اسکرول نیز نمایش داده میشود و تابع تنظیمات اسکرول فراخوانی میگردد:function iframeLoaded() {
iframeLoadedFlag = true;
clearInterval(interval);
loadingContainer.style.display = 'none'; // مخفی کردن لودینگ
document.getElementById('myIframe').style.display = 'block'; // نمایش iframe
// نمایش دکمه دانلود پایین صفحه پس از بارگذاری موفق
document.getElementById('downloadButtonBottom').style.display = 'block';
// نمایش دکمه اسکرول پس از بارگذاری موفق
const scrollButton = document.querySelector('.scroll-handle');
scrollButton.style.display = 'flex';
setupScrollHandle(); // فراخوانی تابع تنظیمات دکمه اسکرول
}
محدودیتهای امنیتی iframe:
تست عملکرد:
سازگاری با دستگاههای لمسی:
touchstart, touchmove, و touchend نیز برای پشتیبانی از دستگاههای لمسی اضافه شدهاند، اما ممکن است نیاز به تنظیمات بیشتری داشته باشید بسته به نیازهای خاص شما.امیدوارم این تغییرات به شما کمک کند تا دکمه اسکرول مورد نظر خود را بهدرستی به کد اضافه کنید. در صورت وجود هرگونه سوال یا نیاز به کمک بیشتر، خوشحال میشوم که راهنماییتان کنم!
Not yet included in a published release.