.iframe-container {
position: relative;
width: 100%;
height: 100vh;
overflow: hidden;
}
iframe {
width: 100%;
height: 100%;
border: none;
display: none;
position: relative;
top: 0;
/* انتقال ویژگیهای sandbox و allow به تگ iframe */
sandbox="allow-scripts allow-same-origin allow-forms allow-modals"
allow="clipboard-read; clipboard-write";
}
.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;
}
/* استایل دکمه اسکرول */
.scroll-handle {
position: fixed;
right: 15px;
top: 50%;
transform: translateY(-50%);
z-index: 9999;
width: 45px;
height: 90px;
border-radius: 20px;
background-color: #ffffff;
box-shadow: 0px 0px 5px rgba(0,0,0,0.3);
display: none; /* مخفی تا زمانی که iframe بارگذاری شود */
align-items: center;
justify-content: center;
flex-direction: column;
}
.scroll-handle .up, .scroll-handle .down {
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
cursor: pointer;
}
.scroll-handle .up {
border-bottom: 15px solid #333;
margin-bottom: 10px;
}
.scroll-handle .down {
border-top: 15px solid #333;
margin-top: 10px;
}
</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 hideUnwantedElements() {
const iframe = document.getElementById('myIframe');
try {
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
if (!iframeDocument) return;
// مخفی کردن لینکهای خاص
const linksToHide = [
'https://gradio.app/',
];
const links = iframeDocument.querySelectorAll('a');
links.forEach(link => {
if (linksToHide.includes(link.href)) {
link.style.display = 'none';
}
});
// مخفی کردن متون خاص
const unwantedTexts = [
"Use via APIlogo ·",
"Use via API"
];
unwantedTexts.forEach(unwanted => {
const elements = Array.from(iframeDocument.body.getElementsByTagName("*")).filter(element => {
return element.textContent.trim() === unwanted;
});
elements.forEach(element => {
element.style.display = 'none';
});
});
// مخفی کردن هر گونه متن مرتبط با Gradio (به صورت کلی)
const gradioElements = Array.from(iframeDocument.body.querySelectorAll('*')).filter(element => {
return element.textContent.includes('Gradio');
});
gradioElements.forEach(element => {
element.style.display = 'none';
});
// جایگزینی متنها
// جایگزینی 'Submit' با 'شروع ساخت'
const submitButtons = Array.from(iframeDocument.querySelectorAll('button')).filter(button => button.textContent.trim() === 'Submit');
submitButtons.forEach(button => { button.textContent = 'شروع ساخت'; });
// جایگزینی 'Clear' با 'پاک کردن'
const clearButtons = Array.from(iframeDocument.querySelectorAll('button')).filter(button => button.textContent.trim() === 'Clear');
clearButtons.forEach(button => { button.textContent = 'پاک کردن'; });
// **حذف جایگزینی 'Output Prompt'**
// const outputPromptElements = Array.from(iframeDocument.querySelectorAll('*')).filter(el => el.textContent.trim() === 'Output Prompt');
// outputPromptElements.forEach(el => { el.textContent = 'خروجی پرامپت شما'; });
} catch (error) {
console.error("نمیتوان به محتوای iframe دسترسی پیدا کرد: ", error);
}
}
function setupElementHiding() {
const iframe = document.getElementById('myIframe');
try {
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
if (!iframeDocument) return;
hideUnwantedElements();
const observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.addedNodes.length) {
hideUnwantedElements();
}
});
});
observer.observe(iframeDocument.body, {
childList: true,
subtree: true
});
} catch (error) {
console.error("نمیتوان به محتوای iframe دسترسی پیدا کرد: ", error);
}
}
function iframeLoaded() {
iframeLoadedFlag = true;
clearInterval(interval);
loadingContainer.style.display = 'none';
document.getElementById('myIframe').style.display = 'block';
scrollHandle.style.display = 'flex';
hideUnwantedElements();
setupElementHiding();
}
function iframeError() {
clearInterval(interval);
loadingContainer.style.display = 'flex';
retryButton.style.display = 'block';
errorMessage.style.display = 'block';
}
function loadIframe() {
fetch(siteURL, { method: 'HEAD', mode: 'no-cors' })
.then(() => {
const iframe = document.getElementById('myIframe');
iframe.src = siteURL;
iframe.onload = iframeLoaded;
iframe.onerror = iframeError;
})
.catch(() => {
iframeError();
});
}
retryButton.addEventListener('click', function() {
progress = 0;
progressBar.style.width = '0%';
iframeLoadedFlag = false;
retryButton.style.display = 'none';
errorMessage.style.display = 'none';
loadingContainer.style.display = 'flex';
document.getElementById('myIframe').style.display = 'none';
loadIframe();
startProgress();
});
// دکمههای اسکرول
scrollHandle.addEventListener('click', (event) => {
const iframe = document.getElementById('myIframe');
if (event.target.classList.contains('up')) {
iframe.contentWindow.scrollBy(0, -100);
} else if (event.target.classList.contains('down')) {
iframe.contentWindow.scrollBy(0, 100);
}
});
// فراخوانی تابع بارگذاری iframe و شروع لودینگ
loadIframe();
startProgress();
</script>