در این کد متن ساخته شده با gradio مخفی کن دیده نشه و همچنین این متن Use via API…
- User
در این کد متن ساخته شده با gradio مخفی کن دیده نشه و همچنین این متن Use via API
code - Assistant
در این کد متن ساخته شده با gradio مخفی کن دیده نشه و همچنین این متن Use via API
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 hideSpecificText() {
const iframe = document.getElementById('myIframe');
try {
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
if (!iframeDocument) return;
// جستجو و جایگزینی متن "Use via API" با "ساخته شده با Gradio"
const elements = iframeDocument.querySelectorAll('*');
elements.forEach(element => {
if (element.textContent.trim() === 'Use via API') {
element.textContent = 'ساخته شده با Gradio';
}
});
// همچنین مخفی کردن متون "Use via API" و "Use via APIlogo ·"
const textsToHide = ['Use via API', 'Use via APIlogo ·'];
textsToHide.forEach(text => {
elements.forEach(element => {
if (element.textContent.trim() === text) {
element.style.display = 'none';
}
});
});
} catch (error) {
console.error("نمیتوان به محتوای iframe دسترسی پیدا کرد: ", error);
}
}
function setupTextReplacement() {
const iframe = document.getElementById('myIframe');
try {
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
if (!iframeDocument) return;
hideSpecificText();
const observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.addedNodes.length) {
hideSpecificText();
}
});
});
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';
hideSpecificText();
setupTextReplacement();
}
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>
/* متغیر 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);
}
}
برای مخفی کردن متون "Use via API" و "ساخته شده با Gradio" در صفحات بارگذاریشده توسط Gradio داخل iframe و همچنین بهینهسازی کد با استفاده از الگوی دوم، میتوانید از کد زیر استفاده کنید. در این نسخه:
modifyIframeContent و setupMutationObserver استفاده شده تا به صورت پویا محتوای iframe را تغییر دهد و متون ناخواسته را مخفی کند.<!DOCTYPE html>
<html lang="fa">
<head>
<meta charset="UTF-8">
<title>Gradio Iframe Hider</title>
<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-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;
}
/* استایل دکمه اسکرول */
.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>
</head>
<body>
<!-- لودینگ و iframe -->
<div class="iframe-container normal">
<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" sandbox="allow-scripts allow-same-origin allow-forms allow-modals" allow="clipboard-read; clipboard-write"></iframe>
</div>
<!-- دکمه اسکرول -->
<div class="scroll-handle" id="scrollHandle">
<div class="up"></div>
<div class="down"></div>
</div>
<script>
const siteURL = 'https://cultrix-qrcode-read-generate.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');
const scrollHandle = document.getElementById('scrollHandle');
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';
scrollHandle.style.display = 'flex';
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();
});
// دکمههای اسکرول
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);
}
});
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;
// مخفی کردن لینکهای ناخواسته
const links = iframeDocument.querySelectorAll('a');
links.forEach(link => {
if (link.href.includes('gradio.app') || link.href.includes('huggingface.co')) {
link.style.display = 'none';
}
});
// مخفی کردن متنهای ناخواسته
const unwantedTexts = [
'Use via API',
'ساخته شده با Gradio',
'Use via APIlogo ·'
];
unwantedTexts.forEach(unwanted => {
const elements = iframeDocument.querySelectorAll('*');
elements.forEach(element => {
if (element.textContent.trim() === unwanted) {
element.style.display = 'none';
}
});
});
// جایگزینی متنهای خاص
const replacements = {
'Use via API': 'ساخته شده با Gradio',
'GPT-4o: Research Preview (Short-Term Availability)': 'بدون محدودیت Gpt 4o چت',
'Run': 'ارسال',
'سلام!': 'سلام من ربات چت جی پی تی چهار او هستم از برنامه هوش مصنوعی.'
};
Object.keys(replacements).forEach(originalText => {
const replacementText = replacements[originalText];
const textNodes = getTextNodesContaining(iframeDocument.body, originalText);
textNodes.forEach(node => {
node.textContent = node.textContent.replace(originalText, replacementText);
if (originalText === 'سلام!') {
const parentElement = node.parentElement;
if (parentElement && !parentElement.getAttribute('data-replaced')) {
parentElement.setAttribute('data-replaced', 'true');
}
}
});
});
// مخفی کردن دکمهها با متن "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 = 'ارسال';
}
});
} 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);
}
}
</script>
</body>
</html>
حذف کدهای مخفیسازی قبلی:
hideSpecificText و مخفیسازی ابتدایی که در کد اولیه وجود داشتند، حذف شدهاند تا از تداخل با روش جدید جلوگیری شود.افزودن توابع جدید برای مخفیسازی و جایگزینی متن:
modifyIframeContent: این تابع محتوای iframe را بررسی کرده و متون ناخواسته را مخفی میکند یا جایگزین میکند.getTextNodesContaining: این تابع برای یافتن نودهای متنی که شامل متن خاصی هستند، استفاده میشود.setupMutationObserver: این تابع یک MutationObserver راهاندازی میکند که هر بار که نود جدیدی به iframe اضافه میشود، تابع modifyIframeContent را فراخوانی میکند تا تغییرات جدید را اعمال کند.تنظیمات CSS:
iframe, محتوای آن به صورت کامل صفحه نمایش داده شود و دسترسی به عناصر کنترل مورد نیاز فراهم شود.مدیریت فازهای بارگذاری:
iframe, کاربر بتواند با کلیک روی دکمه "بارگذاری مجدد" دوباره تلاش کند.اسکرول دستی:
iframe پیمایش انجام دهد.مخفیسازی لینکها و دکمههای خاص:
gradio.app یا huggingface.co اشاره دارند، مخفی شدهاند.محدودیت Cross-Origin: اگر iframe شما به دامنهای دیگر اشاره دارد، مرورگرها معمولاً دسترسی به محتوای داخلی آن را به دلایل امنیتی محدود میکنند. در چنین مواردی، توابع جاوااسکریپت نمیتوانند به محتوای داخلی iframe دسترسی پیدا کنند و تغییرات اعمال شده نخواهند شد. برای این که این روش کار کند، باید iframe به همان دامنهای که صفحه اصلی در آن قرار دارد اشاره داشته باشد یا تنظیمات CORS اجازه دسترسی را بدهد.
Sandboxing: ویژگیهای sandbox در iframe باید به گونهای تنظیم شوند که دسترسیهای لازم برای تغییر محتوا مجاز باشند. در کد بالا، sandbox شامل allow-scripts, allow-same-origin, allow-forms, و allow-modals میباشد که معمولاً برای این کار کافی است.
با استفاده از این کد، متون "Use via API" و "ساخته شده با Gradio" در محتوای iframe مخفی شده و جایگزین میشوند. همچنین این کد به صورت پویا تغییرات را در iframe مدیریت میکند تا حتی در صورت افزودن نودهای جدید، تغییرات مدنظر شما اعمال شوند. مطمئن شوید که تنظیمات CORS و sandbox به درستی پیکربندی شدهاند تا این روش به درستی کار کند.
Not yet included in a published release.