o1-mini-2024-09-12· OpenAI
WildChat-4.8M (AI2)
<style> body { margin: 0; padding: 0; overflow: hidden; height: 100vh; background-color:…
- Usercode
- Assistant
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();
برای اینکه iframe شما کل صفحه موبایل را بهطور کامل پوشش دهد و تمامی عناصر دیگر در صفحه به درستی جایگذاری شوند، میتوانیم CSS و ساختار HTML را بهینهسازی کنیم. در ادامه، نسخه بهبود یافته کد شما را ارائه میدهم که اطمینان حاصل میکند iframe تمام صفحه را در بر میگیرد و عناصر اضافی به صورت مناسب نمایش داده میشوند.
position: fixed برای iframe: این کار تضمین میکند که iframe به طور ثابت در صفحه قرار گیرد و کل صفحه را بپوشاند.<!DOCTYPE html>
<html lang="fa">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>تبدیل متن به صدا با هوش مصنوعی</title>
<style>
body, html {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
overflow: hidden;
background-color: #f0f0f0;
font-family: Arial, sans-serif;
}
.iframe-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
overflow: hidden;
z-index: 1;
}
iframe {
width: 100%;
height: 100%;
border: none;
display: none;
}
.loading {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-direction: column;
align-items: center;
z-index: 10000;
background: rgba(255, 255, 255, 0.8);
padding: 20px;
border-radius: 10px;
}
.loading-message {
margin-bottom: 20px;
font-size: 18px;
color: #333;
}
.progress {
width: 80%;
max-width: 300px;
height: 20px;
background-color: #ddd;
border-radius: 10px;
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: 10px;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
transition: background-color 0.3s;
position: fixed;
top: 10px;
z-index: 10002;
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 {
display: none; /* مخفی سازی دکمه پایین */
}
.modal {
display: none;
position: fixed;
z-index: 10003;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
}
.modal-content {
background-color: #fefefe;
margin: 20% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
max-width: 400px;
text-align: center;
border-radius: 10px;
}
.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>
</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>نسخه پیشرفته تبدیل متن به صدا برنامه <span style="color: #00ffff;">هوش مصنوعی</span></p>
<p>برای نمایش زبان فارسی قسمت زبان ها در کادر جستجو بنویسید <strong>pers</strong></p>
<p>برای استفاده از صدا های طبیعی</p>
<p>بعد از دریافت فایل صوتی میتوانید به قسمت تغییر صدا بروید و با استفاده از مدلهای تغییر صدا فایل صوتی را به صداهای طبیعی و صدای مورد نظر (صدای افراد مشهور) تبدیل کنید.</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>
<!-- دکمه دانلود صدا در پایین صفحه (مخفی شده) -->
<a href="#" class="download-button-bottom" id="downloadButtonBottom">دانلود صدا 📥</a>
<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 < 90) { // محدود کردن حداکثر پیشرفت به 90%
progress += 10;
progressBar.style.width = progress + '%';
}
}, 1000);
}
function iframeLoaded() {
iframeLoadedFlag = true;
clearInterval(interval);
progressBar.style.width = '100%';
setTimeout(() => {
loadingContainer.style.display = 'none';
document.getElementById('myIframe').style.display = 'block';
}, 500);
}
function iframeError() {
clearInterval(interval);
loadingContainer.style.display = 'flex';
errorMessage.style.display = 'block';
retryButton.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.addEventListener('click', function(event) {
if (event.target == modal) {
modal.style.display = 'none';
}
});
// بارگذاری iframe و شروع لودینگ
loadIframe();
startProgress();
</script>
</body>
</html>
ساختار کلی HTML:
position: fixed قرار گرفتهاند و در بالای iframe با z-index مناسب نمایش داده میشوند.CSS بهبود یافته:
position: fixed: این کار تضمین میکند که iframe و عناصر دیگر به درستی در تمام اندازههای صفحه نمایشگاهیده شوند.% و vh برای اطمینان از سازگاری با اندازههای مختلف صفحه نمایش.JavaScript بهینه شده:
.wav و نمایش پیام مناسب در صورت عدم یافتن آنها.توجه به پویاییهای موبایل:
با این تغییرات، iframe شما باید به طور کامل صفحه را در دستگاههای موبایل پوشش دهد و تجربه کاربری بهتری را فراهم آورد. اگر نیاز به تنظیمات بیشتری دارید یا سوالی دارید، خوشحال میشوم کمک کنم!
Not yet included in a published release.