偶尔搜到 csdn 的文章,在 csdn 只能看开头,到 web.archive.org 看存档,会自动跳转到到 csdn 首页,十分恼火。
把浏览器的所有请求保存成 har ,丢给 AI , 让 AI 分析后,写 UserScript 阻止跳转,终于能顺利看完全文了。
与交互过程:
user: 从 www.csdn.net.har 分析一下,如何从 web.archive.org 跳转到 csdn.net AI: 根据 HAR 文件分析,无法从 web.archive.org 直接跳转到 csdn.net 。原因如下: bala bala user: 浏览器最终跳转到了 csdn.net ,可能是某个 js 控制的 AI: 找到了!这是 CSDN 的反盗链/反嵌入检测代码。 分析结果 跳转机制 CSDN 在页面底部(隐藏的 <div> 中)有一段通过 <img Onerror=""> 触发的代码: setTimeout(function(){ if(top!==self){ window.top.location.href=window.location.href // 如果在 iframe 中,让顶层跳转 } if(!/(csdn.net|iteye.com|baiducontent.com|googleusercontent.com|360webcache.com|sogoucdn.com|bingj.com)$/.test(window.lo cation.hostname)){ window.location.href="https://www.csdn.net" // 域名不在白名单则跳转 } },3000); // 3 秒延迟 user: 编写 user.js ,禁止这项跳转,仅在 web.archive.org 生效 AI: 已创建 /tmp/csdn-archive-anti-redirect.user.js 功能说明 该脚本只在 web.archive.org 域名下生效,通过多层防护阻止 CSDN 的跳转: ┌──────┬──────────────────────────────────────┐ │ 方法 │ 防护内容 │ ├──────┼──────────────────────────────────────┤ │ 1 │ 拦截 window.location.href 的赋值 │ ├──────┼──────────────────────────────────────┤ │ 2 │ 拦截 window.location.replace() │ ├──────┼──────────────────────────────────────┤ │ 3 │ 拦截 window.location.assign() │ ├──────┼──────────────────────────────────────┤ │ 4 │ 拦截 setTimeout 中包含跳转的回调 │ ├──────┼──────────────────────────────────────┤ │ 5 │ 拦截 <img Onerror=""> 触发的跳转代码 │ └──────┴──────────────────────────────────────┘ 安装方法 1. 安装 Tampermonkey 或 Violentmonkey 2. 点击扩展图标 → 添加新脚本 3. 复制 /tmp/csdn-archive-anti-redirect.user.js 的内容粘贴 4. 保存 测试 访问 https://web.archive.org/web/*/https://blog.csdn.net/...,页面应该不再跳转到 csdn.net ,控制台会显示拦截日志。 写了 5 种拦截方法,安装后删除一些有语法错误的方法,可以正常工作。
脚本地址: https://greasyfork.org/zh-CN/scripts/579931-csdn-archive-org-anti-redirect
