در اینجا کد کامل بهروزشده بدون مخفیسازی بخش بالایی و پایینی صفحه آورده شده است. من تمامی بخشهای مربوط به مخفیسازی را حذف کردهام و iframe به صورت کامل و بدون هیچگونه پوششی نمایش داده میشود.
<!DOCTYPE html>
<html lang="fa">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<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: 100%; /* استفاده از 100% به جای متغیر --vh */
overflow: hidden; /* مخفی کردن بخشهای اضافی */
z-index: 1; /* ترتیب نمایش */
}
/* تنظیمات iframe */
.iframe-container iframe {
position: absolute;
top: 0; /* حذف پنهانسازی بالا */
left: 0;
width: 100%;
height: 100%; /* تنظیم ارتفاع به 100% */
border: none;
display: 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://prithivmlmods-grabdoc-v.hf.space/" scrolling="yes"></iframe>
</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');
let progressInterval;
let errorTimeout;
// تابع شروع پیشرفت نوار لودینگ
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;
}
// تابع خطا در بارگذاری 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 با once: true
iframe.addEventListener('load', iframeLoaded, { once: true });
iframe.addEventListener('error', iframeError, { once: true });
// شروع بارگذاری و لودینگ
startProgress();
</script>
</body>
</html>
تغییرات انجام شده:
-
حذف Overlay ها:
- تمامی کدهای مربوط به
.overlay-top و .overlay-bottom در CSS و HTML حذف شد.
- حذف event listeners مربوط به اسکرول کردن iframe از طریق overlay ها در جاوااسکریپت.
-
تنظیمات Iframe:
- در CSS،
top: -170px به top: 0 تغییر یافت.
- ارتفاع iframe از
calc((var(--vh) * 100) + 170px + 38px) به 100% تنظیم شد تا کل فضای قابل نمایش را بپوشاند.
-
حذف متغیرهای مرتبط با مخفیسازی:
- تمامی متغیرها و توابعی که به مخفیسازی مربوط بودند حذف شدند.
-
سایر بهبودها:
- اطمینان حاصل شد که iframe به درستی نمایش داده شود و دیگر نیاز به مخفیسازی نداشته باشد.
- کدها بهینهسازی شدند تا عملکرد صفحه بهبود یابد.
با این تغییرات، iframe شما بدون هیچگونه مخفیسازی در بخشهای بالا و پایین صفحه نمایش داده میشود و کاربران میتوانند به صورت کامل محتویات داخل iframe را مشاهده کنند.