Greasy Fork is available in English.

百度贴吧不可能会跳转!

去除贴吧帖子里链接的跳转

您查看的为 2017-05-15 13:01:41 UTC 提交的版本。查看 最新版本

// ==UserScript==
// @id             tieba_url_no_jump
// @name           百度贴吧不可能会跳转!
// @version        2017.05.15
// @namespace      jiayiming
// @author         jiayiming
// @description    去除贴吧帖子里链接的跳转
// @include        *://tieba.baidu.com/p/*
// @include        *://tieba.baidu.com/f?ct*
// @homepageURL    https://greasyfork.org/scripts/783/
// @grant          GM_xmlhttpRequest
// @run-at         document-end
// @note           2017.05.15 支持https
// @note           2014.07.19 转帖用XHR+HEAD获取地址,其他照旧
// ==/UserScript==

var locationHref = location.href;

function decode(url,target){
    GM_xmlhttpRequest({
        method: 'HEAD',
        url: url,
        headers: {
            "Referer": locationHref,
        },
        onload: function(response) {
            var newUrl = response.finalUrl;
            //console.log(newUrl);
            target.setAttribute('href', newUrl);
        }
    })
}

function run() {
    var urls = document.querySelectorAll('a[href^="http://jump.bdimg.com/safecheck"]');
    for (var i = 0; i < urls.length; i++) {
        if (urls[i].parentNode.className == "apc_src_wrapper") {
            decode(urls[i],urls[i]);
        }
        else {
            var url = urls[i].childNodes[0].nodeValue;
            if (url.indexOf("http") < 0)
                url = "http://" + url;
            console.log(url);
            urls[i].setAttribute("href", url);
        }
    }
}
 
function addMutationObserver(selector, callback) {
    var watch = document.querySelector(selector);
    if (!watch) return;
 
    var observer = new MutationObserver(function(mutations){
        var nodeAdded = mutations.some(function(x){ return x.addedNodes.length > 0; });
        if (nodeAdded) {
            // observer.disconnect();
            callback();
        }
    });
    observer.observe(watch, {childList: true, subtree: true});
}
 
 
run();
 
addMutationObserver('#j_p_postlist', run);