<p> </p> <style> body { margin: 0; padding: 0; background-color: #f0f0f0;…
- Usercode
- Assistant
.iframe-container {
position: relative;
width: 100%;
height: 600px; /* تنظیم ارتفاع مناسب برای iframe */
overflow: hidden;
margin: 20px 0;
}
iframe {
width: 100%;
height: 100%;
border: none;
display: none; /* مخفی کردن iframe تا بارگذاری شود */
position: relative;
}
.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: 90px;
color: white;
text-align: center;
padding: 6px;
border-radius: 5px;
cursor: pointer;
font-size: 12px;
transition: background-color 0.3s;
position: fixed; /* حفظ موقعیت 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;
}
/* استایل پنجره سفارشی (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, .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;
}
.download-button-bottom {
position: fixed; /* باقی ماندن در موقعیت fixed */
bottom: 10px;
left: 50%;
transform: translateX(-50%);
background-color: #4CAF50;
padding: 16px 20px; /* افزایش پدینگ عمودی از 12px به 16px */
max-width: 90%;
width: 250px; /* عرض ثابت، قابل تنظیم */
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; /* مخفی کردن دکمه در ابتدا */
}
.download-button-bottom:hover {
background-color: #45a049;
}
/* تنظیمات برای صفحات بسیار کوچک */
@media (max-width: 300px) {
.download-button-bottom {
width: 90%;
}
}
</style>
// متغیر برای ذخیرهی لینک فایل صوتی انتخاب شده
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 خود را در اینجا تنظیم کنید
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("هیچ فایل صوتی ساخته شده یافت نشد.");
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: calc(100% + 5.5cm); /* اضافه کردن ۵.۵ سانتیمتر به ارتفاع */
border: none;
display: none; /* مخفی تا زمانی که سایت بارگذاری شود */
position: relative;
top: -5.5cm; /* مخفی کردن ۵.۵ سانتیمتر از بالا */
}
.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, .description-button {
display: block;
width: 120px;
color: white;
text-align: center;
padding: 6px;
border-radius: 5px;
cursor: pointer;
font-size: 11px;
transition: background-color 0.3s;
position: fixed;
top: 10px;
z-index: 10001;
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: 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;
}
.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 {
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 {
background-color: #4CAF50;
color: white;
}
.translate-btn:hover {
background-color: #45a049;
}
.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;
}
/* اضافه کردن فاصله برای مخفی کردن بالای صفحه */
@media (max-width: 768px) {
iframe {
height: calc(100% + 5.5cm);
top: -5.5cm;
}
}
</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';
}
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();
});
}
function handleDownload(event) {
event.preventDefault();
const iframe = document.getElementById('myIframe');
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
try {
const images = iframeDocument.querySelectorAll('img');
if (images.length === 0) {
alert("هیچ تصویری با فرمت JPG برای دانلود یافت نشد.");
return;
}
let jpgImages = [];
images.forEach((img) => {
if (img.src.toLowerCase().endsWith('.jpg') && !excludeUrls.includes(img.src)) {
jpgImages.push(img.src);
}
});
jpgImages = jpgImages.slice(0, 4);
if (jpgImages.length === 0) {
alert("هیچ تصویر ساخته شدهای یافت نشد.");
return;
}
const imageContainer = document.getElementById('imageContainer');
imageContainer.innerHTML = '';
jpgImages.forEach((imageUrl, index) => {
const imageItem = document.createElement('div');
imageItem.classList.add('image-item');
imageItem.innerHTML = `
<img src="${imageUrl}" alt="Image ${index + 1}">
<button onclick="downloadImage('${imageUrl}')">دانلود</button>
`;
imageContainer.appendChild(imageItem);
});
document.getElementById('myModal').style.display = 'block';
} catch (error) {
console.error("خطا در شناسایی تصاویر: ", error);
alert("خطایی در شناسایی تصاویر رخ داد.");
}
}
function downloadImage(imageUrl) {
const confirmModal = document.createElement('div');
confirmModal.style.cssText = `
position: fixed;
z-index: 10003;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
`;
const modalContent = document.createElement('div');
modalContent.style.cssText = `
background-color: #fefefe;
padding: 20px;
border: 1px solid #888;
width: 80%;
max-width: 400px;
text-align: center;
border-radius: 5px;
`;
modalContent.innerHTML = `
<p style="margin-bottom: 20px;">برای دانلود تصویر روی تایید کلیک کنید و بعد از باز شدن مرورگر روی تصویر محکم نگه دارید و بارگیری تصویر را کلیک کنید.</p>
<button id="confirmDownload" style="
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
margin-right: 10px;
">تایید</button>
<button id="cancelDownload" style="
background-color: #f44336;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
">لغو</button>
`;
confirmModal.appendChild(modalContent);
document.body.appendChild(confirmModal);
document.getElementById('confirmDownload').addEventListener('click', function() {
window.open(imageUrl, '_blank');
document.body.removeChild(confirmModal);
});
document.getElementById('cancelDownload').addEventListener('click', function() {
document.body.removeChild(confirmModal);
});
confirmModal.addEventListener('click', function(event) {
if (event.target === confirmModal) {
document.body.removeChild(confirmModal);
}
});
}
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();
});
document.getElementById('downloadButton').addEventListener('click', handleDownload);
document.getElementById('downloadButtonBottom').addEventListener('click', handleDownload);
const modal = document.getElementById('myModal');
const closeBtn = document.getElementById('closeBtn');
closeBtn.addEventListener('click', function() {
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';
});
window.addEventListener('click', function(event) {
if (event.target == modal) {
modal.style.display = 'none';
}
if (event.target == descriptionModal) {
descriptionModal.style.display = 'none';
}
});
// تابع بارگذاری iframe
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();
});
}
loadIframe();
startProgress();
</script>
Certainly! Below is the complete, adjusted code that combines the functionalities of your upper and lower code snippets. The primary modification ensures that the "لطفاً صبر کنید..." ("Please wait...") message and the progress bar remain visible even if the internet connection is interrupted or the iframe fails to load. Additionally, the progress bar will stop advancing when an error occurs, mirroring the behavior of your lower code snippet.
<!DOCTYPE html>
<html lang="fa">
<head>
<meta charset="UTF-8">
<title>Iframe Loader with Persistent Progress</title>
<style>
body {
margin: 0;
padding: 0;
background-color: #f0f0f0;
font-family: Arial, sans-serif;
/* اجازه اسکرول طبیعی */
overflow: hidden;
height: 100vh;
}
.iframe-container {
position: relative;
width: 100%;
height: 600px; /* تنظیم ارتفاع مناسب برای iframe */
overflow: hidden;
margin: 20px 0;
}
iframe {
width: 100%;
height: 100%;
border: none;
display: none; /* مخفی کردن iframe تا بارگذاری شود */
position: relative;
}
.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: 90px;
color: white;
text-align: center;
padding: 6px;
border-radius: 5px;
cursor: pointer;
font-size: 12px;
transition: background-color 0.3s;
position: fixed; /* حفظ موقعیت 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;
}
/* استایل پنجره سفارشی (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, .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;
}
.download-button-bottom {
position: fixed; /* باقی ماندن در موقعیت fixed */
bottom: 10px;
left: 50%;
transform: translateX(-50%);
background-color: #4CAF50;
padding: 16px 20px; /* افزایش پدینگ عمودی از 12px به 16px */
max-width: 90%;
width: 250px; /* عرض ثابت، قابل تنظیم */
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; /* مخفی کردن دکمه در ابتدا */
}
.download-button-bottom:hover {
background-color: #45a049;
}
/* تنظیمات برای صفحات بسیار کوچک */
@media (max-width: 300px) {
.download-button-bottom {
width: 90%;
}
}
</style>
</head>
<body>
<!-- دکمههای دانلود و توضیحات -->
<p>
<a href="#" class="download-button" id="downloadButton">دانلود صدا 📥</a>
<a href="#" class="description-button" id="descriptionButton">توضیحات</a>
</p>
<!-- پنجره سفارشی (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 style="text-align: center;">دستیار مجهز به هوش مصنوعی شما</p>
<p style="text-align: center;"><span style="color: #0000ff;"><strong>افزایش کیفیت صدا</strong></span> بهره وری از پیشرفتهترین مدل هوش مصنوعی برای تقویت فایلهای صوتی</p>
<p style="text-align: center;">حذف نویز و تقویت پیشرفته صدا AI </p>
<button class="modal-button cancel-btn" id="closeDescriptionBtn">بستن</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>
<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';
}
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'; // مخفی کردن iframe
loadIframe();
startProgress();
});
function loadIframe() {
const iframe = document.getElementById('myIframe');
// آدرس iframe خود را در اینجا تنظیم کنید
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("هیچ فایل صوتی ساخته شده یافت نشد.");
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>
</body>
</html>
حفظ نمایش لودینگ در صورت خطا:
iframeError(), اطمینان حاصل شده است که loadingContainer همچنان به صورت flex نمایش داده میشود تا پیام "لطفاً صبر کنید..." و نوار پیشرفت قابل مشاهده باقی بمانند.function iframeError() {
clearInterval(interval);
// اطمینان از نمایش لودینگ در حالت خطا
loadingContainer.style.display = 'flex';
retryButton.style.display = 'block';
errorMessage.style.display = 'block';
// نوار پیشرفت متوقف میشود و پیغام خطا نمایش داده میشود
}
توقف نوار پیشرفت در صورت خطا:
دکمه بارگذاری مجدد:
retryButton) به کاربر امکان میدهد تا مجدداً تلاش کند iframe را بارگذاری کند. این دکمه در صورت بروز خطا قابل مشاهده است و با کلیک بر روی آن، فرآیند بارگذاری مجدد آغاز میشود.سبکهای ثابت و پاسخگو:
position: fixed و z-index بالا تنظیم شدهاند تا همیشه در بالای سایر محتواها قابل مشاهده باشند.توضیحات و پنجرههای مودال:
محدودیت دسترسی به محتوای iframe:
تعیین آدرس iframe:
loadIframe(), اطمینان حاصل کنید که URL صحیح و قابل دسترسی برای iframe تنظیم شده است:
function loadIframe() {
const iframe = document.getElementById('myIframe');
// آدرس iframe خود را در اینجا تنظیم کنید
const urlParts = ['https:', '', 'resembleai-resemble-enhance.hf.space', ''];
iframe.src = urlParts.join('/');
}
resembleai-resemble-enhance.hf.space را با آدرس صحیح جایگزین کنید.افزودن لینکهای صوتی:
.wav باشد تا کاربران بتوانند آنها را دانلود کنند.امیدوارم این کد برای نیازهای شما مناسب باشد! اگر سوال یا نیاز به تغییرات بیشتری دارید، لطفاً اطلاع دهید.
Not yet included in a published release.