如何去除百度搜索广告推广链接?去百度搜索置顶推广脚本.js

    相信网友们都很烦百度的推广链接,明明是想搜索自己想要的东西,但使用百度搜索,前面的几个搜索结果都是广告推广链接,一点进去就是广告,那我们怎样去除百度搜索上面和下面的广告推广链接?去百度搜索置顶推广脚本浏览器插件下载:文章源自技术奇点-https://www.xerer.com/archives/13777.html

    去除插入在百度搜索结果头部、尾部的推广链接。
    如何安装此脚本?文章源自技术奇点-https://www.xerer.com/archives/13777.html

    插件名称:去百度搜索置顶推广.user.js文章源自技术奇点-https://www.xerer.com/archives/13777.html

    插件下载地址:文章源自技术奇点-https://www.xerer.com/archives/13777.html

    https://greasyfork.org/zh-CN/scripts/10019-%E5%8E%BB%E7%99%BE%E5%BA%A6%E6%90%9C%E7%B4%A2%E7%BD%AE%E9%A1%B6%E6%8E%A8%E5%B9%BF
    试用之后,您可以提问、评论或举报这个脚本。
    版本2015.8.26文章源自技术奇点-https://www.xerer.com/archives/13777.html

    作者axetroy文章源自技术奇点-https://www.xerer.com/archives/13777.html

    创建日期2015-05-22文章源自技术奇点-https://www.xerer.com/archives/13777.html

    最近更新2015-08-2文章源自技术奇点-https://www.xerer.com/archives/13777.html

    如何去除百度搜索广告推广链接?去百度搜索置顶推广脚本.js
    去百度搜索置顶推广脚本描述
    简介:文章源自技术奇点-https://www.xerer.com/archives/13777.html

    去除插入在百度搜索结果头部和尾部的推广链接。文章源自技术奇点-https://www.xerer.com/archives/13777.html

    推荐使用我的另一个脚本,效果更佳:
    去除百度跳转链接:https://greasyfork.org/zh-CN/scripts/11915文章源自技术奇点-https://www.xerer.com/archives/13777.html

    //更新日志
    2015.8.26
    [优化]:优化了去广告规则
    [优化]:小部分优化
    [修复]:修复了上版本更新之后,可能带来的浏览器崩溃问题。
    [整理]:整理代码结构,使之更清晰。文章源自技术奇点-https://www.xerer.com/archives/13777.html

    2015.8.22
    [更改]:更改异步加载的监听方式,抛弃DOMNodeinserted使用更为优雅的Mutation
    [新增]:在搜索结果的头部显示已经屏蔽的推广链接数量
    [优化]:代码规范化文章源自技术奇点-https://www.xerer.com/archives/13777.html

     文章源自技术奇点-https://www.xerer.com/archives/13777.html

    以下是去百度搜索置顶推广.user.js的代码:文章源自技术奇点-https://www.xerer.com/archives/13777.html

    // ==UserScript==
    // @name 去百度搜索置顶推广
    // @author burningall
    // @description 去除插入在百度搜索结果头部、尾部的推广链接。
    // @version 2015.8.26
    // @grant none
    // @include *www.baidu.com*
    // @supportURL http://www.burningall.com
    // @run-at document-start
    // @contributionURL [email protected]|alipay.com
    // @namespace https://greasyfork.org/zh-CN/users/3400-axetroy
    // ==/UserScript==文章源自技术奇点-https://www.xerer.com/archives/13777.html

    (function(document) {
    function handler(obj) {
    return new Event(obj);
    }
    function Event(obj) {
    this.element = obj;
    return this;
    }
    Event.prototype.addEvent = function(type, fn) {
    var obj = this.element;
    var ev;
    return obj.addEventListener ?
    obj.addEventListener(type, function(e) {
    ev = window.event ? window.event : (e ? e : null);
    ev.target = ev.target || ev.srcElement;
    if (fn.call(obj, ev) === false) {
    ev.cancelBubble = true; //阻止冒泡
    ev.preventDefault(); //chrome,firefox下阻止默认事件
    }
    }, false) :
    obj.attachEvent('on' + type, function(e) {
    ev = window.event ? window.event : (e ? e : null);
    ev.target = ev.target || ev.srcElement;
    if (fn.call(obj, ev) === false) {
    ev.cancelBubble = true; //阻止冒泡
    return false; //阻止默认事件,针对IE8
    }
    });
    };
    Event.prototype.bind = function(type, fn) {
    var obj = this.element;
    if (arguments.length == 1) {
    for (var attr in type) {
    this.addEvent(attr, type[attr]);
    }
    } else if (arguments.length == 2) {
    var events = type.split(' ');
    var eventsLength = events.length;
    var j = 0;
    while (j < eventsLength) {
    this.addEvent(events[j], fn);
    j++;
    }
    }
    return this;
    };
    Event.prototype.ob = function(config, fn) {
    var target = this.element;
    var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver,
    observer = new MutationObserver(function(mutations) {
    mutations.forEach(function(mutation) {
    fn.call(target);
    });
    });
    observer.observe(target, config);
    return this;
    };文章源自技术奇点-https://www.xerer.com/archives/13777.html

    function init() {
    return new RemoveAds();
    }
    function RemoveAds() {
    this.ads = document.querySelectorAll('#content_left>div:not([class*=result]):not([class*=container]):not(.leftBlock):not([adsFilted]),#content_left>table:not(.result):not([adsFilted])');
    this.length = this.ads.length;
    var a = {};
    var temps = [];
    for( var i=0;i<this.length;i++){
    var v = this.ads[i];
    if( typeof a[v] =="undefined" ){
    a[v] = 1;
    temps.push( v );
    }
    }
    this.ads = temps;
    this.length =this.ads.length;
    }
    var count = {
    "num":0,
    "hadChange":false
    };
    RemoveAds.prototype.filter = function(){
    for(var i=0;i<this.length;i++ ){
    this.ads[i].style.cssText = "display:none !important";
    this.ads[i].setAttribute("adsFilted","");
    console.log( this.ads[i] );
    count.num++;
    }
    count.hadChange = this.length>0 ? true : false;
    return this;
    };
    RemoveAds.prototype.showTip = function() {
    if( count.hadChange !== true ) return this;
    var insertPos = document.querySelector('.nums');
    if (insertPos) {
    var span = document.querySelector('span.adTip') || document.createElement('span'),
    spanTextStr = "……累计过滤" + count.num + "条推广链接";
    if (this.tipWord) {
    if( span.innerText ){
    span.innerText = spanTextStr;
    }else{
    span.textContent = spanTextStr;
    }
    } else {
    if( span.innerText ){
    span.innerText = spanTextStr;
    }else{
    span.textContent = spanTextStr;
    }
    span.className = "adTip";
    insertPos.appendChild(span);
    }
    }
    count.hadChange = false;
    };
    handler(document).bind("DOMContentLoaded",function(){
    handler(this).ob({
    "childList":true,
    "subtree":true
    },function(){
    init().filter().showTip();
    });
    });
    })(document);文章源自技术奇点-https://www.xerer.com/archives/13777.html

    文章源自技术奇点-https://www.xerer.com/archives/13777.html
    weinxin
    微信公众号
    扫码关注公众号获取资源下载及吃瓜爆料
    • 本文由 发表于 2015/09/2323:35:09

    发表评论

    匿名网友