<p> </p> <style> /* تنظیمات پایه برای body و html / html, body { margin: 0;…
- User
/* متغیر CSS برای ارتفاع نمایشگر */ :root { --vh: 100%; } /* حالت عادی */ .iframe-container.normal { position: relative; width: 100%; height: 100vh; overflow: hidden; } .iframe-container.normal iframe { width: 100%; height: 100%; border: none; display: none; position: relative; top: 0; } /* حالت تمام صفحه */ .iframe-container.fullscreen { position: fixed; top: 0; left: 0; width: 100%; height: calc(var(--vh) * 100); overflow: hidden; z-index: 1; } .iframe-container.fullscreen iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: none; display: block; } /* استایلهای مشترک */ .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; }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; let observer; 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'; const iframeContainer = document.querySelector('.iframe-container'); iframeContainer.classList.remove('normal'); iframeContainer.classList.add('fullscreen'); document.getElementById('myIframe').style.display = 'block'; modifyIframeContent(); setupMutationObserver(); } 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(); }); function setVh() { let vh = window.innerHeight * 0.01; document.documentElement.style.setProperty('--vh', `${vh}px`); } setVh(); window.addEventListener('resize', setVh); loadIframe(); startProgress(); function modifyIframeContent() { const iframe = document.getElementById('myIframe'); try { const iframeDocument = iframe.contentDocument || iframe.contentWindow.document; if (!iframeDocument) return; // قطع اتصال MutationObserver if (observer) observer.disconnect(); // مخفی کردن لینکهای ناخواسته const links = iframeDocument.querySelectorAll('a'); links.forEach(link => { if (link.href === 'https://huggingface.co/spaces/yuntian-deng/ChatGPT4Turbo' || link.href === 'https://gradio.app/') { link.style.display = 'none'; } }); // مخفی کردن متنهای ناخواسته const unwantedTexts = [ 'ساخته شده با gradio', 'Use via API', 'Chat Gpt 4o بدون محدودیت در برنامه هوش مصنوعی', 'If this app doesn\'t respond, consider trying our other GPT-4O app:' ]; unwantedTexts.forEach(unwanted => { const textNodes = getTextNodesContaining(iframeDocument.body, unwanted); textNodes.forEach(node => { const parentElement = node.parentElement; if (parentElement) { parentElement.style.display = 'none'; } }); }); // جایگزینی متن 'GPT-4o: Research Preview (Short-Term Availability)' const textNodesToReplace = getTextNodesContaining(iframeDocument.body, 'GPT-4o: Research Preview (Short-Term Availability)'); textNodesToReplace.forEach(node => { node.textContent = node.textContent.replace('GPT-4o: Research Preview (Short-Term Availability)', 'بدون محدودیت Gpt 4o چت'); }); // جایگزینی متن 'Run' با 'ارسال' const runButtons = iframeDocument.querySelectorAll('button, input[type="button"], input[type="submit"]'); runButtons.forEach(element => { if (element.textContent.trim() === 'Run' || element.value === 'Run') { element.textContent = 'ارسال'; element.value = 'ارسال'; } }); // جایگزینی متن 'سلام!' با متن مورد نظر، فقط یکبار const salamNodes = getTextNodesContaining(iframeDocument.body, 'سلام!'); salamNodes.forEach(node => { const parentElement = node.parentElement; if (parentElement && !parentElement.getAttribute('data-replaced')) { node.textContent = node.textContent.replace('سلام!', 'سلام من ربات چت جی پی تی چهار او هستم از برنامه هوش مصنوعی.'); parentElement.setAttribute('data-replaced', 'true'); } }); // اتصال مجدد MutationObserver if (observer) observer.observe(iframeDocument.body, { childList: true, subtree: true }); } catch (error) { console.error("نمیتوان به محتوای iframe دسترسی پیدا کرد: ", error); } } function getTextNodesContaining(node, text) { let textNodes = []; if (node.nodeType === Node.TEXT_NODE && node.nodeValue.includes(text)) { textNodes.push(node); } else { node.childNodes.forEach(child => { textNodes = textNodes.concat(getTextNodesContaining(child, text)); }); } return textNodes; } function setupMutationObserver() { const iframe = document.getElementById('myIframe'); try { const iframeDocument = iframe.contentDocument || iframe.contentWindow.document; if (!iframeDocument) return; observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if (mutation.addedNodes.length) { modifyIframeContent(); } }); }); observer.observe(iframeDocument.body, { childList: true, subtree: true }); } catch (error) { console.error("نمیتوان به محتوای iframe دسترسی پیدا کرد: ", error); } } - Assistant
برای کاهش حجم و سادگی کد شما میتوانیم برخی از توابع مرتبط با مخفیسازی متنها و جایگزینی آنها را حذف کنیم. میتوانیم بهجای اینکه همیشه بهدنبال متنهایی مشخص بگردیم، کد را سادهتر کنیم و فقط به بارگذاری iframe و نمایش آن تمرکز کنیم.
در زیر نسخهی سادهشدهی کد شما را آماده کردهام که شامل بارگذاری iframe و فرآیندهای مرتبط دیگری میباشد، ولی دیگر شامل عملیات مخفیسازی و جایگزینی متنهای داخل آن نخواهد بود:
<!DOCTYPE html> <html lang="fa"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> /* تنظیمات پایه برای body و html */ html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; background-color: #f0f0f0; font-family: Arial, sans-serif; } /* حالت عادی */ .iframe-container { position: relative; width: 100%; height: 100vh; overflow: hidden; } .iframe-container iframe { width: 100%; height: 100%; border: none; display: none; position: relative; top: 0; } /* استایلهای لودینگ */ .loading { display: flex; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); flex-direction: column; align-items: center; z-index: 1000; } .progress { width: 80%; height: 20px; background-color: #ddd; border-radius: 5px; overflow: hidden; } .progress-bar { height: 100%; width: 0; background-color: #4caf50; transition: width 1s; } .error-message, #retryButton { display: none; margin-top: 10px; } </style> </head> <body> <div class="iframe-container"> <div class="loading" id="loadingContainer"> <div class="progress"> <div class="progress-bar" id="progressBar"></div> </div> <div class="error-message" id="errorMessage">بارگیری با خطا مواجه شد.</div> <button id="retryButton">بارگذاری مجدد</button> </div> <iframe id="myIframe"></iframe> </div> <script> const siteURL = 'https://akhaliq-anychat.hf.space'; 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 loadIframe() { const iframe = document.getElementById('myIframe'); iframe.src = siteURL; iframe.onload = iframeLoaded; } retryButton.addEventListener('click', function() { progress = 0; progressBar.style.width = '0%'; iframeLoadedFlag = false; retryButton.style.display = 'none'; errorMessage.style.display = 'none'; loadingContainer.style.display = 'flex'; loadIframe(); startProgress(); }); loadIframe(); startProgress(); </script> </body> </html>در این نسخهی سادهشده:
- تمام توابع و بخشهایی که به مخفیسازی متنها و جایگزینی آنها مربوط میشدند، حذف شده است.
- همچنان بارگذاری iframe و بارگذاری مجدد آن از طریق صفحه نمایش داده میشود.
- استایلها و منطق مربوط به لودینگ و دکمهی بارگذاری مجدد حفظ شدهاند.
این کد حالا سبکتر و سادهتر است و فقط به بارگذاری iframe و مدیریت وضعیت لودینگ متمرکز است.
- User
نوار پیشرفت باشه با مخفی سازی لینک ها
- Assistant
میتوانیم کد شما را طوری تغییر دهیم که نوار پیشرفت قابل مشاهده باشد و همچنین لینکهای خاصی را مخفی کند. در اینجا نسخهی جدید کد شما است که این تغییرات را اعمال میکند:
<!DOCTYPE html> <html lang="fa"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> /* تنظیمات پایه برای body و html */ html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; background-color: #f0f0f0; font-family: Arial, sans-serif; } /* حالت عادی */ .iframe-container { position: relative; width: 100%; height: 100vh; overflow: hidden; } .iframe-container iframe { width: 100%; height: 100%; border: none; display: none; position: absolute; top: 0; left: 0; } /* استایلهای لودینگ */ .loading { display: flex; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); flex-direction: column; align-items: center; z-index: 1000; } .progress { width: 80%; height: 20px; background-color: #ddd; border-radius: 5px; overflow: hidden; } .progress-bar { height: 100%; width: 0; background-color: #4caf50; transition: width 1s; } .error-message, #retryButton { display: none; margin-top: 10px; } </style> </head> <body> <div class="iframe-container"> <div class="loading" id="loadingContainer"> <div class="progress"> <div class="progress-bar" id="progressBar"></div> </div> <div class="error-message" id="errorMessage">بارگیری با خطا مواجه شد.</div> <button id="retryButton">بارگذاری مجدد</button> </div> <iframe id="myIframe"></iframe> </div> <script> const siteURL = 'https://akhaliq-anychat.hf.space'; 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'; // محتوای iframe را تغییر میدهیم modifyIframeContent(); } function loadIframe() { const iframe = document.getElementById('myIframe'); iframe.src = siteURL; iframe.onload = iframeLoaded; } retryButton.addEventListener('click', function() { progress = 0; progressBar.style.width = '0%'; iframeLoadedFlag = false; retryButton.style.display = 'none'; errorMessage.style.display = 'none'; loadingContainer.style.display = 'flex'; loadIframe(); startProgress(); }); loadIframe(); startProgress(); function modifyIframeContent() { const iframe = document.getElementById('myIframe'); try { const iframeDocument = iframe.contentDocument || iframe.contentWindow.document; if (!iframeDocument) return; // مخفی کردن لینکهای ناخواسته const links = iframeDocument.querySelectorAll('a'); links.forEach(link => { if (link.href === 'https://huggingface.co/spaces/yuntian-deng/ChatGPT4Turbo' || link.href === 'https://gradio.app/') { link.style.display = 'none'; } }); } catch (error) { console.error("نمیتوان به محتوای iframe دسترسی پیدا کرد: ", error); } } </script> </body> </html>تغییرات انجام شده:
- بارگذاری iframe: تابع
loadIframeهنوز با بارگذاری URL مربوطه به iframe کار میکند. - نوار پیشرفت: نوار پیشرفت با استفاده از تابع
startProgressپیادهسازی شده است و بهطور متداوم پیشرفت 0 تا 100% را نمایش میدهد. - مخفیسازی لینکها: تابع
modifyIframeContentبرای مخفیسازی لینکهای مشخصشده همچنان وجود دارد و اگر داخل iframe بارگذاری شود، لینکهای ناخواسته را مخفی میکند.
این کد ساده و سبکتر است و شما میتوانید به راحتی آن را با محتوا یا ویژگیهای دیگر گسترش دهید.
- بارگذاری iframe: تابع
- User
نوار پیشرفت که اول بود بعد صفحه بارگذاری میشد اون یکی باشه
- Assistant
با هدف نمایش نوار پیشرفت در ابتدا و سپس بارگذاری صفحه، ما میتوانیم نوار پیشرفت را طوری تنظیم کنیم که در ابتدا نمایش داده شود و پس از اینکه iframe بارگذاری شد، نوار پیشرفت مخفی شود و iframe نمایش داده شود. در زیر نسخه جدید کد شما را آماده کردهام که این رفتار را پیادهسازی میکند:
<!DOCTYPE html> <html lang="fa"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> /* تنظیمات پایه برای body و html */ html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; background-color: #f0f0f0; font-family: Arial, sans-serif; } /* حالت عادی */ .iframe-container { position: relative; width: 100%; height: 100vh; overflow: hidden; } .iframe-container iframe { width: 100%; height: 100%; border: none; display: none; /* مخفی به طور پیشفرض */ position: absolute; top: 0; left: 0; } /* استایلهای لودینگ */ .loading { display: flex; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); flex-direction: column; align-items: center; z-index: 1000; } .progress { width: 80%; height: 20px; background-color: #ddd; border-radius: 5px; overflow: hidden; } .progress-bar { height: 100%; width: 0; background-color: #4caf50; transition: width 1s; } .error-message, #retryButton { display: none; margin-top: 10px; } </style> </head> <body> <div class="iframe-container"> <div class="loading" id="loadingContainer"> <div class="progress"> <div class="progress-bar" id="progressBar"></div> </div> <div class="error-message" id="errorMessage">بارگیری با خطا مواجه شد.</div> <button id="retryButton">بارگذاری مجدد</button> </div> <iframe id="myIframe"></iframe> </div> <script> const siteURL = 'https://akhaliq-anychat.hf.space'; 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'; // نمایش iframe // مخفی کردن لینکهای ناخواسته modifyIframeContent(); } function loadIframe() { const iframe = document.getElementById('myIframe'); iframe.src = siteURL; iframe.onload = iframeLoaded; } retryButton.addEventListener('click', function() { progress = 0; progressBar.style.width = '0%'; iframeLoadedFlag = false; retryButton.style.display = 'none'; errorMessage.style.display = 'none'; loadingContainer.style.display = 'flex'; // نمایش لودینگ loadIframe(); startProgress(); }); loadIframe(); startProgress(); function modifyIframeContent() { const iframe = document.getElementById('myIframe'); try { const iframeDocument = iframe.contentDocument || iframe.contentWindow.document; if (!iframeDocument) return; // مخفی کردن لینکهای ناخواسته const links = iframeDocument.querySelectorAll('a'); links.forEach(link => { if (link.href === 'https://huggingface.co/spaces/yuntian-deng/ChatGPT4Turbo' || link.href === 'https://gradio.app/') { link.style.display = 'none'; } }); } catch (error) { console.error("نمیتوان به محتوای iframe دسترسی پیدا کرد: ", error); } } </script> </body> </html>ویژگیهای این نسخه:
- نوار پیشرفت: ابتدا نوار پیشرفت نشان داده میشود و در حین بارگذاری iframe پیشرفت را نمایش میدهد.
- مخفیسازی لودینگ: پس از بارگذاری iframe، نوار لودینگ مخفی میشود و iframe نمایش داده میشود.
- مخفیسازی لینکها: لینکهای مشخصشده همچنان در محتوای iframe مخفی میشوند.
این کد بهطور کامل تمام خواستهها و ویژگیهای شما را پیادهسازی میکند.