<!DOCTYPE html> <html lang="fa"> <head> <meta charset="UTF-8"> <title>صفحه با دکمه…
- Usercode
- Assistant
.iframe-container {
position: relative;
width: 100%;
height: 100vh;
overflow: hidden;
}
iframe {
width: 100%;
height: 100%;
border: none;
display: none;
position: relative;
top: 0;
}
.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;
}
@media (max-width: 768px) {
iframe {
height: 100%;
top: 0;
}
.download-button-bottom {
width: 90%;
padding: 12px 40px;
font-size: 14px;
}
}
</style>
<!-- پنجره سفارشی (modal) برای تصاویر شناسایی شده -->
<div id="myModal" class="modal">
<div class="modal-content">
<p style="text-align: center;">تصاویر شناساییشده</p>
<div class="image-container" id="imageContainer"><!-- تصاویر شناساییشده در اینجا قرار میگیرند --></div>
<button class="modal-button cancel-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"></iframe>
</div>
<!-- دکمه دانلود در پایین صفحه -->
<p>
<a href="#" class="download-button-bottom" id="downloadButtonBottom">دانلود صدا 📥</a>
</p>
<script>
const siteURL = 'https://ovi054-image-to-prompt.hf.space/';
const excludeUrls = [
'https://yanze-pulid.hf.space/--replicas/3t64n/file=/tmp/gradio/7567beceda2541f726af7beb4c9aa857b4a96b77/liuyifei.png'
];
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';
}
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';
}
});
// اجرای بارگذاری iframe و آغاز لودینگ
loadIframe();
startProgress();
</script>
برای نمایش پیغام "این ربات تبدیل تصویر به پرامپت" هنگام کلیک بر روی دکمه "دانلود صدا 📥"، میتوانید از یک پنجره مدال مشابه پنجره موجود برای تصاویر استفاده کنید. در زیر نحوه انجام این کار را مرحله به مرحله توضیح دادهام:
افزودن یک پنجره مدال جدید برای پیغام دانلود:
ابتدا باید در قسمت <body>، بعد از پنجره مدال اصلی، یک پنجره مدال جدید اضافه کنید که پیغام مورد نظر را نمایش دهد.
بهروزرسانی CSS (در صورت نیاز):
اگر استایلهای مدال موجود کافی هستند، نیازی به تغییر ندارید. در غیر این صورت، میتوانید استایلهای جدید را اضافه کنید.
افزودن اسکریپت جاوااسکریپت برای مدیریت نمایش پنجره مدال جدید:
باید یک رویداد کلیک به دکمه دانلود اضافه کنید که پنجره مدال را نمایش دهد و همچنین دکمه بستن را مدیریت کنید.
در ادامه، کد کامل HTML شما با تغییرات لازم آورده شده است:
<!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: 100%;
border: none;
display: none;
position: relative;
top: 0;
}
.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;
}
@media (max-width: 768px) {
iframe {
height: 100%;
top: 0;
}
.download-button-bottom {
width: 90%;
padding: 12px 40px;
font-size: 14px;
}
}
</style>
</head>
<body>
<!-- پنجره سفارشی (modal) برای تصاویر شناسایی شده -->
<div id="myModal" class="modal">
<div class="modal-content">
<p style="text-align: center;">تصاویر شناساییشده</p>
<div class="image-container" id="imageContainer"><!-- تصاویر شناساییشده در اینجا قرار میگیرند --></div>
<button class="modal-button cancel-btn" id="closeBtn">بستن</button>
</div>
</div>
<!-- پنجره مدال جدید برای پیغام دانلود -->
<div id="downloadModal" class="modal">
<div class="modal-content">
<p>این ربات تبدیل تصویر به پرامپت است.</p>
<button class="modal-button cancel-btn" id="closeDownloadModal">بستن</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"></iframe>
</div>
<!-- دکمه دانلود در پایین صفحه -->
<p>
<a href="#" class="download-button-bottom" id="downloadButtonBottom">دانلود صدا 📥</a>
</p>
<script>
const siteURL = 'https://ovi054-image-to-prompt.hf.space/';
const excludeUrls = [
'https://yanze-pulid.hf.space/--replicas/3t64n/file=/tmp/gradio/7567beceda2541f726af7beb4c9aa857b4a96b77/liuyifei.png'
];
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';
}
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';
}
});
// مدیریت پنجره مدال دانلود
const downloadModal = document.getElementById('downloadModal');
const closeDownloadModal = document.getElementById('closeDownloadModal');
const downloadButton = document.getElementById('downloadButtonBottom');
downloadButton.addEventListener('click', function(event) {
event.preventDefault(); // جلوگیری از عمل پیشفرض لینک
downloadModal.style.display = 'block';
});
closeDownloadModal.addEventListener('click', function() {
downloadModal.style.display = 'none';
});
window.addEventListener('click', function(event) {
if (event.target == downloadModal) {
downloadModal.style.display = 'none';
}
});
// اجرای بارگذاری iframe و آغاز لودینگ
loadIframe();
startProgress();
</script>
</body>
</html>
افزودن پنجره مدال جدید برای پیغام دانلود:
<!-- پنجره مدال جدید برای پیغام دانلود -->
<div id="downloadModal" class="modal">
<div class="modal-content">
<p>این ربات تبدیل تصویر به پرامپت است.</p>
<button class="modal-button cancel-btn" id="closeDownloadModal">بستن</button>
</div>
</div>
این بخش را بعد از پنجره مدال اصلی برای تصاویر اضافه کنید.
مدیریت پنجره مدال جدید با جاوااسکریپت:
// مدیریت پنجره مدال دانلود
const downloadModal = document.getElementById('downloadModal');
const closeDownloadModal = document.getElementById('closeDownloadModal');
const downloadButton = document.getElementById('downloadButtonBottom');
downloadButton.addEventListener('click', function(event) {
event.preventDefault(); // جلوگیری از عمل پیشفرض لینک
downloadModal.style.display = 'block';
});
closeDownloadModal.addEventListener('click', function() {
downloadModal.style.display = 'none';
});
window.addEventListener('click', function(event) {
if (event.target == downloadModal) {
downloadModal.style.display = 'none';
}
});
این بخش اطمینان حاصل میکند که با کلیک بر روی دکمه دانلود، پنجره مدال نمایش داده شود و با کلیک بر روی دکمه بستن یا خارج از پنجره مدال، پنجره بسته شود.
با این تغییرات، هنگامی که کاربر بر روی دکمه "دانلود صدا 📥" کلیک کند، یک پنجره مدال نمایش داده میشود که پیغام "این ربات تبدیل تصویر به پرامپت" را نشان میدهد. همچنین کاربر میتواند با کلیک بر روی دکمه "بستن" یا خارج از پنجره مدال، آن را ببندد.
اگر ترجیح میدهید از یک پیغام ساده تر مانند alert استفاده کنید، میتوانید به جای ایجاد پنجره مدال جدید، از alert استفاده کنید. اما استفاده از مدال تجربه کاربری بهتری را فراهم میکند.
alert (اختیاری)اگر میخواهید از یک پنجره هشدار ساده استفاده کنید، کافی است بخش مدیریت دکمه دانلود را به صورت زیر تغییر دهید:
// مدیریت پنجره مدال دانلود با استفاده از alert
const downloadButton = document.getElementById('downloadButtonBottom');
downloadButton.addEventListener('click', function(event) {
event.preventDefault(); // جلوگیری از عمل پیشفرض لینک
alert('این ربات تبدیل تصویر به پرامپت است.');
});
در این حالت، نیازی به اضافه کردن پنجره مدال جدید در HTML نیست.
امیدوارم این توضیحات مفید بوده باشد! در صورت نیاز به کمک بیشتر، سوالات خود را مطرح کنید.
Not yet included in a published release.