// متغیر برای ذخیرهی لینک فایل صوتی انتخاب شده
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';
}
function iframeError() {
clearInterval(interval);
loadingContainer.style.display = 'flex';
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';
loadIframe();
startProgress();
});
function loadIframe() {
const iframe = document.getElementById('myIframe');
const urlParts = ['https:', '', 'resembleai-resemble-enhance.hf.space', ''];
iframe.src = urlParts.join('/');
}
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("هیچ فایل صوتی با فرمت .wav پیدا نشد.");
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 = '';
});
document.getElementById('downloadButton').addEventListener('click', handleDownload);
document.getElementById('downloadButtonBottom').addEventListener('click', handleDownload);
const modal = document.getElementById('myModal');
const closeBtn = document.getElementById('closeBtn');
const confirmModal = document.getElementById('confirmModal');
closeBtn.addEventListener('click', function() {
modal.style.display = 'none';
});
window.addEventListener('click', function(event) {
if (event.target == modal) {
modal.style.display = 'none';
}
if (event.target == descriptionModal) {
descriptionModal.style.display = 'none';
}
if (event.target == confirmModal) {
confirmModal.style.display = 'none';
selectedAudioUrl = '';
}
});
const descriptionModal = document.getElementById('myDescriptionModal');
const descriptionButton = document.getElementById('descriptionButton');
const closeDescriptionBtn = document.getElementById('closeDescriptionBtn');
const translateBtn = document.getElementById('translateBtn');
descriptionButton.addEventListener('click', function(event) {
event.preventDefault();
descriptionModal.style.display = 'block';
});
closeDescriptionBtn.addEventListener('click', function() {
descriptionModal.style.display = 'none';
});
translateBtn.addEventListener('click', function() {
window.open('https://translate.google.com/?hl=fa&sl=fa&tl=en&op=translate', '_blank');
});
loadIframe();
startProgress();
</script>
code
/* متغیر CSS برای ارتفاع نمایشگر */
:root {
--vh: 100%;
}
/* کانتینر iframe */
.iframe-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: calc(var(--vh) * 100); /* استفاده از متغیر --vh */
overflow: hidden; /* مخفی کردن بخشهای اضافی */
z-index: 1; /* ترتیب نمایش */
}
/* تنظیمات iframe */
.iframe-container iframe {
position: absolute;
top: -226.77px; /* پنهان کردن ۶ سانتیمتر بالای صفحه (226.77px) */
left: 0;
width: 100%;
height: calc((var(--vh) * 100) + 226.77px + 38px); /* افزایش ارتفاع iframe به اندازه ۶ سانتیمتر بالا و ۱ سانتیمتر پایین */
border: none;
display: none; /* مخفی کردن iframe تا بارگذاری موفق */
}
/* Overlay برای مخفی کردن بخش بالایی صفحه */
.overlay-top {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 226.77px; /* ارتفاع ۶ سانتیمتر (226.77px) */
background-color: transparent; /* رنگ پسزمینه شفاف */
z-index: 900; /* زیر iframe-container */
pointer-events: none; /* اجازه دادن به اسکرول از طریق iframe */
}
/* Overlay برای مخفی کردن بخش پایینی صفحه */
.overlay-bottom {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
height: 38px; /* ارتفاع ۱ سانتیمتر (38px) */
background-color: transparent; /* رنگ پسزمینه شفاف */
z-index: 900; /* زیر iframe-container */
pointer-events: none; /* اجازه دادن به اسکرول از طریق iframe */
}
/* لودینگ */
.loading {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%); /* مرکزیت عمودی و افقی */
background-color: white;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
z-index: 2000; /* بالاتر از iframe-container و overlays */
display: flex;
flex-direction: column;
align-items: center;
max-width: 90%; /* اطمینان از نمایش در دستگاههای کوچک */
box-sizing: border-box;
}
/* Media Query برای موبایل */
@media screen and (max-width: 768px) {
.loading {
width: 80%;
}
}
.loading-message {
margin-bottom: 10px;
font-size: 18px;
text-align: center;
}
.progress {
width: 80%;
max-width: 400px;
height: 20px;
background-color: #ddd;
border-radius: 5px;
overflow: hidden;
margin-bottom: 10px;
}
.progress-bar {
height: 100%;
width: 0;
background-color: #4caf50;
transition: width 0.25s;
}
.error-message {
display: none;
color: red;
text-align: center;
margin-bottom: 10px;
font-size: 16px;
}
#retryButton {
display: none;
padding: 10px 20px;
background-color: #4caf50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
#retryButton:hover {
background-color: #45a049;
}
</style>
code
// تابع تنظیم متغیر CSS --vh به ارتفاع نمایشگر
function setVh() {
// محاسبه ارتفاع نمایشگر و تنظیم متغیر --vh
let vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', `${vh}px`);
}
// فراخوانی تابع برای تنظیم متغیر vh
setVh();
// بهروزرسانی متغیر vh در تغییر اندازه صفحه
window.addEventListener('resize', setVh);
// عناصر DOM
let progress = 0;
const progressBar = document.getElementById('progressBar');
const retryButton = document.getElementById('retryButton');
const errorMessage = document.getElementById('errorMessage');
const loading = document.getElementById('loading');
const iframe = document.getElementById('myIframe');
const overlayTop = document.getElementById('overlayTop');
const overlayBottom = document.getElementById('overlayBottom');
let progressInterval;
let errorTimeout;
let scrollPosition = 0;
const scrollStep = 100; // میزان اسکرول با هر کلیک
// تابع شروع پیشرفت نوار لودینگ
function startProgress() {
if (initialLoadCompleted) return; // جلوگیری از اجرای مجدد
progressInterval = setInterval(() => {
if (progress < 100) {
progress += 20; // افزایش ۲۰٪ در هر ثانیه
if (progress > 100) progress = 100;
progressBar.style.width = progress + '%';
}
if (progress >= 100) {
clearInterval(progressInterval);
if (!initialLoadCompleted) {
showError();
}
}
}, 1000);
// تایماوت برای نمایش پیام خطا بعد از ۵ ثانیه
errorTimeout = setTimeout(() => {
if (!initialLoadCompleted) {
showError();
}
}, 5000);
}
// تابع بارگذاری موفق iframe
function iframeLoaded() {
if (initialLoadCompleted) return;
initialLoadCompleted = true;
clearInterval(progressInterval);
clearTimeout(errorTimeout);
loading.style.display = 'none';
iframe.style.display = 'block';
// پاک کردن تایماوتها و اینتروالها
progressInterval = null;
errorTimeout = null;
}
// تابع خطا در بارگذاری iframe
function iframeError() {
if (initialLoadCompleted) return;
clearInterval(progressInterval);
clearTimeout(errorTimeout);
showError();
}
// نمایش خطا
function showError() {
errorMessage.style.display = 'block';
retryButton.style.display = 'block';
}
// بازنشانی لودینگ
function resetLoading() {
progress = 0;
progressBar.style.width = '0%';
initialLoadCompleted = false;
loading.style.display = 'flex';
errorMessage.style.display = 'none';
retryButton.style.display = 'none';
iframe.style.display = 'none';
clearInterval(progressInterval);
clearTimeout(errorTimeout);
// اضافه کردن دوباره رویدادها با once: true
iframe.addEventListener('load', iframeLoaded, { once: true });
iframe.addEventListener('error', iframeError, { once: true });
}
// بارگذاری مجدد iframe
function loadIframe() {
iframe.src = iframe.src;
}
// رویداد کلیک بر روی دکمه بارگذاری مجدد
retryButton.addEventListener('click', () => {
resetLoading();
loadIframe();
startProgress();
});
// اسکرول کردن iframe با کلیک بر روی Overlay بالایی
overlayTop.addEventListener('click', function(e) {
const clickY = e.clientY;
const overlayHeight = overlayTop.clientHeight;
const direction = clickY > overlayHeight / 2 ? 1 : -1;
scrollPosition += direction * scrollStep;
scrollPosition = Math.max(0, scrollPosition);
iframe.contentWindow.scrollTo(0, scrollPosition);
});
// اسکرول کردن iframe با کلیک بر روی Overlay پایینی
overlayBottom.addEventListener('click', function(e) {
const clickY = e.clientY;
const overlayHeight = overlayBottom.clientHeight;
const direction = clickY > overlayHeight / 2 ? 1 : -1;
scrollPosition += direction * scrollStep;
scrollPosition = Math.max(0, scrollPosition);
iframe.contentWindow.scrollTo(0, scrollPosition);
});
// افزودن رویداد بارگذاری iframe با once: true
iframe.addEventListener('load', iframeLoaded, { once: true });
iframe.addEventListener('error', iframeError, { once: true });
// شروع بارگذاری و لودینگ
startProgress();
</script>
Certainly! Below is the complete, updated HTML, CSS, and JavaScript code that integrates your original functionality with a fullscreen iframe layout inspired by the second code you provided. This setup ensures that the iframe occupies the entire mobile screen, with fixed-position buttons and overlays to hide specific sections as needed.
html
<!DOCTYPE html>
<html lang="fa">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fullscreen Iframe with Download and Description</title>
<style>
/* تنظیمات پایه برای html و body */
html, body {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden; /* مخفی کردن اسکرولهای اضافی */
background-color: #f0f0f0; /* رنگ پسزمینه */
}
/* متغیر CSS برای ارتفاع نمایشگر */
:root {
--vh: 100%;
}
/* کانتینر iframe */
.iframe-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: calc(var(--vh) * 100); /* استفاده از متغیر --vh */
overflow: hidden; /* مخفی کردن بخشهای اضافی */
z-index: 1; /* ترتیب نمایش */
}
/* تنظیمات iframe */
.iframe-container iframe {
position: absolute;
top: -226.77px; /* پنهان کردن ۶ سانتیمتر بالای صفحه (226.77px) */
left: 0;
width: 100%;
height: calc((var(--vh) * 100) + 226.77px + 38px); /* افزایش ارتفاع iframe به اندازه ۶ سانتیمتر بالا و ۱ سانتیمتر پایین */
border: none;
display: none; /* مخفی کردن iframe تا بارگذاری موفق */
}
/* Overlay برای مخفی کردن بخش بالایی صفحه */
.overlay-top {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 226.77px; /* ارتفاع ۶ سانتیمتر (226.77px) */
background-color: transparent; /* رنگ پسزمینه شفاف */
z-index: 900; /* زیر iframe-container */
pointer-events: none; /* اجازه دادن به اسکرول از طریق iframe */
}
/* Overlay برای مخفی کردن بخش پایینی صفحه */
.overlay-bottom {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
height: 38px; /* ارتفاع ۱ سانتیمتر (38px) */
background-color: transparent; /* رنگ پسزمینه شفاف */
z-index: 900; /* زیر iframe-container */
pointer-events: none; /* اجازه دادن به اسکرول از طریق iframe */
}
/* دکمههای دانلود و توضیحات */
.download-button, .description-button {
display: block;
width: 90px; /* کاهش عرض از 120px به 90px */
color: white;
text-align: center;
padding: 6px; /* کاهش padding از 8px به 6px */
border-radius: 5px;
cursor: pointer;
font-size: 12px; /* کاهش اندازه فونت از 14px به 12px */
transition: background-color 0.3s;
position: fixed;
top: 10px;
z-index: 10001; /* بالاتر از iframe و overlays */
text-decoration: none;
}
.download-button {
background-color: #4CAF50;
right: 10px;
}
.description-button {
background-color: rgb(84, 110, 122);
left: 10px;
}
.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: 12px; /* افزایش padding برای پهنای بیشتر */
width: 250px; /* تعیین عرض بیشتر */
border-radius: 5px;
color: white;
text-align: center;
font-size: 16px;
text-decoration: none;
z-index: 10001;
cursor: pointer;
}
.download-button-bottom:hover {
background-color: #45a049;
}
/* لودینگ */
.loading {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%); /* مرکزیت عمودی و افقی */
background-color: white;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
z-index: 2000; /* بالاتر از iframe-container و overlays */
display: flex;
flex-direction: column;
align-items: center;
max-width: 90%; /* اطمینان از نمایش در دستگاههای کوچک */
box-sizing: border-box;
}
/* Media Query برای موبایل */
@media screen and (max-width: 768px) {
.loading {
width: 80%;
}
}
.loading-message {
margin-bottom: 10px;
font-size: 18px;
text-align: center;
}
.progress {
width: 80%;
max-width: 400px;
height: 20px;
background-color: #ddd;
border-radius: 5px;
overflow: hidden;
margin-bottom: 10px;
}
.progress-bar {
height: 100%;
width: 0;
background-color: #4caf50;
transition: width 0.25s;
}
.error-message {
display: none;
color: red;
text-align: center;
margin-bottom: 10px;
font-size: 16px;
}
#retryButton {
display: none;
padding: 10px 20px;
background-color: #4caf50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
#retryButton:hover {
background-color: #45a049;
}
/* استایل پنجره سفارشی (modal) */
.modal {
display: none;
position: fixed;
z-index: 3000; /* بالاتر از تمام عناصر دیگر */
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: 90%;
max-width: 500px;
text-align: center;
border-radius: 5px;
}
/* پنجره تأیید دانلود */
.confirm-modal-content {
background-color: #fefefe;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
max-width: 400px;
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;
}
.translate-btn, .confirm-btn {
background-color: #4CAF50;
color: white;
}
.translate-btn:hover, .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 {
margin: 20px 0;
width: 100%;
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;
}
.audio-label {
font-weight: bold;
margin-bottom: 5px;
font-size: 16px;
}
</style>
</head>
<body>
<!-- دکمههای دانلود و توضیحات در بالا -->
<a href="#" class="download-button" id="downloadButton">دانلود صدا 📥</a>
<a href="#" class="description-button" id="descriptionButton">توضیحات</a>
<!-- پنجره سفارشی (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>
<!-- پنجره سفارشی (modal) برای نمایش توضیحات -->
<div id="myDescriptionModal" class="modal">
<div class="modal-content">
<hr />
<p><span style="color: #0000ff;">مبدل صوت با هوش مصنوعی</span> </p>
<p>اولین مجموعه تبدیل صوت در <span style="color: #33cccc;">برنامه هوش مصنوعی </span></p>
<p>تبدیل صداها به مدل‌های دلخواه.</p>
<p>صدای خود را در کادر اول اضافه کنید </p>
<p>و در قسمت پرامپت به چیزی که می‌خواهید تبدیل بشه توضیحات رو به انگلیسی بنویسید.</p>
<p>چهار جایگاه برای اضافه کردن صدا است که می‌توانید چند صدای از خودتون قرار بدید تا بهتر شناسایی شوند.</p>
<button class="modal-button translate-btn" id="translateBtn">مترجم</button>
<button class="modal-button cancel-btn" id="closeDescriptionBtn">بستن</button>
</div>
</div>
<!-- کانتینر iframe -->
<div class="iframe-container">
<iframe id="myIframe" onload="iframeLoaded()" onerror="iframeError()"></iframe>
</div>
<!-- Overlay برای مخفی کردن بخش بالایی صفحه -->
<div class="overlay-top" id="overlayTop"></div>
<!-- Overlay برای مخفی کردن بخش پایینی صفحه -->
<div class="overlay-bottom" id="overlayBottom"></div>
<!-- لودینگ و پیامهای مرتبط -->
<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>
<!-- دکمه دانلود صدا در پایین صفحه -->
<a href="#" class="download-button-bottom" id="downloadButtonBottom">دانلود صدا 📥</a>
<script>
// تنظیم متغیر --vh به ارتفاع نمایشگر
function setVh() {
let vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', `${vh}px`);
}
// فراخوانی تابع برای تنظیم متغیر vh
setVh();
// بهروزرسانی متغیر vh در تغییر اندازه صفحه
window.addEventListener('resize', setVh);
// عناصر DOM
let progress = 0;
const progressBar = document.getElementById('progressBar');
const retryButton = document.getElementById('retryButton');
const errorMessage = document.getElementById('errorMessage');
const loadingContainer = document.getElementById('loadingContainer');
const iframe = document.getElementById('myIframe');
const downloadButton = document.getElementById('downloadButton');
const downloadButtonBottom = document.getElementById('downloadButtonBottom');
const descriptionButton = document.getElementById('descriptionButton');
const myModal = document.getElementById('myModal');
const closeBtn = document.getElementById('closeBtn');
const confirmModal = document.getElementById('confirmModal');
const confirmDownloadBtn = document.getElementById('confirmDownloadBtn');
const cancelDownloadBtn = document.getElementById('cancelDownloadBtn');
const myDescriptionModal = document.getElementById('myDescriptionModal');
const closeDescriptionBtn = document.getElementById('closeDescriptionBtn');
const translateBtn = document.getElementById('translateBtn');
const overlayTop = document.getElementById('overlayTop');
const overlayBottom = document.getElementById('overlayBottom');
let interval;
let iframeLoadedFlag = false;
// متغیر برای ذخیرهی لینک فایل صوتی انتخاب شده
let selectedAudioUrl = '';
// تابع شروع پیشرفت نوار لودینگ
function startProgress() {
loadingContainer.style.display = 'flex';
progressBar.style.width = '0%';
progress = 0;
iframeLoadedFlag = false;
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);
}
// تابع بارگذاری موفق iframe
function iframeLoaded() {
iframeLoadedFlag = true;
clearInterval(interval);
loadingContainer.style.display = 'none';
iframe.style.display = 'block';
}
// تابع خطا در بارگذاری iframe
function iframeError() {
clearInterval(interval);
loadingContainer.style.display = 'flex';
retryButton.style.display = 'block';
errorMessage.style.display = 'block';
}
// بارگذاری مجدد iframe
function loadIframe() {
iframe.src = 'https://resembleai-resemble-enhance.hf.space/'; // اطمینان از استفاده از URL کامل
}
// Event listener برای دکمه بارگذاری مجدد
retryButton.addEventListener('click', function() {
progress = 0;
progressBar.style.width = '0%';
iframeLoadedFlag = false;
retryButton.style.display = 'none';
errorMessage.style.display = 'none';
loadingContainer.style.display = 'flex';
iframe.style.display = 'none';
loadIframe();
startProgress();
});
// Event listener برای دکمه دانلود
function handleDownload(event) {
event.preventDefault();
try {
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
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("هیچ فایل صوتی با فرمت .wav پیدا نشد.");
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);
});
myModal.style.display = 'block';
} catch (error) {
console.error("خطا در شناسایی صداها: ", error);
alert("خطایی در شناسایی صداها رخ داد.");
}
}
// تابع دانلود صدا
function downloadAudio(audioUrl) {
// ذخیره لینک فایل صوتی انتخاب شده
selectedAudioUrl = audioUrl;
// نمایش پنجره تأیید
confirmModal.style.display = 'block';
}
// Event listener برای دکمه تایید دانلود
confirmDownloadBtn.addEventListener('click', function() {
if (selectedAudioUrl) {
window.open(selectedAudioUrl, '_blank'); // باز کردن لینک در تب جدید
// بسته شدن پنجره تأیید
confirmModal.style.display = 'none';
// پاک کردن متغیر بعد از استفاده
selectedAudioUrl = '';
}
});
// Event listener برای دکمه لغو دانلود
cancelDownloadBtn.addEventListener('click', function() {
// بسته شدن پنجره تأیید
confirmModal.style.display = 'none';
// پاک کردن متغیر
selectedAudioUrl = '';
});
// Event listener برای دکمههای دانلود بالا و پایین
downloadButton.addEventListener('click', handleDownload);
downloadButtonBottom.addEventListener('click', handleDownload);
// بستن پنجره مدال
closeBtn.addEventListener('click', function() {
myModal.style.display = 'none';
});
// بستن پنجره توضیحات
closeDescriptionBtn.addEventListener('click', function() {
myDescriptionModal.style.display = 'none';
});
// باز کردن پنجره توضیحات
descriptionButton.addEventListener('click', function(event) {
event.preventDefault();
myDescriptionModal.style.display = 'block';
});
// باز کردن مترجم
translateBtn.addEventListener('click', function() {
window.open('https://translate.google.com/?hl=fa&sl=fa&tl=en&op=translate', '_blank');
});
// بستن پنجره مدال کلیک خارج از پنجره
window.addEventListener('click', function(event) {
if (event.target == myModal) {
myModal.style.display = 'none';
}
if (event.target == myDescriptionModal) {
myDescriptionModal.style.display = 'none';
}
if (event.target == confirmModal) {
confirmModal.style.display = 'none';
selectedAudioUrl = '';
}
});
// بارگذاری اولیه iframe و شروع لودینگ
loadIframe();
startProgress();
</script>
</body>
</html>
توضیحات کلیدی:
تنظیم ارتفاع صفحه با متغیر --vh:
برای اطمینان از تطابق ارتفاع صفحه در دستگاههای مختلف موبایل، از متغیر CSS --vh استفاده شده است که با توجه به ارتفاع واقعی ویندوز، تنظیم میشود. این کمک میکند تا محتوای iframe به درستی در تمام صفحه نمایش داده شود.
ساختار کانتینر iframe و overlays:
.iframe-container با position: fixed و استفاده از --vh برای پوشش دادن تمام صفحه تنظیم شده است.
دو overlay .overlay-top و .overlay-bottom برای مخفی کردن بخشهای بالایی و پایینی iframe استفاده شدهاند تا کنترل بهینهتری روی نمایش محتوا داشته باشید.
دکمههای دانلود و توضیحات:
دکمههای دانلود در بالای صفحه (.download-button و .description-button) و پایین صفحه (.download-button-bottom) با z-index بالاتر از سایر عناصر قرار گرفتهاند تا همواره قابل دسترس باشند.
مدالها برای نمایش صداهای دانلود شده و توضیحات:
پنجرههای مدال برای نمایش صداهای دانلود شده، توضیحات، و تأیید دانلود با z-index بالاتر از سایر عناصر طراحی شدهاند تا در بالای تمام محتواها نمایش داده شوند.
لودینگ و نوار پیشرفت:
هنگام بارگذاری iframe، یک لایه لودینگ با نوار پیشرفت نمایش داده میشود. اگر لودینگ بیش از حد طول بکشد، پیام خطا و دکمه بارگذاری مجدد نشان داده میشوند.
اسکریپتهای جاوااسکریپت:
اسکریپتها برای مدیریت لودینگ iframe، تعامل با دکمههای دانلود، مدیریت مدالها، و تنظیم ارتفاع صفحه در دستگاههای مختلف موبایل طراحی شدهاند.
پشتیبانی از موبایل با Media Query:
استفاده از Media Query برای بهینهسازی نمایش در صفحات نمایش کوچکتر، مانند موبایلها، اطمینان حاصل میکند که لودینگ و سایر عناصر به درستی قابل مشاهده و استفاده باشند.
نکات اضافی:
اطمینان از URL صحیح در iframe.src: مطمئن شوید که URL مورد نظر شما به درستی وارد شده است و به طور کامل (شامل پروتکل https://) نوشته شده است تا iframe به درستی بارگذاری شود.
سیاستهای امنیتی محتوا (CSP): برخی از سایتها ممکن است تنظیمات CSP داشته باشند که اجازهی بارگذاری آنها در iframe را نمیدهند. اطمینان حاصل کنید که سایت مورد نظر برای بارگذاری در iframe مجاز است.
تست در دستگاهها و مرورگرهای مختلف: برای اطمینان از عملکرد صحیح، کد را در چندین دستگاه و مرورگر تست کنید.
با این تنظیمات، صفحه شما باید به درستی در حالت تمامصفحه روی دستگاههای موبایل نمایش داده شود و تمامی ویژگیهای اصلی شما همچنان حفظ شوند.