Greasy Fork

Greasy Fork is available in English.

去百度搜索置顶推广

去除插入在百度搜索结果头部、尾部的推广链接。

当前为 2015-08-26 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name    去百度搜索置顶推广
// @author  burningall
// @description 去除插入在百度搜索结果头部、尾部的推广链接。
// @version     2015.8.22
// @include     *www.baidu.com*
// @supportURL      http://www.burningall.com
// @run-at      document-start
// @contributionURL [email protected]|alipay.com
// @namespace http://greasyfork.icu/zh-CN/users/3400-axetroy
// ==/UserScript==

(function(document) {

    function ob(target, config, fn) {
        var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
        var observer = new MutationObserver(function(mutations) {
            mutations.forEach(function(mutation) {
                fn.call(target);
            });
        });
        observer.observe(target, config);
    }

    function init() {
        return new RemoveAds();
    }

    function RemoveAds() {
        this.ads = document.querySelectorAll('#content_left>*');
        this.length = this.ads.length;
        for (var i = 0; i < this.length; i++) {
            this.id = this.ads[i].getAttribute("id");
            if (this.id > 1000 || this.id === null) {
                num++;
                this.ads[i].style.cssText = "display: none !important;";
                this.ads[i].remove(this);
                // console.log( this.ads[i] );
                this.showTip();
            }
        }
    }
    var num = 0;
    RemoveAds.prototype.showTip = function() {
        this.tip = document.querySelectorAll('.nums')[0];
        if (this.tip) {
            this.tipWord = document.querySelectorAll('span.adTip')[0];
            this.span = this.tipWord || document.createElement('span');
            if (this.tipWord) {
                this.span.textContent = "……已过滤" + num + "条推广链接";
            } else {
                this.span.textContent = "……已过滤" + num + "条推广链接";
                this.span.className = "adTip";
                this.tip.appendChild(this.span);
            }
        }
    };
    ob(document, {
        "childList": true,
        "subtree": true
    }, function() {
        init();
    });
})(document);