Greasy Fork

Greasy Fork is available in English.

AC-百度去广告

去掉百度的推广链接

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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)
        }
    }
}