const siteURL = 'https://akhaliq-anychat.hf.space';
const excludeUrls = new Set([
'https://yanze-pulid.hf.space/--replicas/3t64n/file=/tmp/gradio/7567beceda2541f726af7beb4c9aa857b4a96b77/liuyifei.png',
'https://prodiazenafey-faceswap.hf.space/file=/tmp/gradio/44ce6237aa956835c13beb89ae4c83f8afea7edb/example3.jpg',
'https://cohereforai-aya-expanse.hf.space/gradio_api/file=/tmp/gradio/195e9bc39ae67221fa523905a8a7f36b44bb03ebd3310192cf2ad0235b29fc1b/AyaExpanse.png'
]);
const progressBar = document.getElementById('progressBar');
const retryButton = document.getElementById('retryButton');
const errorMessage = document.getElementById('errorMessage');
const loadingContainer = document.getElementById('loadingContainer');
const iframe = document.getElementById('myIframe');
let iframeLoadedFlag = false;
let mutationObserver = null;
let debounceTimeout = null;
let startTime = null;
let progressInterval = null;
function hideUnwantedElements() {
try {
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
if (!iframeDocument) return;
// مخفی یا جایگزین کردن تصاویر مشخصشده
const images = iframeDocument.querySelectorAll('img');
images.forEach(img => {
if (img.src.endsWith('.png')) {
img.src = 'https://app.puzzley.net/uploads/user/Jydo/هوش%20مصنوعی/Negar_1731256487636.png';
}
});
// مخفی کردن لینکهای مشخصشده
const linksToHide = new Set([
'https://docs.cohere.com/docs/c4ai-acceptable-use-policy',
'https://gradio.app/',
'https://huggingface.co/openai/whisper-large-v3-turbo',
'https://groq.com/',
'http://neets.ai/',
'https://huggingface.co/black-forest-labs/FLUX.1-schnell'
]);
const links = iframeDocument.querySelectorAll('a');
links.forEach(link => {
if (
linksToHide.has(link.href) ||
link.textContent.trim().includes("C4AI's Acceptable Use Policy")
) {
link.style.display = 'none';
}
});
// مخفی یا جایگزین کردن متون مشخصشده
const unwantedTexts = [
"C4AI Aya Expanse is a state-of-art model with highly advanced capabilities to connect the world across languages.",
"You can use this space to chat, speak and visualize with Aya Expanse in 23 languages.",
"Made with gradio",
"Whisper large-v3-turbo",
"Groq",
"Gemini coder",
"Speak with Aya",
"neets.ai",
"Flux Schnell",
"This space uses Aya Expanse for translating multilingual prompts and generating detailed image descriptions and Flux Schnell for Image Generation.",
"To enable voice interaction with Aya Expanse, this space uses Whisper large-v3-turbo and Groq for STT and neets.ai for TTS."
];
const textsToReplace = {
"Aya Expanse": "هوش مصنوعی",
"Describe an image": "چه عکسی برات بسازم توضیحات تو بنویس تا در لحظه تبدیل به تصویر کنم(نسخه فلاکس رایگان)",
"Visualize with Aya": "🖼️ساخت تصاویر",
"Submit": "ارسال",
"Clear": "پاک",
"Load example prompt for:": "این نسخه رایگان است برای ساخت تصاویر زیباتر و با کیفیت تر به قسمت ساخت عکس مراجعه کنید و از فلاکس پرو پیشرفته استفاده کنید",
"Chat with Aya": "🤖چت",
"Open Ai": "هوش مصنوعی"
};
unwantedTexts.forEach(unwanted => {
const textNodes = getTextNodesContaining(iframeDocument.body, unwanted);
textNodes.forEach(node => {
const parentElement = node.parentElement;
if (parentElement) {
parentElement.style.display = 'none';
}
});
});
Object.keys(textsToReplace).forEach(originalText => {
const newText = textsToReplace[originalText];
const textNodes = getTextNodesContaining(iframeDocument.body, originalText);
textNodes.forEach(node => {
node.textContent = node.textContent.replace(new RegExp(escapeRegExp(originalText), 'g'), newText);
});
});
} catch (error) {
console.error("نمیتوان به محتوای iframe دسترسی پیدا کرد: ", error);
}
}
function getTextNodesContaining(node, text) {
let textNodes = [];
const walker = document.createTreeWalker(node, NodeFilter.SHOW_TEXT, {
acceptNode: function(node) {
return node.nodeValue.includes(text) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT;
}
}, false);
while(walker.nextNode()) {
textNodes.push(walker.currentNode);
}
return textNodes;
}
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
function iframeLoaded() {
iframeLoadedFlag = true;
clearInterval(progressInterval);
// Animate progress bar to 100% over 4 seconds
progressBar.style.transition = 'width 4s linear';
progressBar.style.width = '100%';
// After 4 seconds, hide loading and show iframe
setTimeout(() => {
hideLoadingAndShowIframe();
}, 4000);
}
function iframeError() {
clearInterval(progressInterval);
errorMessage.style.display = 'block';
retryButton.style.display = 'block';
progressBar.style.width = '0%';
progressBar.style.transition = 'none';
}
function setupElementHiding() {
try {
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
if (!iframeDocument) return;
hideUnwantedElements();
// استفاده از MutationObserver با تنظیمات بهینه
if (mutationObserver) {
mutationObserver.disconnect();
}
mutationObserver = new MutationObserver(function(mutations) {
if (debounceTimeout) {
clearTimeout(debounceTimeout);
}
debounceTimeout = setTimeout(() => {
hideUnwantedElements();
}, 500); // تاخیر 500 میلیثانیه
});
mutationObserver.observe(iframeDocument.body, {
childList: true,
subtree: true
});
} catch (error) {
console.error("نمیتوان به محتوای iframe دسترسی پیدا کرد: ", error);
}
}
retryButton.addEventListener('click', function() {
loadIframe();
});
function hideLoadingAndShowIframe() {
loadingContainer.style.display = 'none';
const iframeContainer = document.querySelector('.iframe-container');
iframeContainer.classList.remove('normal');
iframeContainer.classList.add('fullscreen');
iframe.style.display = 'block';
hideUnwantedElements();
setupElementHiding();
}
function loadIframe() {
clearInterval(progressInterval);
progressBar.style.width = '0%';
progressBar.style.transition = 'none';
loadingContainer.style.display = 'flex';
errorMessage.style.display = 'none';
retryButton.style.display = 'none';
iframe.style.display = 'none';
iframeLoadedFlag = false;
// Reset progress bar
progressBar.style.width = '0%';
progressBar.style.transition = 'width 0.2s ease';
// Start simulated progress up to 90%
let progress = 0;
startTime = Date.now();
progressInterval = setInterval(() => {
if (progress < 90) {
progress += Math.random() * 5; // Increment by random value to simulate progress
if (progress > 90) progress = 90;
progressBar.style.width = progress + '%';
}
}, 200); // Update every 200ms
// Load the iframe
fetch(siteURL, { method: 'HEAD', mode: 'no-cors' })
.then(() => {
iframe.src = siteURL;
iframe.onload = iframeLoaded;
iframe.onerror = iframeError;
})
.catch(() => {
iframeError();
});
}
// شروع بارگذاری iframe
loadIframe();
</script>
در کد شما، متن "Open AI" به دلیل تفاوت در حروف بزرگ و کوچک (حساسیت به حروف بزرگ و کوچک) همچنان نمایش داده میشد. برای رفع این مشکل، نیاز است که کد را به گونهای تنظیم کنیم که جایگزینی و مخفی کردن متنها به صورت غیر حساس به حروف بزرگ و کوچک انجام شود. همچنین باید مطمئن شویم که تمامی موارد "Open AI" (با حروف بزرگ و کوچک متفاوت) را پوشش دهیم.
در زیر کد اصلاحشده ارائه شده است:
html
<style>
:root {
--color-primary: #4CAF50;
--color-secondary: rgb(84, 110, 122);
--color-danger: #f44336;
--color-white: #ffffff;
--color-black: #000000;
--color-gray: #f0f0f0;
--color-light-gray: #ddd;
--color-green: #4caf50;
--color-hover: #d32f2f;
}
body {
margin: 0;
padding: 0;
overflow: hidden;
height: calc(var(--vh, 1vh) * 100);
background-color: #f0f0f0;
font-family: Arial, sans-serif;
text-align: center;
direction: rtl;
}
/* حالت عادی */
.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, 1vh) * 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 0.2s ease;
}
.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;
transition: background-color 0.3s;
}
#retryButton:hover {
background-color: #45a049;
}
/* اعلان */
.notification {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: #ffffff;
padding: 20px 30px;
border-radius: 5px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
z-index: 10003;
display: none;
text-align: center;
width: 90%;
max-width: 400px;
max-height: 80vh;
overflow-y: auto;
}
.notification-buttons {
display: flex;
justify-content: center;
margin-top: 20px;
flex-wrap: wrap;
}
.notification-buttons button {
background-color: #4CAF50;
color: #ffffff;
border: none;
padding: 5px 10px;
border-radius: 5px;
cursor: pointer;
margin: 5px;
}
.notification-buttons button:hover {
background-color: #45a049;
}
/* استایلهای مربوط به تصاویر و دکمه ذخیره */
.image-container {
margin-bottom: 20px;
}
.save-image-button {
background-color: #4CAF50;
color: #ffffff;
border: none;
padding: 5px 10px;
border-radius: 5px;
cursor: pointer;
margin-top: 10px;
}
.save-image-button:hover {
background-color: #45a049;
}
</style>
<!-- لودینگ و 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>
<!-- افزودن ویژگیهای sandbox و allow به iframe -->
<iframe id="myIframe" sandbox="allow-scripts allow-same-origin allow-forms allow-modals" allow="clipboard-read; clipboard-write"></iframe>
</div>
<script>
// تنظیم ارتفاع متغیر CSS --vh برای سازگاری با موبایل
function setVhVariable() {
let vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', vh + 'px');
}
setVhVariable();
window.addEventListener('resize', setVhVariable);
const siteURL = 'https://akhaliq-anychat.hf.space';
const excludeUrls = new Set([
'https://yanze-pulid.hf.space/--replicas/3t64n/file=/tmp/gradio/7567beceda2541f726af7beb4c9aa857b4a96b77/liuyifei.png',
'https://prodiazenafey-faceswap.hf.space/file=/tmp/gradio/44ce6237aa956835c13beb89ae4c83f8afea7edb/example3.jpg',
'https://cohereforai-aya-expanse.hf.space/gradio_api/file=/tmp/gradio/195e9bc39ae67221fa523905a8a7f36b44bb03ebd3310192cf2ad0235b29fc1b/AyaExpanse.png'
]);
const progressBar = document.getElementById('progressBar');
const retryButton = document.getElementById('retryButton');
const errorMessage = document.getElementById('errorMessage');
const loadingContainer = document.getElementById('loadingContainer');
const iframe = document.getElementById('myIframe');
let iframeLoadedFlag = false;
let mutationObserver = null;
let debounceTimeout = null;
let startTime = null;
let progressInterval = null;
function hideUnwantedElements() {
try {
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
if (!iframeDocument) return;
// مخفی یا جایگزین کردن تصاویر مشخصشده
const images = iframeDocument.querySelectorAll('img');
images.forEach(img => {
if (img.src.endsWith('.png')) {
img.src = 'https://app.puzzley.net/uploads/user/Jydo/هوش%20مصنوعی/Negar_1731256487636.png';
}
});
// مخفی کردن لینکهای مشخصشده
const linksToHide = new Set([
'https://docs.cohere.com/docs/c4ai-acceptable-use-policy',
'https://gradio.app/',
'https://huggingface.co/openai/whisper-large-v3-turbo',
'https://groq.com/',
'http://neets.ai/',
'https://huggingface.co/black-forest-labs/FLUX.1-schnell'
]);
const links = iframeDocument.querySelectorAll('a');
links.forEach(link => {
if (
linksToHide.has(link.href) ||
link.textContent.trim().includes("C4AI's Acceptable Use Policy")
) {
link.style.display = 'none';
}
});
// مخفی یا جایگزین کردن متون مشخصشده
const unwantedTexts = [
"C4AI Aya Expanse is a state-of-art model with highly advanced capabilities to connect the world across languages.",
"You can use this space to chat, speak and visualize with Aya Expanse in 23 languages.",
"Made with gradio",
"Whisper large-v3-turbo",
"Groq",
"Gemini coder",
"Speak with Aya",
"neets.ai",
"Flux Schnell",
"This space uses Aya Expanse for translating multilingual prompts and generating detailed image descriptions and Flux Schnell for Image Generation.",
"To enable voice interaction with Aya Expanse, this space uses Whisper large-v3-turbo and Groq for STT and neets.ai for TTS.",
"Open AI"
];
const textsToReplace = {
"Aya Expanse": "هوش مصنوعی",
"Describe an image": "چه عکسی برات بسازم توضیحات تو بنویس تا در لحظه تبدیل به تصویر کنم(نسخه فلاکس رایگان)",
"Visualize with Aya": "🖼️ساخت تصاویر",
"Submit": "ارسال",
"Clear": "پاک",
"Load example prompt for:": "این نسخه رایگان است برای ساخت تصاویر زیباتر و با کیفیت تر به قسمت ساخت عکس مراجعه کنید و از فلاکس پرو پیشرفته استفاده کنید",
"Chat with Aya": "🤖چت",
"Open Ai": "هوش مصنوعی",
"Open AI": "هوش مصنوعی"
};
unwantedTexts.forEach(unwanted => {
const textNodes = getTextNodesContaining(iframeDocument.body, unwanted);
textNodes.forEach(node => {
const parentElement = node.parentElement;
if (parentElement) {
parentElement.style.display = 'none';
}
});
});
Object.keys(textsToReplace).forEach(originalText => {
const newText = textsToReplace[originalText];
const textNodes = getTextNodesContaining(iframeDocument.body, originalText);
textNodes.forEach(node => {
node.textContent = node.textContent.replace(new RegExp(escapeRegExp(originalText), 'gi'), newText);
});
});
} catch (error) {
console.error("نمیتوان به محتوای iframe دسترسی پیدا کرد: ", error);
}
}
function getTextNodesContaining(node, text) {
let textNodes = [];
const walker = document.createTreeWalker(node, NodeFilter.SHOW_TEXT, {
acceptNode: function(node) {
return node.nodeValue.toLowerCase().includes(text.toLowerCase()) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT;
}
}, false);
while(walker.nextNode()) {
textNodes.push(walker.currentNode);
}
return textNodes;
}
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
function iframeLoaded() {
iframeLoadedFlag = true;
clearInterval(progressInterval);
// Animate progress bar to 100% over 4 seconds
progressBar.style.transition = 'width 4s linear';
progressBar.style.width = '100%';
// After 4 seconds, hide loading and show iframe
setTimeout(() => {
hideLoadingAndShowIframe();
}, 4000);
}
function iframeError() {
clearInterval(progressInterval);
errorMessage.style.display = 'block';
retryButton.style.display = 'block';
progressBar.style.width = '0%';
progressBar.style.transition = 'none';
}
function setupElementHiding() {
try {
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
if (!iframeDocument) return;
hideUnwantedElements();
// استفاده از MutationObserver با تنظیمات بهینه
if (mutationObserver) {
mutationObserver.disconnect();
}
mutationObserver = new MutationObserver(function(mutations) {
if (debounceTimeout) {
clearTimeout(debounceTimeout);
}
debounceTimeout = setTimeout(() => {
hideUnwantedElements();
}, 500); // تاخیر 500 میلیثانیه
});
mutationObserver.observe(iframeDocument.body, {
childList: true,
subtree: true
});
} catch (error) {
console.error("نمیتوان به محتوای iframe دسترسی پیدا کرد: ", error);
}
}
retryButton.addEventListener('click', function() {
loadIframe();
});
function hideLoadingAndShowIframe() {
loadingContainer.style.display = 'none';
const iframeContainer = document.querySelector('.iframe-container');
iframeContainer.classList.remove('normal');
iframeContainer.classList.add('fullscreen');
iframe.style.display = 'block';
hideUnwantedElements();
setupElementHiding();
}
function loadIframe() {
clearInterval(progressInterval);
progressBar.style.width = '0%';
progressBar.style.transition = 'none';
loadingContainer.style.display = 'flex';
errorMessage.style.display = 'none';
retryButton.style.display = 'none';
iframe.style.display = 'none';
iframeLoadedFlag = false;
// Reset progress bar
progressBar.style.width = '0%';
progressBar.style.transition = 'width 0.2s ease';
// Start simulated progress up to 90%
let progress = 0;
startTime = Date.now();
progressInterval = setInterval(() => {
if (progress < 90) {
progress += Math.random() * 5; // Increment by random value to simulate progress
if (progress > 90) progress = 90;
progressBar.style.width = progress + '%';
}
}, 200); // Update every 200ms
// Load the iframe
fetch(siteURL, { method: 'HEAD', mode: 'no-cors' })
.then(() => {
iframe.src = siteURL;
iframe.onload = iframeLoaded;
iframe.onerror = iframeError;
})
.catch(() => {
iframeError();
});
}
// شروع بارگذاری iframe
loadIframe();
</script>
توضیحات اصلاحات انجام شده:
حساسیت به حروف بزرگ و کوچک در جستجو: در تابع getTextNodesContaining، جستجو را به صورت غیر حساس به حروف بزرگ و کوچک انجام دادیم:
جایگزینی متن به صورت غیر حساس به حروف بزرگ و کوچک: در بخش جایگزینی متنها، از عبارت منظم با فلگهای gi استفاده کردیم تا جایگزینی به صورت غیر حساس به حروف بزرگ و کوچک انجام شود: