Greasy Fork

Greasy Fork is available in English.

AC-百度去广告

去掉百度的推广链接

目前为 2017-03-20 提交的版本,查看 最新版本

// ==UserScript==
// @name AC-百度去广告
// @namespace ACNoAdd
// @description 去掉百度的推广链接
// @include http://www.baidu.com/*
// @include https://www.baidu.com/*
// @version 4.0
// @grant none
// @author AC
// @icon            https://coding.net/u/zb227/p/zbImg/git/raw/master/img0/icon.jpg
// @run-at document-end
// ==/UserScript==
document.body.addEventListener("DOMNodeInserted", removeAD, false);

function removeAD(){
    var no = document.getElementById("content_right");
    if(no != null) no.remove();
    var fathers = document.querySelectorAll("#content_left")[0].childNodes;
    
    var lastId = 0;
    for(var i = 0; i < fathers.length; i++){
        var currentNode = fathers[i];
        if(fathers[i].tagName=="DIV" && fathers[i].getAttribute("dealAD") == null){
            if(null == currentNode.id || "" == currentNode.id){
                // 米有ID的貌似都是广告
                currentNode.remove();
            } else if(currentNode.id == "clone"){
                // ID 显示为CLONE的也是广告
                currentNode.remove();
            } else if(currentNode.className.indexOf("result") != 0 && /^\d+$/.test(currentNode.id)){
                // class不是result...的,并且id是纯粹数字的(很大)
                currentNode.remove();
            }
            currentNode.setAttribute("dealAD", 1)
        }
    }
}