<!DOCTYPE html> <html lang="fa"> <head> <meta charset="UTF-8"> <title>صفحه شما</title>…
- Usercode
- Assistant
.iframe-container {
position: relative;
width: 100%;
height: 100vh;
overflow: hidden;
}
iframe {
width: 100%;
height: calc(100% + 114px); /* تغییر از 228px به 114px */
border: none;
display: none;
position: relative;
top: -114px; /* تغییر از -152px به -114px */
}
.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: 90px;
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: 10px;
border-radius: 5px;
color: white;
text-align: center;
font-size: 14px;
text-decoration: none;
z-index: 10001;
cursor: pointer;
}
.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;
}
.close-btn {
background-color: #f44336;
color: white;
}
</style>
<!-- پنجره سفارشی (modal) -->
<div id="myModal" class="modal">
<div class="modal-content">
<p style="text-align: center;">جدا سازی صدای خواننده از موزیک </p>
<p style="text-align: center;">و یا جدا سازی موزیک از صدای خواننده</p>
<p style="text-align: center;">با بالاترین کیفیت ممکن </p>
<p style="text-align: center;">با <span style="color: #33cccc;">هوش مصنوعی</span></p>
<button class="modal-button close-btn" id="closeBtn">بستن</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;
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');
iframe.src = 'https://nick088-edge-tts.hf.space/';
}
document.getElementById('downloadButton').addEventListener('click', function(event) {
event.preventDefault();
downloadAudio();
});
document.getElementById('downloadButtonBottom').addEventListener('click', function(event) {
event.preventDefault();
downloadAudio();
});
function downloadAudio() {
const iframe = document.getElementById('myIframe');
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
try {
const links = iframeDocument.querySelectorAll('a');
if (links.length === 0) {
alert("هیچ لینک صوتی برای دانلود یافت نشد.");
return;
}
let wavFiles = [];
links.forEach((link) => {
const href = link.href;
if (href.endsWith('.wav')) {
wavFiles.push(href);
}
});
if (wavFiles.length === 0) {
alert("هیچ فایل صوتی با فرمت .wav پیدا نشد.");
return;
}
const numFiles = wavFiles.length;
if (confirm(${numFiles} فایل صوتی ساخته شده پیدا شد.\nبرای دانلود روی 'تأیید' کلیک کنید. بعد از باز شدن مرورگر روی فایل محکم نگه دارید و 'بارگیری صدا' را انتخاب کنید.)) {
wavFiles.forEach((audioUrl) => {
window.open(audioUrl, '_blank');
});
}
} catch (error) {
console.error("خطا در شناسایی فایلهای صوتی: ", error);
alert("خطایی در شناسایی فایلهای صوتی رخ داد.");
}
}
const modal = document.getElementById('myModal');
const closeBtn = document.getElementById('closeBtn');
const descriptionButton = document.getElementById('descriptionButton');
// نمایش پنجره توضیحات
descriptionButton.addEventListener('click', function(event) {
event.preventDefault();
modal.style.display = 'block';
});
// دکمه بستن داخل پنجره
closeBtn.addEventListener('click', function() {
modal.style.display = 'none';
});
// بستن پنجره در صورت کلیک خارج از آن
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = 'none';
}
}
loadIframe();
startProgress();
</script>
سلام!
به نظر میرسد که شما میخواهید دکمه "توضیحات" (description-button) در صفحهی شما به درستی عمل کند و پنجره توضیحات (Modal) را باز کند. همچنین ممکن است بخواهید عملکرد کلی صفحه را بهبود دهید. من در ادامه به بررسی کد شما و ارائه برخی اصلاحات و بهبودها میپردازم.
اشتباه در استفاده از confirm در تابع downloadAudio:
در کد اصلی، رشتهی پیام داخل confirm به درستی تعریف نشده است. باید از Template Literals (با استفاده از بکتیک `) استفاده کنید تا مقادیر متغیر درون رشته قرار گیرند.
بهبود عملکرد دکمه "توضیحات": اطمینان حاصل کنید که دکمه "توضیحات" به درستی پنجرهی محاورهای (Modal) را باز و میبندد.
بهبود دسترسی و تجربه کاربری: اضافه کردن کیفریمها یا انیمیشنها برای بهبود تجربه کاربری و دسترسی بهتر.
در زیر نسخهی اصلاحشده و بهبود یافتهی کد شما را مشاهده میکنید:
<!DOCTYPE html>
<html lang="fa">
<head>
<meta charset="UTF-8">
<title>صفحه شما</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
height: 100vh;
background-color: #f0f0f0;
font-family: Arial, sans-serif;
}
.iframe-container {
position: relative;
width: 100%;
height: 100vh;
overflow: hidden;
}
iframe {
width: 100%;
height: calc(100% + 114px); /* تغییر از 228px به 114px */
border: none;
display: none;
position: relative;
top: -114px; /* تغییر از -152px به -114px */
}
.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: 8px;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
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: 10px 20px;
border-radius: 5px;
color: white;
text-align: center;
font-size: 14px;
text-decoration: none;
z-index: 10001;
cursor: pointer;
}
.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);
animation: fadeIn 0.3s;
}
.modal-content {
background-color: #fefefe;
margin: 15% auto;
padding: 20px;
border: none; /* حذف حاشیه برای ظاهری تمیزتر */
width: 80%;
max-width: 400px;
text-align: center;
border-radius: 10px;
box-shadow: 0 5px 15px rgba(0,0,0,0.3);
animation: slideDown 0.3s;
}
.modal-button {
margin-top: 20px;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
transition: background-color 0.3s;
}
.close-btn {
background-color: #f44336;
color: white;
}
.close-btn:hover {
background-color: #d32f2f;
}
@keyframes fadeIn {
from {opacity: 0;}
to {opacity: 1;}
}
@keyframes slideDown {
from {transform: translateY(-20px); opacity: 0;}
to {transform: translateY(0); opacity: 1;}
}
</style>
</head>
<body>
<!-- دکمههای دانلود و توضیحات -->
<p><a href="#" class="download-button" id="downloadButton">دانلود صدا 📥</a></p>
<p><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>
<p style="text-align: center;">و یا جدا سازی موزیک از صدای خواننده</p>
<p style="text-align: center;">با بالاترین کیفیت ممکن </p>
<p style="text-align: center;">با <span style="color: #33cccc;">هوش مصنوعی</span></p>
<button class="modal-button close-btn" id="closeBtn">بستن</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;
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');
iframe.src = 'https://nick088-edge-tts.hf.space/';
}
document.getElementById('downloadButton').addEventListener('click', function(event) {
event.preventDefault();
downloadAudio();
});
document.getElementById('downloadButtonBottom').addEventListener('click', function(event) {
event.preventDefault();
downloadAudio();
});
function downloadAudio() {
const iframe = document.getElementById('myIframe');
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
try {
const links = iframeDocument.querySelectorAll('a');
if (links.length === 0) {
alert("هیچ لینک صوتی برای دانلود یافت نشد.");
return;
}
let wavFiles = [];
links.forEach((link) => {
const href = link.href;
if (href.endsWith('.wav')) {
wavFiles.push(href);
}
});
if (wavFiles.length === 0) {
alert("هیچ فایل صوتی با فرمت .wav پیدا نشد.");
return;
}
const numFiles = wavFiles.length;
if (confirm(`${numFiles} فایل صوتی ساخته شده پیدا شد.\nبرای دانلود روی 'تأیید' کلیک کنید. بعد از باز شدن مرورگر روی فایل محکم نگه دارید و 'بارگیری صدا' را انتخاب کنید.`)) {
wavFiles.forEach((audioUrl) => {
window.open(audioUrl, '_blank');
});
}
} catch (error) {
console.error("خطا در شناسایی فایلهای صوتی: ", error);
alert("خطایی در شناسایی فایلهای صوتی رخ داد.");
}
}
const modal = document.getElementById('myModal');
const closeBtn = document.getElementById('closeBtn');
const descriptionButton = document.getElementById('descriptionButton');
// نمایش پنجره توضیحات
descriptionButton.addEventListener('click', function(event) {
event.preventDefault();
modal.style.display = 'block';
});
// دکمه بستن داخل پنجره
closeBtn.addEventListener('click', function() {
modal.style.display = 'none';
});
// بستن پنجره در صورت کلیک خارج از آن
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = 'none';
}
}
// بارگذاری اولیه iframe و شروع لودینگ
loadIframe();
startProgress();
</script>
</body>
</html>
اصلاح رشته در confirm:
if (confirm(`${numFiles} فایل صوتی ساخته شده پیدا شد.\nبرای دانلود روی 'تأیید' کلیک کنید. بعد از باز شدن مرورگر روی فایل محکم نگه دارید و 'بارگیری صدا' را انتخاب کنید.`)) {
با استفاده از Template Literals و بکتیکها، رشته به درستی تعریف شده و متغیر numFiles به داخل رشته جایگذاری میشود.
بهبود طراحی دکمهها: عرض دکمهها را افزایش دادم تا متن به خوبی نمایش داده شود و به تجربه کاربری بهتری منجر شود.
افزودن انیمیشنها به Modal:
با اضافه کردن انیمیشنهای fadeIn و slideDown، باز و بسته شدن پنجرهی توضیحات نرمتر و جذابتر شده است.
حذف حاشیه از modal-content و افزودن سایه:
حذف حاشیهی پیشفرض و افزودن سایه به پنجرهی توضیحات ظاهری مدرنتر به آن بخشیده است.
بهبود واکنشگرایی و دسترسی: فونتها و اندازههای متن بهبود یافتهاند تا در دستگاههای مختلف به خوبی نمایش داده شوند.
سرویسهای Cross-Origin (CORS): توجه داشته باشید که دسترسی به محتوای iframe از دامنههای دیگر ممکن است به دلیل محدودیتهای امنیتی CORS مسدود شود. اطمینان حاصل کنید که سرور میزبان iframe اجازه دسترسی لازم را میدهد.
تست در مرورگرهای مختلف: بعد از اعمال تغییرات، صفحه را در مرورگرهای مختلف (Chrome, Firefox, Safari و غیره) تست کنید تا از سازگاری و عملکرد صحیح آن مطمئن شوید.
بهینهسازی تجربه کاربری: میتوانید با اضافه کردن پیامهای بیشتر یا راهنماییهای بهتر به کاربران، تجربه کاربری را بهبود بخشید.
اگر سوال یا نیازی به تغییرات بیشتری دارید، خوشحال میشوم که کمک کنم!
Not yet included in a published release.