تنظیمات iframe و بارگذاری
Criado em: 31 de outubro de 2024
Respondido usando O1 Preview por Chat01
Criado em: 31 de outubro de 2024
Respondido usando O1 Preview por Chat01
.iframe-container {
position: relative;
width: 100%;
height: 100vh;
overflow: hidden;
}
iframe {
width: 100%;
height: calc(100% + 1244px); /* اضافه کردن 33 سانتیمتر به پایین /
border: none;
display: none;
position: relative;
top: -583.15px; / مخفی کردن 20.5 سانت از بالا */
}
.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;
}
.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;
}
.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;
}
</style>
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() {
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("هیچ تصویری با فرمت PNG برای دانلود یافت نشد.");
return;
}
let pngImages = [];
images.forEach((img) => {
if (img.src.endsWith('.png') && !excludeUrls.includes(img.src)) {
pngImages.push(img.src);
}
});
pngImages = pngImages.slice(0, 4);
if (pngImages.length === 0) {
alert("هیچ تصویر ساخته شدهای یافت نشد.");
return;
}
const imageContainer = document.getElementById('imageContainer');
imageContainer.innerHTML = '';
pngImages.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) {
window.open(imageUrl, '_blank');
}
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';
});
window.addEventListener('click', function(event) {
if (event.target == modal) {
modal.style.display = 'none';
}
if (event.target == descriptionModal) {
descriptionModal.style.display = 'none';
}
});
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>
Here's the updated code with the requested changes:
html<p> </p> <style> body { margin: 0; padding: 0; overflow: hidden; height: calc(var(--vh, 1vh) * 100); background-color: #f0f0f0; font-family: Arial, sans-serif; } .iframe-container { position: relative; width: 100%; height: calc(var(--vh, 1vh) * 100); overflow: hidden; } iframe { width: 100%; height: calc(100% + 1244px); /* اضافه کردن 33 سانتیمتر به پایین */ border: none; display: none; position: relative; top: -529.13px; /* مخفی کردن 14 سانت از بالا */ } .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; } .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; } .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; } </style> <!-- دکمههای دانلود و توضیحات --> <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> <div class="image-container" id="imageContainer"></div> <button class="modal-button cancel-btn" id="closeBtn">بستن</button></div> </div> <!-- پنجره سفارشی (modal) برای نمایش توضیحات --> <div id="myDescriptionModal" class="modal"> <div class="modal-content"> <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"> <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> <p> <script> function setVhVariable() { let vh = window.innerHeight * 0.01; document.documentElement.style.setProperty('--vh', `${vh}px`); } setVhVariable(); window.addEventListener('resize', setVhVariable); const siteURL = 'https://cohereforai-aya-expanse.hf.space/'; const excludeUrls = [ 'https://yanze-pulid.hf.space/--replicas/3t64n/file=/tmp/gradio/7567beceda2541f726af7beb4c9aa857b4a96b77/liuyifei.png', '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'; } 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() { 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("هیچ تصویری با فرمت PNG برای دانلود یافت نشد."); return; } let pngImages = []; images.forEach((img) => { if (img.src.endsWith('.png') && !excludeUrls.includes(img.src)) { pngImages.push(img.src); } }); pngImages = pngImages.slice(0, 4); if (pngImages.length === 0) { alert("هیچ تصویر ساخته شدهای یافت نشد."); return; } const imageContainer = document.getElementById('imageContainer'); imageContainer.innerHTML = ''; pngImages.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) { window.open(imageUrl, '_blank'); } 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'; }); window.addEventListener('click', function(event) { if (event.target == modal) { modal.style.display = 'none'; } if (event.target == descriptionModal) { descriptionModal.style.display = 'none'; } }); 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> </p>
این عالی شد ممنون چند تا تغییر دیگه ای هم ایجاد کن وقتی دکمه دانلود کلیک میکنیم فقط تصاویر دارای فرمت webp رو شناسایی کنه و وقتی تصاویر شناسایی میکنه توی اعلان عکس رو نشون میده خب با یک دکمه زیرش که نوشته دانلود کاری کن وقتی کاربر روی دکمه دانلود کلیک میکنه یک اعلان براش باز بشه که نوشته بشه برای دانلود تصویر روی تایید کلیک کنید و بعد از بازشدن مرورگر روی تصویر محکم نگهدارید و بارگیری تصویر را کلیک کنید. وقتی کاربر روی تایید کلیک میکنه اونجا در واقع به مرورگر هدایت بشه و اینکه قسمت توضیحات روی اعلان توضیحات یک دکمه به اسم مترجم است اونو کلا حذف کن مترجم لازم نیست کد کامل یکجا درست کن بفرست
در اینجا کد کامل با تغییرات موردنظر شما ارائه شده است:
html<p> </p> <style> body { margin: 0; padding: 0; overflow: hidden; height: calc(var(--vh, 1vh) * 100); background-color: #f0f0f0; font-family: Arial, sans-serif; } .iframe-container { position: relative; width: 100%; height: calc(var(--vh, 1vh) * 100); overflow: hidden; } iframe { width: 100%; height: calc(100% + 1244px); /* اضافه کردن 33 سانتیمتر به پایین */ border: none; display: none; position: relative; top: -529.13px; /* مخفی کردن 14 سانت از بالا */ } .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; } .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; } .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; } .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; } </style> <!-- دکمههای دانلود و توضیحات --> <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> <div class="image-container" id="imageContainer"></div> <button class="modal-button cancel-btn" id="closeBtn">بستن</button></div> </div> <!-- پنجره سفارشی (modal) برای نمایش توضیحات --> <div id="myDescriptionModal" class="modal"> <div class="modal-content"> <p>مبدل تصویر با هوش مصنوعی</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"></iframe></div> <!-- دکمه دانلود تصویر در پایین صفحه --> <p><a href="#" class="download-button-bottom" id="downloadButtonBottom">دانلود تصویر 📥</a></p> <p> <script> function setVhVariable() { let vh = window.innerHeight * 0.01; document.documentElement.style.setProperty('--vh', `${vh}px`); } setVhVariable(); window.addEventListener('resize', setVhVariable); const siteURL = 'https://cohereforai-aya-expanse.hf.space/'; const excludeUrls = [ 'https://yanze-pulid.hf.space/--replicas/3t64n/file=/tmp/gradio/7567beceda2541f726af7beb4c9aa857b4a96b77/liuyifei.png', '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'; } 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() { 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("هیچ تصویری با فرمت WEBP برای دانلود یافت نشد."); return; } let webpImages = []; images.forEach((img) => { if (img.src.endsWith('.webp') && !excludeUrls.includes(img.src)) { webpImages.push(img.src); } }); webpImages = webpImages.slice(0, 4); if (webpImages.length === 0) { alert("هیچ تصویر ساخته شدهای یافت نشد."); return; } const imageContainer = document.getElementById('imageContainer'); imageContainer.innerHTML = ''; webpImages.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) { if (confirm("برای دانلود تصویر روی تایید کلیک کنید و بعد از بازشدن مرورگر روی تصویر محکم نگهدارید و بارگیری تصویر را کلیک کنید.")) { window.open(imageUrl, '_blank'); } } 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'; }); window.addEventListener('click', function(event) { if (event.target == modal) { modal.style.display = 'none'; } if (event.target == descriptionModal) { descriptionModal.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'; }); loadIframe(); startProgress(); </script> </p>
تغییرات انجامشده:
شناسایی تصاویر با فرمت WEBP:
در تابع handleDownload، بررسی فرمت تصاویر به .webp تغییر داده شده است:
javascriptif (img.src.endsWith('.webp') && !excludeUrls.includes(img.src)) { webpImages.push(img.src); }
افزودن اعلان تأیید هنگام دانلود تصویر:
در تابع downloadImage، یک پیام تأیید قبل از باز کردن تصویر اضافه شده است:
javascriptfunction downloadImage(imageUrl) { if (confirm("برای دانلود تصویر روی تایید کلیک کنید و بعد از بازشدن مرورگر روی تصویر محکم نگهدارید و بارگیری تصویر را کلیک کنید.")) { window.open(imageUrl, '_blank'); } }
حذف دکمه مترجم از بخش توضیحات: دکمه مترجم از بخش توضیحات حذف شده است:
html<!-- دکمه مترجم حذف شد --> <!-- <button class="modal-button translate-btn" id="translateBtn">مترجم</button> -->
همچنین، کدهای مرتبط با این دکمه در جاوااسکریپت نیز حذف شدهاند.
توجه: این کد را با دقت کپی کرده و در محل موردنظر خود قرار دهید. امیدوارم این تغییرات مطابق خواسته شما باشد.
عالی شد ممنون دکمه دانلود تصویر در پایین صفحه رو حذف کن لازم نیست و کاری کن سایت در حالت تمام صفحه باز بشه برای اینکه بفهمی حالت تمام صفحه چجوری است از این کد الهام بگیر <p> </p>
<style> /* تنظیمات پایه برای body و html */ 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: -192.75px; /* پنهان کردن ۵.۱ سانتیمتر بالای صفحه (192.75px) */ left: 0; width: 100%; height: calc((var(--vh) * 100) + 192.75px + 38px); /* افزایش ارتفاع iframe به اندازه ۵.۱ سانتیمتر بالا و ۱ سانتیمتر پایین */ border: none; display: none; /* مخفی کردن iframe تا بارگذاری موفق */ } /* Overlay برای مخفی کردن بخش بالایی صفحه */ .overlay-top { position: fixed; top: 0; left: 0; width: 100%; height: 192.75px; /* ارتفاع ۵.۱ سانتیمتر (192.75px) */ 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> <!-- لودینگ --> <div class="loading" id="loading"> <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 --> <div class="iframe-container"><iframe id="myIframe" src="https://yuntian-deng-chatgpt4turbo.hf.space" scrolling="yes"></iframe></div> <!-- Overlay برای مخفی کردن بخش بالایی صفحه --> <div class="overlay-top" id="overlayTop"></div> <!-- Overlay برای مخفی کردن بخش پایینی صفحه --> <div class="overlay-bottom" id="overlayBottom"></div> <p> <script> // متغیر برای بررسی تکمیل بارگذاری اولیه let initialLoadCompleted = false;</script> </p> کد کامل یکجا درست کن بفرستtext// تابع تنظیم متغیر 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();
در اینجا کد کامل با تغییرات موردنظر شما ارائه شده است:
html<p> </p> <style> /* تنظیمات پایه برای body و html */ html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; /* مخفی کردن اسکرولهای اضافی */ background-color: #f0f0f0; /* رنگ پسزمینه */ font-family: Arial, sans-serif; } /* متغیر 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: -529.13px; /* مخفی کردن 14 سانت از بالا */ left: 0; width: 100%; height: calc((var(--vh) * 100) + 1244px); /* افزایش ارتفاع iframe */ border: none; display: none; /* مخفی کردن iframe تا بارگذاری موفق */ } /* Overlay برای مخفی کردن بخش بالایی صفحه */ .overlay-top { position: fixed; top: 0; left: 0; width: 100%; height: 529.13px; /* ارتفاع 14 سانتیمتر */ 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; /* ارتفاع 1 سانتیمتر (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; } .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; } .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; } .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; } </style> <!-- دکمههای دانلود و توضیحات --> <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> <div class="image-container" id="imageContainer"></div> <button class="modal-button cancel-btn" id="closeBtn">بستن</button></div> </div> <!-- پنجره سفارشی (modal) برای نمایش توضیحات --> <div id="myDescriptionModal" class="modal"> <div class="modal-content"> <p>مبدل تصویر با هوش مصنوعی</p> <button class="modal-button cancel-btn" id="closeDescriptionBtn">بستن</button></div> </div> <!-- لودینگ --> <div class="loading" id="loading"> <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 --> <div class="iframe-container"><iframe id="myIframe" src="https://cohereforai-aya-expanse.hf.space/" scrolling="yes"></iframe></div> <!-- Overlay برای مخفی کردن بخش بالایی صفحه --> <div class="overlay-top" id="overlayTop"></div> <!-- Overlay برای مخفی کردن بخش پایینی صفحه --> <div class="overlay-bottom" id="overlayBottom"></div> <p> <script> // متغیر برای بررسی تکمیل بارگذاری اولیه let initialLoadCompleted = false; // تابع تنظیم متغیر 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(); }); // رویداد کلیک بر روی دکمه دانلود function handleDownload(event) { event.preventDefault(); const iframeDocument = iframe.contentDocument || iframe.contentWindow.document; try { const images = iframeDocument.querySelectorAll('img'); if (images.length === 0) { alert("هیچ تصویری با فرمت WEBP برای دانلود یافت نشد."); return; } let webpImages = []; images.forEach((img) => { if (img.src.endsWith('.webp')) { webpImages.push(img.src); } }); webpImages = webpImages.slice(0, 4); if (webpImages.length === 0) { alert("هیچ تصویر ساخته شدهای یافت نشد."); return; } const imageContainer = document.getElementById('imageContainer'); imageContainer.innerHTML = ''; webpImages.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) { if (confirm("برای دانلود تصویر روی تایید کلیک کنید و بعد از بازشدن مرورگر روی تصویر محکم نگهدارید و بارگیری تصویر را کلیک کنید.")) { window.open(imageUrl, '_blank'); } } document.getElementById('downloadButton').addEventListener('click', handleDownload); const modal = document.getElementById('myModal'); const closeBtn = document.getElementById('closeBtn'); 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'; } }); 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'; }); // افزودن رویداد بارگذاری iframe با once: true iframe.addEventListener('load', iframeLoaded, { once: true }); iframe.addEventListener('error', iframeError, { once: true }); // شروع بارگذاری و لودینگ startProgress(); </script> </p>
توضیحات تغییرات:
حذف دکمه دانلود تصویر در پایین صفحه: کد مربوط به دکمه دانلود در پایین صفحه حذف شده است.
افزودن حالت تمام صفحه: کدهای CSS و JavaScript برای حالت تمام صفحه از کد ارائهشده توسط شما الهام گرفته شده و با کد قبلی ترکیب شده است. ارتفاع صفحه و iframe تنظیم شده تا در حالت تمام صفحه نمایش داده شوند.
بهروزرسانی آدرس iframe:
آدرس src در تگ iframe به https://cohereforai-aya-expanse.hf.space/ تنظیم شده است.
ترکیب کدها: کدهای CSS و JavaScript برای اطمینان از عملکرد صحیح ترکیب و بهینهسازی شدهاند.
حذف دکمه مترجم: دکمه مترجم از بخش توضیحات حذف شده است.
حذف دکمه دانلود در پایین صفحه: کد مربوط به دکمه دانلود تصویر در پایین صفحه حذف شده است.
لطفاً این کد را با دقت کپی کرده و در محل مناسب قرار دهید. امیدوارم این تغییرات مطابق با خواستههای شما باشد.
مخفی سازی بالا رو بجای ۱۴ سانت بکن ۱۳ سانت و اینکه یک مشکل هم وجود داره حتی توی اون کدی هم که فرستادیم گفتم ازش الهام بگیر این مشکل وجود داشت وقتی سایت در حالت تمام صفحه باز میشه تمام صفحه رو نمیگیره و فقط یک سانت بالای صفحه باز میشه کاری کن کل صفحه رو همه چی در بر بگیره
در اینجا کد کامل با تغییرات موردنظر شما ارائه شده است:
html<p> </p> <style> /* تنظیمات پایه برای body و html */ html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; /* مخفی کردن اسکرولهای اضافی */ background-color: #f0f0f0; /* رنگ پسزمینه */ font-family: Arial, sans-serif; } /* کانتینر iframe */ .iframe-container { position: fixed; top: 0; left: 0; width: 100%; height: 100vh; /* استفاده از 100vh برای ارتفاع کامل صفحه */ overflow: hidden; /* مخفی کردن بخشهای اضافی */ z-index: 1; /* ترتیب نمایش */ } /* تنظیمات iframe */ .iframe-container iframe { position: absolute; top: -491.34px; /* مخفی کردن 13 سانت از بالا */ left: 0; width: 100%; height: calc(100vh + 1244px); /* افزایش ارتفاع iframe */ border: none; display: none; /* مخفی کردن iframe تا بارگذاری موفق */ } /* Overlay برای مخفی کردن بخش بالایی صفحه */ .overlay-top { position: fixed; top: 0; left: 0; width: 100%; height: 491.34px; /* ارتفاع 13 سانتیمتر */ 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; /* ارتفاع 1 سانتیمتر (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; } .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; } .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; } .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; } </style> <!-- دکمههای دانلود و توضیحات --> <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> <div class="image-container" id="imageContainer"></div> <button class="modal-button cancel-btn" id="closeBtn">بستن</button></div> </div> <!-- پنجره سفارشی (modal) برای نمایش توضیحات --> <div id="myDescriptionModal" class="modal"> <div class="modal-content"> <p>مبدل تصویر با هوش مصنوعی</p> <button class="modal-button cancel-btn" id="closeDescriptionBtn">بستن</button></div> </div> <!-- لودینگ --> <div class="loading" id="loading"> <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 --> <div class="iframe-container"><iframe id="myIframe" src="https://cohereforai-aya-expanse.hf.space/" scrolling="yes"></iframe></div> <!-- Overlay برای مخفی کردن بخش بالایی صفحه --> <div class="overlay-top" id="overlayTop"></div> <!-- Overlay برای مخفی کردن بخش پایینی صفحه --> <div class="overlay-bottom" id="overlayBottom"></div> <p> <script> // تابع تنظیم متغیر 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() { progressInterval = setInterval(() => { if (progress < 100) { progress += 20; // افزایش ۲۰٪ در هر ثانیه if (progress > 100) progress = 100; progressBar.style.width = progress + '%'; } if (progress >= 100) { clearInterval(progressInterval); if (!iframeLoadedFlag) { showError(); } } }, 1000); // تایماوت برای نمایش پیام خطا بعد از ۵ ثانیه errorTimeout = setTimeout(() => { if (!iframeLoadedFlag) { showError(); } }, 5000); } let iframeLoadedFlag = false; // تابع بارگذاری موفق iframe function iframeLoaded() { iframeLoadedFlag = true; clearInterval(progressInterval); clearTimeout(errorTimeout); loading.style.display = 'none'; iframe.style.display = 'block'; // پاک کردن تایماوتها و اینتروالها progressInterval = null; errorTimeout = null; } // تابع خطا در بارگذاری iframe function iframeError() { clearInterval(progressInterval); clearTimeout(errorTimeout); showError(); } // نمایش خطا function showError() { errorMessage.style.display = 'block'; retryButton.style.display = 'block'; } // بازنشانی لودینگ function resetLoading() { progress = 0; progressBar.style.width = '0%'; iframeLoadedFlag = 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(); }); // رویداد کلیک بر روی دکمه دانلود function handleDownload(event) { event.preventDefault(); const iframeDocument = iframe.contentDocument || iframe.contentWindow.document; try { const images = iframeDocument.querySelectorAll('img'); if (images.length === 0) { alert("هیچ تصویری با فرمت WEBP برای دانلود یافت نشد."); return; } let webpImages = []; images.forEach((img) => { if (img.src.endsWith('.webp')) { webpImages.push(img.src); } }); webpImages = webpImages.slice(0, 4); if (webpImages.length === 0) { alert("هیچ تصویر ساخته شدهای یافت نشد."); return; } const imageContainer = document.getElementById('imageContainer'); imageContainer.innerHTML = ''; webpImages.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) { if (confirm("برای دانلود تصویر روی تایید کلیک کنید و بعد از بازشدن مرورگر روی تصویر محکم نگهدارید و بارگیری تصویر را کلیک کنید.")) { window.open(imageUrl, '_blank'); } } document.getElementById('downloadButton').addEventListener('click', handleDownload); const modal = document.getElementById('myModal'); const closeBtn = document.getElementById('closeBtn'); 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'; } }); 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'; }); // افزودن رویداد بارگذاری iframe با once: true iframe.addEventListener('load', iframeLoaded, { once: true }); iframe.addEventListener('error', iframeError, { once: true }); // شروع بارگذاری و لودینگ startProgress(); </script> </p>
توضیحات تغییرات:
مخفی کردن ۱۳ سانتیمتر از بالا:
مقدار top در تنظیمات iframe را از -529.13px به -491.34px تغییر دادیم:
csstop: -491.34px; /* مخفی کردن 13 سانت از بالا */
این مقدار با توجه به تبدیل ۱۳ سانتیمتر به پیکسل (۱ سانتیمتر ≈ ۳۷.۷۹۵ پیکسل) محاسبه شده است:
13 cm * 37.795 = 491.34 px
رفع مشکل نمایش تمامصفحه:
متغیر --vh را از :root حذف کردیم، زیرا در جاوااسکریپت مقداردهی میشود.
در CSS به جای استفاده از calc(var(--vh) * 100) از 100vh استفاده کردیم تا ارتفاع به طور کامل تنظیم شود:
css.iframe-container { height: 100vh; /* استفاده از 100vh برای ارتفاع کامل صفحه */ }
و در تنظیمات iframe:
css.iframe-container iframe { height: calc(100vh + 1244px); /* افزایش ارتفاع iframe */ }
این تغییرات باعث میشود که iframe تمام صفحه را در بر بگیرد و مشکل نمایش یک سانتیمتر در بالا حل شود.
بهروزرسانی جاوااسکریپت:
setVh() همچنان برای پشتیبانی از تغییر اندازه صفحه و دستگاههای موبایل استفاده میشود، اما مطمئن شدیم که مقدار --vh به درستی تنظیم میشود.100vh در CSS استفاده کردیم تا ارتفاع صفحه به درستی محاسبه شود.نکته: این کد را با دقت کپی کرده و در محل مناسب قرار دهید. امیدوارم این تغییرات مطابق با خواستههای شما باشد و مشکل نمایش تمامصفحه برطرف شده باشد.
بجای ۱۳ سانت بکن ۱۲ سانت بالارو و اینکه مشکل قبل وجود داره ببین توضیح میدم کامل وقتی محتوای صفحه باز میشه به اندازه دو سانت اول بالای صفحه همه چی رو نشون میده پایین صفحه همه چی کلا خالی است یعنی در حالت تمام صفحه همه چی نیست همه چی منظورم است آیا این مشکل حل میشه قبل فرستادی نشد چند بار کنم امتحان کردم نشد کد خیلی دقیق برسی کن و درست کن که تمام محتوا تمام صفحه موبایل رو بگیره
در اینجا کد کامل با تغییرات موردنظر شما ارائه شده است:
html<p> </p> <style> /* تنظیمات پایه برای body و html */ html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; /* مخفی کردن اسکرولهای اضافی */ background-color: #f0f0f0; /* رنگ پسزمینه */ font-family: Arial, sans-serif; } /* کانتینر iframe */ .iframe-container { position: fixed; top: 0; left: 0; width: 100%; height: calc(var(--vh, 1vh) * 100); /* استفاده از متغیر --vh */ overflow: hidden; /* مخفی کردن بخشهای اضافی */ z-index: 1; /* ترتیب نمایش */ } /* تنظیمات iframe */ .iframe-container iframe { position: absolute; top: -453.54px; /* مخفی کردن 12 سانت از بالا */ left: 0; width: 100%; height: calc((var(--vh, 1vh) * 100) + 1244px); /* افزایش ارتفاع iframe */ border: none; display: none; /* مخفی کردن iframe تا بارگذاری موفق */ } /* Overlay برای مخفی کردن بخش بالایی صفحه */ .overlay-top { position: fixed; top: 0; left: 0; width: 100%; height: 453.54px; /* ارتفاع 12 سانتیمتر */ 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; /* ارتفاع 1 سانتیمتر (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; } .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; } .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; } .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; } </style> <!-- دکمههای دانلود و توضیحات --> <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> <div class="image-container" id="imageContainer"></div> <button class="modal-button cancel-btn" id="closeBtn">بستن</button></div> </div> <!-- پنجره سفارشی (modal) برای نمایش توضیحات --> <div id="myDescriptionModal" class="modal"> <div class="modal-content"> <p>مبدل تصویر با هوش مصنوعی</p> <button class="modal-button cancel-btn" id="closeDescriptionBtn">بستن</button></div> </div> <!-- لودینگ --> <div class="loading" id="loading"> <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 --> <div class="iframe-container"><iframe id="myIframe" src="https://cohereforai-aya-expanse.hf.space/" scrolling="yes"></iframe></div> <!-- Overlay برای مخفی کردن بخش بالایی صفحه --> <div class="overlay-top" id="overlayTop"></div> <!-- Overlay برای مخفی کردن بخش پایینی صفحه --> <div class="overlay-bottom" id="overlayBottom"></div> <p> <script> // تابع تنظیم متغیر 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 iframeLoadedFlag = false; // تابع شروع پیشرفت نوار لودینگ function startProgress() { progressInterval = setInterval(() => { if (progress < 100) { progress += 20; // افزایش ۲۰٪ در هر ثانیه if (progress > 100) progress = 100; progressBar.style.width = progress + '%'; } if (progress >= 100) { clearInterval(progressInterval); if (!iframeLoadedFlag) { showError(); } } }, 1000); // تایماوت برای نمایش پیام خطا بعد از ۵ ثانیه errorTimeout = setTimeout(() => { if (!iframeLoadedFlag) { showError(); } }, 5000); } // تابع بارگذاری موفق iframe function iframeLoaded() { iframeLoadedFlag = true; clearInterval(progressInterval); clearTimeout(errorTimeout); loading.style.display = 'none'; iframe.style.display = 'block'; // پاک کردن تایماوتها و اینتروالها progressInterval = null; errorTimeout = null; } // تابع خطا در بارگذاری iframe function iframeError() { clearInterval(progressInterval); clearTimeout(errorTimeout); showError(); } // نمایش خطا function showError() { errorMessage.style.display = 'block'; retryButton.style.display = 'block'; } // بازنشانی لودینگ function resetLoading() { progress = 0; progressBar.style.width = '0%'; iframeLoadedFlag = 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(); }); // رویداد کلیک بر روی دکمه دانلود function handleDownload(event) { event.preventDefault(); const iframeDocument = iframe.contentDocument || iframe.contentWindow.document; try { const images = iframeDocument.querySelectorAll('img'); if (images.length === 0) { alert("هیچ تصویری با فرمت WEBP برای دانلود یافت نشد."); return; } let webpImages = []; images.forEach((img) => { if (img.src.endsWith('.webp')) { webpImages.push(img.src); } }); webpImages = webpImages.slice(0, 4); if (webpImages.length === 0) { alert("هیچ تصویر ساخته شدهای یافت نشد."); return; } const imageContainer = document.getElementById('imageContainer'); imageContainer.innerHTML = ''; webpImages.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) { if (confirm("برای دانلود تصویر روی تایید کلیک کنید و بعد از بازشدن مرورگر روی تصویر محکم نگهدارید و بارگیری تصویر را کلیک کنید.")) { window.open(imageUrl, '_blank'); } } document.getElementById('downloadButton').addEventListener('click', handleDownload); const modal = document.getElementById('myModal'); const closeBtn = document.getElementById('closeBtn'); 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'; } }); 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'; }); // افزودن رویداد بارگذاری iframe با once: true iframe.addEventListener('load', iframeLoaded, { once: true }); iframe.addEventListener('error', iframeError, { once: true }); // شروع بارگذاری و لودینگ startProgress(); </script> </p>
توضیحات تغییرات:
مخفی کردن ۱۲ سانتیمتر از بالا:
مقدار top در تنظیمات iframe را به -453.54px تغییر دادیم:
csstop: -453.54px; /* مخفی کردن 12 سانت از بالا */
این مقدار با تبدیل ۱۲ سانتیمتر به پیکسل محاسبه شده است:
12 cm * 37.7952755906 px/cm ≈ 453.54 px
ارتفاع .overlay-top را نیز به 453.54px تغییر دادیم:
cssheight: 453.54px; /* ارتفاع 12 سانتیمتر */
رفع مشکل نمایش تمامصفحه:
از متغیر --vh برای تنظیم ارتفاع استفاده کردیم تا در دستگاههای موبایل به درستی عمل کند. در تنظیمات .iframe-container:
cssheight: calc(var(--vh, 1vh) * 100); /* استفاده از متغیر --vh */
در تنظیمات iframe:
cssheight: calc((var(--vh, 1vh) * 100) + 1244px); /* افزایش ارتفاع iframe */
تابع جاوااسکریپت setVh() مقدار --vh را بر اساس ارتفاع واقعی صفحه تنظیم میکند:
javascriptfunction setVh() { let vh = window.innerHeight * 0.01; document.documentElement.style.setProperty('--vh', `${vh}px`); }
با این تغییرات، ارتفاع صفحه به درستی تنظیم میشود و محتوای iframe کل صفحه را در بر میگیرد.
بررسی و رفع مشکلات احتمالی:
window.innerHeight برای محاسبه دقیق ارتفاع صفحه استفاده کردیم تا در تمامی دستگاهها به درستی عمل کند.overflow: hidden را در body و .iframe-container تنظیم کردیم تا از نمایش اسکرولهای اضافی جلوگیری کنیم.حذف متغیر غیرضروری :root:
--vh مستقیماً در جاوااسکریپت مقداردهی میشود، بنابراین نیازی به تعریف آن در :root نیست.نکته: لطفاً این کد را با دقت کپی کرده و در محل مناسب قرار دهید. امیدوارم این تغییرات مشکل نمایش تمامصفحه را برطرف کرده و مطابق با خواستههای شما باشد.
بجای ۱۲ سانت بکن ۱۱ سانت و اینکه مشکل باز هم حل نشد یکم بهتر شد بالای صفحه محتوا رو تا پایین صفحه نمایش نمیده و فقط دو سانت بالا رو نشون میده درست کن .
و اینکه یک تغییر دیگه ای هم ایجاد کن وقتی روی دکمه دانلود تصویر کلیک میکنیم محتوا رو توی یک اعلان نشون میده و عکس رو با دکمه دانلود نشون میده اصلا اینها لازم نیست به محض اینکه روی دکمه دانلود تصویر کلیک میکنیم همون اعلان انتهایی و اعلان ساده رو نشون بده کافیه که نوشته برای دانلود روی تایید کلیک کنید منظورم همین اعلان با کلیک روی دکمه دانلود نشون بده کافیه
در اینجا کد کامل با تغییرات موردنظر شما ارائه شده است:
html<p> </p> <style> /* تنظیمات پایه برای body و html */ html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; /* مخفی کردن اسکرولهای اضافی */ background-color: #f0f0f0; /* رنگ پسزمینه */ font-family: Arial, sans-serif; } /* کانتینر iframe */ .iframe-container { position: fixed; top: 0; left: 0; width: 100%; height: calc(var(--vh, 1vh) * 100); /* استفاده از متغیر --vh */ overflow: hidden; /* مخفی کردن بخشهای اضافی */ z-index: 1; /* ترتیب نمایش */ } /* تنظیمات iframe */ .iframe-container iframe { position: absolute; top: -415.75px; /* مخفی کردن 11 سانت از بالا */ left: 0; width: 100%; height: calc((var(--vh, 1vh) * 100) + 1244px); /* افزایش ارتفاع iframe */ border: none; display: none; /* مخفی کردن iframe تا بارگذاری موفق */ } /* Overlay برای مخفی کردن بخش بالایی صفحه */ .overlay-top { position: fixed; top: 0; left: 0; width: 100%; height: 415.75px; /* ارتفاع 11 سانتیمتر */ 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; /* ارتفاع 1 سانتیمتر (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; } .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; } .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; } </style> <!-- دکمههای دانلود و توضیحات --> <p><a href="#" class="download-button" id="downloadButton">دانلود تصویر 📥</a></p> <p><a href="#" class="description-button" id="descriptionButton">توضیحات</a></p> <!-- پنجره سفارشی (modal) برای نمایش توضیحات --> <div id="myDescriptionModal" class="modal"> <div class="modal-content"> <p>مبدل تصویر با هوش مصنوعی</p> <button class="modal-button cancel-btn" id="closeDescriptionBtn">بستن</button></div> </div> <!-- لودینگ --> <div class="loading" id="loading"> <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 --> <div class="iframe-container"><iframe id="myIframe" src="https://cohereforai-aya-expanse.hf.space/" scrolling="yes"></iframe></div> <!-- Overlay برای مخفی کردن بخش بالایی صفحه --> <div class="overlay-top" id="overlayTop"></div> <!-- Overlay برای مخفی کردن بخش پایینی صفحه --> <div class="overlay-bottom" id="overlayBottom"></div> <p> <script> // تابع تنظیم متغیر 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'); let progressInterval; let errorTimeout; let iframeLoadedFlag = false; // تابع شروع پیشرفت نوار لودینگ function startProgress() { progressInterval = setInterval(() => { if (progress < 100) { progress += 20; // افزایش ۲۰٪ در هر ثانیه if (progress > 100) progress = 100; progressBar.style.width = progress + '%'; } if (progress >= 100) { clearInterval(progressInterval); if (!iframeLoadedFlag) { showError(); } } }, 1000); // تایماوت برای نمایش پیام خطا بعد از ۵ ثانیه errorTimeout = setTimeout(() => { if (!iframeLoadedFlag) { showError(); } }, 5000); } // تابع بارگذاری موفق iframe function iframeLoaded() { iframeLoadedFlag = true; clearInterval(progressInterval); clearTimeout(errorTimeout); loading.style.display = 'none'; iframe.style.display = 'block'; // پاک کردن تایماوتها و اینتروالها progressInterval = null; errorTimeout = null; } // تابع خطا در بارگذاری iframe function iframeError() { clearInterval(progressInterval); clearTimeout(errorTimeout); showError(); } // نمایش خطا function showError() { errorMessage.style.display = 'block'; retryButton.style.display = 'block'; } // بازنشانی لودینگ function resetLoading() { progress = 0; progressBar.style.width = '0%'; iframeLoadedFlag = 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(); }); // رویداد کلیک بر روی دکمه دانلود function handleDownload(event) { event.preventDefault(); if (confirm("برای دانلود تصویر روی تایید کلیک کنید.")) { const iframeDocument = iframe.contentDocument || iframe.contentWindow.document; try { const images = iframeDocument.querySelectorAll('img'); let webpImages = []; images.forEach((img) => { if (img.src.endsWith('.webp')) { webpImages.push(img.src); } }); if (webpImages.length === 0) { alert("هیچ تصویر ساخته شدهای یافت نشد."); return; } // باز کردن اولین تصویر در مرورگر window.open(webpImages[0], '_blank'); } catch (error) { console.error("خطا در شناسایی تصاویر: ", error); alert("خطایی در شناسایی تصاویر رخ داد."); } } } document.getElementById('downloadButton').addEventListener('click', handleDownload); 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 == descriptionModal) { descriptionModal.style.display = 'none'; } }); // افزودن رویداد بارگذاری iframe با once: true iframe.addEventListener('load', iframeLoaded, { once: true }); iframe.addEventListener('error', iframeError, { once: true }); // شروع بارگذاری و لودینگ startProgress(); </script> </p>
توضیحات تغییرات:
مخفی کردن 11 سانتیمتر از بالا:
مقدار top در تنظیمات iframe به -415.75px تغییر داده شد:
csstop: -415.75px; /* مخفی کردن 11 سانت از بالا */
این مقدار با تبدیل 11 سانتیمتر به پیکسل محاسبه شده است:
11 cm * 37.7952755906 px/cm ≈ 415.75 px
ارتفاع .overlay-top نیز به 415.75px تنظیم شد:
cssheight: 415.75px; /* ارتفاع 11 سانتیمتر */
رفع مشکل نمایش تمامصفحه:
از متغیر --vh برای تنظیم ارتفاع استفاده شده تا در دستگاههای موبایل و دسکتاپ به درستی عمل کند.
تابع جاوااسکریپت setVh() مقدار --vh را بر اساس ارتفاع واقعی صفحه تنظیم میکند:
javascriptfunction setVh() { let vh = window.innerHeight * 0.01; document.documentElement.style.setProperty('--vh', `${vh}px`); }
با این تغییرات، ارتفاع صفحه به درستی تنظیم میشود و محتوای iframe کل صفحه را در بر میگیرد.
تغییر رفتار دکمه دانلود تصویر:
کد مربوط به نمایش مودال و تصاویر حذف شده است.
در تابع handleDownload، به محض کلیک روی دکمه دانلود، یک اعلان ساده نمایش داده میشود و پس از تأیید، اولین تصویر ساختهشده باز میشود:
javascriptfunction handleDownload(event) { event.preventDefault(); if (confirm("برای دانلود تصویر روی تایید کلیک کنید.")) { // ... کد برای باز کردن تصویر ... } }
کد مربوط به مودال تصاویر و دکمههای دانلود حذف شده است.
حذف پنجره مودال تصاویر:
.modal و .modal-content به دلیل استفاده در پنجره توضیحات باقی مانده است.تست و بررسی عملکرد:
نکته: لطفاً این کد را با دقت کپی کرده و در محل مناسب قرار دهید. امیدوارم این تغییرات مشکل نمایش تمامصفحه را برطرف کرده و رفتار دکمه دانلود تصویر مطابق با خواسته شما باشد.
ممنون چند تغییر دیگری هم ایجاد کن دکمه توضیحات رو کلا حذف کن و دکمه دانلود تصویر رو بیار سمت چپ بجای دکمه توضیحات اونجا باشه و اینکه وقتی روی دکمه دانلود تصویر کلیک میکنم در واقع دو تا اعلان نشون میده کاری کن به محض اینکه روی دکمه دانلود تصویر کلیک میکنم یک اعلان نشون بده و همونجا برسی کنه و با یک باز تایید به مرورگر هدایت بشه و همون جا نوشته بده توی یک اعلان اعلان انتهایی رو فقط نشون بده کافیه . مخفی سازی بالا رو از ۱۱ سانت به ۱۲ سانت تغییر بده .
و اینکه در این کد دکمه لطفاً صبر کنید به هیچ عنوان قطع نمیشه حتی اگر اینترنت هم قطع بشه باز هم است و دکمه لطفاً صبر کنید و نوار پیشرفت حتی اگر اینترنت هم قطع بشه نمیره و متوقف میشه اگر سایت بالا نیاد یا اینترنت در حین باز شدن قطع بشه <p> </p><style> body { margin: 0; padding: 0; overflow: hidden; height: calc(var(--vh, 1vh) * 100); background-color: #f0f0f0; font-family: Arial, sans-serif; } .iframe-container { position: relative; width: 100%; height: calc(var(--vh, 1vh) * 100); overflow: hidden; } iframe { width: 100%; height: calc(100% + 1244px); /* اضافه کردن 33 سانتیمتر به پایین / border: none; display: none; position: relative; top: -529.13px; / مخفی کردن 14 سانت از بالا */ } .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; } .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; } .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; } .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; } </style><!-- دکمههای دانلود و توضیحات --><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><div class="image-container" id="imageContainer"></div><button class="modal-button cancel-btn" id="closeBtn">بستن</button></div></div><!-- پنجره سفارشی (modal) برای نمایش توضیحات --><div id="myDescriptionModal" class="modal"><div class="modal-content"><p>مبدل تصویر با هوش مصنوعی</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"></iframe></div><!-- دکمه دانلود تصویر در پایین صفحه --><p><a href="#" class="download-button-bottom" id="downloadButtonBottom">دانلود تصویر 📥</a></p><p><script> function setVhVariable() { let vh = window.innerHeight * 0.01; document.documentElement.style.setProperty('--vh', {vh}px); } setVhVariable(); window.addEventListener('resize', setVhVariable); const siteURL = 'https://cohereforai-aya-expanse.hf.space/'; const excludeUrls = [ 'https://yanze-pulid.hf.space/--replicas/3t64n/file=/tmp/gradio/7567beceda2541f726af7beb4c9aa857b4a96b77/liuyifei.png', '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'; } 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() { 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("هیچ تصویری با فرمت WEBP برای دانلود یافت نشد."); return; } let webpImages = []; images.forEach((img) => { if (img.src.endsWith('.webp') && !excludeUrls.includes(img.src)) { webpImages.push(img.src); } }); webpImages = webpImages.slice(0, 4); if (webpImages.length === 0) { alert("هیچ تصویر ساخته شدهای یافت نشد."); return; } const imageContainer = document.getElementById('imageContainer'); imageContainer.innerHTML = ''; webpImages.forEach((imageUrl, index) => { const imageItem = document.createElement('div'); imageItem.classList.add('image-item'); imageItem.innerHTML = <img src="{imageUrl}" alt="Image {imageUrl}')">دانلود</button> ; imageContainer.appendChild(imageItem); }); document.getElementById('myModal').style.display = 'block'; } catch (error) { console.error("خطا در شناسایی تصاویر: ", error); alert("خطایی در شناسایی تصاویر رخ داد."); } } function downloadImage(imageUrl) { if (confirm("برای دانلود تصویر روی تایید کلیک کنید و بعد از بازشدن مرورگر روی تصویر محکم نگهدارید و بارگیری تصویر را کلیک کنید.")) { window.open(imageUrl, '_blank'); } } 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'; }); window.addEventListener('click', function(event) { if (event.target == modal) { modal.style.display = 'none'; } if (event.target == descriptionModal) { descriptionModal.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'; }); loadIframe(); startProgress(); </script></p> دکمه لطفاً صبر کنید با نوار پیشرفت کلا میخواستم برای کد منم مثل این کد باشه
در اینجا کد کامل با تغییرات موردنظر شما ارائه شده است:
html<p> </p> <style> /* تنظیمات پایه برای body و html */ html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; /* مخفی کردن اسکرولهای اضافی */ background-color: #f0f0f0; /* رنگ پسزمینه */ font-family: Arial, sans-serif; } /* کانتینر iframe */ .iframe-container { position: fixed; top: 0; left: 0; width: 100%; height: calc(var(--vh, 1vh) * 100); /* استفاده از متغیر --vh */ overflow: hidden; /* مخفی کردن بخشهای اضافی */ z-index: 1; /* ترتیب نمایش */ } /* تنظیمات iframe */ .iframe-container iframe { position: absolute; top: -453.54px; /* مخفی کردن 12 سانت از بالا */ left: 0; width: 100%; height: calc((var(--vh, 1vh) * 100) + 1244px); /* افزایش ارتفاع iframe */ border: none; display: 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; } .download-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; left: 10px; /* جابجایی به سمت چپ */ z-index: 10001; text-decoration: none; background-color: #4CAF50; } .download-button:hover { background-color: #45a049; } </style> <!-- دکمه دانلود تصویر --> <p><a href="#" class="download-button" id="downloadButton">دانلود تصویر 📥</a></p> <!-- لودینگ --> <div class="loading" id="loading"> <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 --> <div class="iframe-container"> <iframe id="myIframe" src="https://cohereforai-aya-expanse.hf.space/" scrolling="yes"></iframe> </div> <p> <script> // تابع تنظیم متغیر CSS --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 loading = document.getElementById('loading'); const iframe = document.getElementById('myIframe'); let progressInterval; let errorTimeout; let iframeLoadedFlag = false; // تابع شروع پیشرفت نوار لودینگ function startProgress() { progress = 0; progressBar.style.width = '0%'; loading.style.display = 'flex'; errorMessage.style.display = 'none'; retryButton.style.display = 'none'; progressInterval = setInterval(() => { if (progress < 100) { progress += 10; // افزایش ۱۰٪ در هر ثانیه progressBar.style.width = progress + '%'; } }, 1000); // تایماوت برای نمایش پیام خطا بعد از ۱۰ ثانیه errorTimeout = setTimeout(() => { if (!iframeLoadedFlag) { showError(); } }, 10000); } // تابع بارگذاری موفق iframe function iframeLoaded() { iframeLoadedFlag = true; clearInterval(progressInterval); clearTimeout(errorTimeout); loading.style.display = 'none'; iframe.style.display = 'block'; } // تابع خطا در بارگذاری iframe function iframeError() { clearInterval(progressInterval); clearTimeout(errorTimeout); showError(); } // نمایش خطا function showError() { errorMessage.style.display = 'block'; retryButton.style.display = 'block'; } // بازنشانی لودینگ function resetLoading() { progress = 0; progressBar.style.width = '0%'; iframeLoadedFlag = false; loading.style.display = 'flex'; errorMessage.style.display = 'none'; retryButton.style.display = 'none'; iframe.style.display = 'none'; // اضافه کردن دوباره رویدادها با 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(); }); // رویداد کلیک بر روی دکمه دانلود function handleDownload(event) { event.preventDefault(); if (confirm("برای دانلود تصویر روی تایید کلیک کنید.")) { const iframeDocument = iframe.contentDocument || iframe.contentWindow.document; try { const images = iframeDocument.querySelectorAll('img'); let webpImages = []; images.forEach((img) => { if (img.src.endsWith('.webp')) { webpImages.push(img.src); } }); if (webpImages.length === 0) { alert("هیچ تصویر ساخته شدهای یافت نشد."); return; } // باز کردن اولین تصویر در مرورگر window.open(webpImages[0], '_blank'); } catch (error) { console.error("خطا در شناسایی تصاویر: ", error); alert("خطایی در شناسایی تصاویر رخ داد."); } } } document.getElementById('downloadButton').addEventListener('click', handleDownload); // افزودن رویداد بارگذاری iframe با once: true iframe.addEventListener('load', iframeLoaded, { once: true }); iframe.addEventListener('error', iframeError, { once: true }); // شروع بارگذاری و لودینگ startProgress(); </script> </p>
توضیحات تغییرات:
حذف دکمه توضیحات و جابجایی دکمه دانلود تصویر به سمت چپ:
کد HTML مربوط به دکمه توضیحات حذف شد.
در CSS، کلاس .download-button بهروزرسانی شد تا به سمت چپ منتقل شود:
css.download-button { left: 10px; /* جابجایی به سمت چپ */ right: auto; /* حذف موقعیت قبلی */ }
نمایش یک اعلان ساده هنگام کلیک روی دکمه دانلود تصویر:
handleDownload، تنها یک اعلان confirm نمایش داده میشود و پس از تأیید، کاربر به تصویر هدایت میشود.مخفیسازی بالای صفحه از ۱۱ سانت به ۱۲ سانت:
مقدار top در تنظیمات iframe به -453.54px تغییر داده شد تا ۱۲ سانتیمتر از بالا مخفی شود:
csstop: -453.54px; /* مخفی کردن 12 سانت از بالا */
این مقدار با تبدیل ۱۲ سانتیمتر به پیکسل محاسبه شده است:
12 cm * 37.7952755906 px/cm ≈ 453.54 px
بهبود رفتار لودینگ و نوار پیشرفت هنگام قطع اینترنت یا عدم بارگذاری سایت:
در تابع startProgress، یک تایماوت ۱۰ ثانیهای اضافه شده است که اگر iframe بارگذاری نشود، پیام خطا نمایش داده میشود:
javascripterrorTimeout = setTimeout(() => { if (!iframeLoadedFlag) { showError(); } }, 10000);
رویداد error برای iframe اضافه شده است تا در صورت بروز خطا در بارگذاری، پیام خطا نمایش داده شود:
javascriptiframe.addEventListener('error', iframeError, { once: true });
حذف پنجرههای مودال اضافی و سادهسازی کد:
توجه: لطفاً این کد را با دقت کپی کرده و در محل مناسب قرار دهید. امیدوارم این تغییرات مطابق با خواستههای شما باشد و مشکل نمایش تمامصفحه و رفتار دکمهها برطرف شده باشد.