Baidu:绕过百度重定向直接访问网页

繞過百度搜索結果中的自己的跳轉鏈接,直接訪問原始網頁-反正都能看懂

当前为 2015-11-24 提交的版本,查看 最新版本

// ==UserScript==
// @name Baidu:绕过百度重定向直接访问网页
// @author         AC
// @namespace      [email protected]
// @description    繞過百度搜索結果中的自己的跳轉鏈接,直接訪問原始網頁-反正都能看懂
// @version        1.0
// @create         2015-11-25
// @lastmodified   2015-11-25
// @include         /^https?\:\/\/www.baidu.[^\/]+/
// @copyright      2015+, AC
// @run-at         document-end
// @grant		    GM_xmlhttpRequest
// @icon            https://coding.net/u/zb227/p/zbImg/git/raw/master/icon.jpg
// ==/UserScript==

// 采用MutationObserver监视会大大实际代码的调用次数-比DOMNodeInserted更好的调用方式

var targets;
var list;
if(location.href.indexOf('www.baidu') > -1){
    targets = document.querySelector("#content_left"); // 百度
} 
mo = new MutationObserver(function(allmutations) {
    // 注意querySelectorAll得到的对象是静态的,所以每次重复调用的时候需要更新
    list = document.querySelectorAll(".t a");
    resetURL();
});
mo.observe(targets, {'childList': true, 'subtree': true});
function resetURL(){
    for(var i = 0; i < list.length; i++){
        // 此方法是异步,故在结束的时候使用i会出问题-严重!
        // 采用调用前通过context过去,调用结束后通过response.context获得
        GM_xmlhttpRequest({
                url: list[i].href,
                headers: {
                    "Accept": "text/xml"
                },
                context: i+1, //直接传递i,在i=0的时候反馈回来时null-猜想被会被转换掉,所以+1
                method: "GET",
                onload: function(response) {
                    var index = response.context-1; 
                    document.querySelectorAll(".t a")[index].href=response.finalUrl;
                }
       });
    }
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址