<p> </p> <style> /* تنظیمات پایه برای body و html / html, body { margin: 0;…
- Usercode
- Assistant
/* متغیر 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: -226.77px; /* پنهان کردن ۶ سانتیمتر بالای صفحه (226.77px) */
left: 0;
width: 100%;
height: calc((var(--vh) * 100) + 226.77px + 38px); /* افزایش ارتفاع iframe به اندازه ۶ سانتیمتر بالا و ۱ سانتیمتر پایین */
border: none;
display: none; /* مخفی کردن iframe تا بارگذاری موفق */
}
/* Overlay برای مخفی کردن بخش بالایی صفحه */
.overlay-top {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 226.77px; /* ارتفاع ۶ سانتیمتر (226.77px) */
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>
// تابع تنظیم متغیر 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;
// اگر Same-Origin است، CSS را برای مخفی کردن متون مشکی اضافه کنید
try {
const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
// اضافه کردن استایل برای مخفی کردن فقط متون مشکی
const style = iframeDoc.createElement('style');
style.innerHTML = `
/* پنهان کردن متنهای مشکی */
*:not(script):not(style) {
color: inherit !important;
text-shadow: 0 0 0 rgba(255,255,255,0.7) !important;
}
*:not(script):not(style)::before,
*:not(script):not(style)::after {
color: inherit !important;
text-shadow: 0 0 0 rgba(255,255,255,0.7) !important;
}
/* استایل خاص برای متنهای مشکی */
*:not(script):not(style):not([style*="color"]):not(svg *),
*:not(script):not(style):not([style*="color"]):not(svg *)::before,
*:not(script):not(style):not([style*="color"]):not(svg *)::after {
color: transparent !important;
text-shadow: none !important;
}
`;
iframeDoc.head.appendChild(style);
} catch (e) {
console.warn('دسترسی به محتوای iframe محدود شده است:', e);
}
}
// تابع خطا در بارگذاری 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();
</script>
متوجه درخواست شما شدم که میخواهید:
در ادامه، راهنماییهایی برای انجام این تغییرات ارائه میدهم.
در کد شما، بخشهایی وجود دارد که با استفاده از CSS داخل iframe متون را مخفی میکنند. برای نمایش متون، باید این بخشها را حذف یا غیرفعال کنید.
const style = iframeDoc.createElement('style');
style.innerHTML = `
/* پنهان کردن متنهای مشکی */
*:not(script):not(style) {
color: inherit !important;
text-shadow: 0 0 0 rgba(255,255,255,0.7) !important;
}
*:not(script):not(style)::before,
*:not(script):not(style)::after {
color: inherit !important;
text-shadow: 0 0 0 rgba(255,255,255,0.7) !important;
}
/* استایل خاص برای متنهای مشکی */
*:not(script):not(style):not([style*="color"]):not(svg *),
*:not(script):not(style):not([style*="color"]):not(svg *)::before,
*:not(script):not(style):not([style*="color"]):not(svg *)::after {
color: transparent !important;
text-shadow: none !important;
}
`;
iframeDoc.head.appendChild(style);
برای نمایش متون، میتوانید این بخش از کد را کامنت کنید یا کاملاً حذف نمایید. به عنوان مثال:
// const style = iframeDoc.createElement('style');
// style.innerHTML = `
// /* پنهان کردن متنهای مشکی */
// *:not(script):not(style) {
// color: inherit !important;
// text-shadow: 0 0 0 rgba(255,255,255,0.7) !important;
// }
// *:not(script):not(style)::before,
// *:not(script):not(style)::after {
// color: inherit !important;
// text-shadow: 0 0 0 rgba(255,255,255,0.7) !important;
// }
// /* استایل خاص برای متنهای مشکی */
// *:not(script):not(style):not([style*="color"]):not(svg *),
// *:not(script):not(style):not([style*="color"]):not(svg *)::before,
// *:not(script):not(style):not([style*="color"]):not(svg *)::after {
// color: transparent !important;
// text-shadow: none !important;
// }
// `;
// iframeDoc.head.appendChild(style);
مخفی کردن شکلکها نیازمند دسترسی به محتوای iframe و اعمال تغییراتی بر روی آن است. با این حال، توجه داشته باشید که به دلیل سیاستهای امنیتی مرورگر (سیاست Same-Origin)، ممکن است نتوانید بدون دسترسی مناسب به محتوای iframe اقدام به تغییرات کنید. اگر دامنه iframe با دامنه صفحه شما یکی نیست، دسترسی به محتوای آن محدود خواهد بود.
اگر دسترسی به محتوای iframe دارید، میتوانید از CSS و JavaScript برای مخفی کردن شکلکها استفاده کنید.
میتوانید با استفاده از CSS سعی کنید محدوده کاراکترهای Emoji را مخفی کنید. اما این روش کاملاً کامل نیست و ممکن است بعضی از شکلکها نمایش داده شوند.
/* مخفی کردن Emojiها با استفاده از CSS */
body *:not(script):not(style):not(svg *) {
font-family: Arial, sans-serif !important;
}
body *:not(script):not(style):not(svg *)::after,
body *:not(script):not(style):not(svg *)::before {
content: none !important;
}
میتوانید از JavaScript برای پیمایش محتوای iframe و حذف کاراکترهای Emoji استفاده کنید.
function removeEmojis(element) {
for (let node of element.childNodes) {
if (node.nodeType === 3) { // متن
node.textContent = node.textContent.replace(/[\u{1F600}-\u{1F64F}]/gu, '');
} else {
removeEmojis(node);
}
}
}
// فراخوانی فانکشن پس از لود محتوا
removeEmojis(iframeDoc.body);
در زیر نسخه بهروزشده کد شما با اعمال تغییرات مورد نظر ارائه شده است:
حذف CSS مخفیسازی متون: در قسمت iframeLoaded، تمام تگهای <style> موجود داخل iframe را حذف میکنیم تا اطمینان حاصل شود متون نمایش داده میشوند.
مخفی کردن Emojiها:
U+1F600 تا U+1F64F) را از محتوای متنی حذف میکنیم.سیاست Same-Origin: اگر دامنه iframe (https://jbilcke-hf-FacePoke.hf.space/) با دامنه صفحه شما متفاوت باشد، مرورگر به دلایل امنیتی اجازه دسترسی به محتوا و اعمال تغییرات را نمیدهد. در این حالت، کدی که برای تغییرات استفاده شده است، با خطا مواجه خواهد شد و نمیتواند اعمال شود.
تست و تنظیم: ممکن است نیاز باشد محدوده Unicode در تابع removeEmojis را متناسب با نیاز خود تنظیم کنید تا تمام شکلکهای مورد نظر را پوشش دهد.
امیدوارم این راهنما به شما کمک کند تا به هدف خود برسید. در صورت بروز هرگونه سوال یا نیاز به توضیحات بیشتر، خوشحال میشوم که کمک کنم.
موفق باشید!
Not yet included in a published release.
<!DOCTYPE html>
<html lang="fa">
<head>
<meta charset="UTF-8">
<title>صفحه با iframe</title>
<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: -226.77px; /* پنهان کردن ۶ سانتیمتر بالای صفحه (226.77px) */
left: 0;
width: 100%;
height: calc((var(--vh) * 100) + 226.77px + 38px); /* افزایش ارتفاع iframe به اندازه ۶ سانتیمتر بالا و ۱ سانتیمتر پایین */
border: none;
display: none; /* مخفی کردن iframe تا بارگذاری موفق */
}
/* Overlay برای مخفی کردن بخش بالایی صفحه */
.overlay-top {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 226.77px; /* ارتفاع ۶ سانتیمتر (226.77px) */
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>
</head>
<body>
<!-- لودینگ -->
<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://jbilcke-hf-FacePoke.hf.space/" scrolling="yes"></iframe>
</div>
<!-- Overlay برای مخفی کردن بخش بالایی صفحه -->
<div class="overlay-top" id="overlayTop"></div>
<!-- Overlay برای مخفی کردن بخش پایینی صفحه -->
<div class="overlay-bottom" id="overlayBottom"></div>
<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;
// اگر Same-Origin است، CSS را برای مدیریت محتوای iframe اضافه کنید
try {
const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
// حذف CSS قبلی که متون را مخفی میکرد (در صورت وجود)
const existingStyles = iframeDoc.querySelectorAll('style');
existingStyles.forEach(style => {
style.remove();
});
// اضافه کردن استایل برای مخفی کردن Emojiها
const emojiStyle = iframeDoc.createElement('style');
emojiStyle.innerHTML = `
/* استفاده از فونت بدون Emoji */
body, body * {
font-family: Arial, sans-serif !important;
}
`;
iframeDoc.head.appendChild(emojiStyle);
// حذف Emojiها با استفاده از JavaScript
function removeEmojis(element) {
for (let node of element.childNodes) {
if (node.nodeType === 3) { // متن
node.textContent = node.textContent.replace(/[\u{1F600}-\u{1F64F}]/gu, '');
} else {
removeEmojis(node);
}
}
}
removeEmojis(iframeDoc.body);
} catch (e) {
console.warn('دسترسی به محتوای iframe محدود شده است:', e);
}
}
// تابع خطا در بارگذاری 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();
</script>
</body>
</html>