首页 > 其他分享 >Purify Baidu Search

Purify Baidu Search

时间:2022-09-06 01:55:51浏览次数:61  
标签:Baidu function Search document obj Purify var span ev

// ==UserScript==
// @name         Purify Baidu Search
// @description  百度搜索净化,去除推广链接和默认安装百度杀毒
// @namespace    https://greasyfork.org/zh-CN/scripts/13808
// @version      2.0
// @include      *www.baidu.com*
// @run-at       document-start
// @grant        none
// ==/UserScript==

setInterval(function() {
    if(document.querySelector('.op-soft-checkbox')) 
        document.querySelector('.op-soft-checkbox').checked = '';
}, 1000);

(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;
    };

    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);

标签:Baidu,function,Search,document,obj,Purify,var,span,ev
From: https://www.cnblogs.com/leoTsou/p/16660281.html

相关文章

  • baidu no jump
    //==UserScript==//@namebaidunojump//@namespace1018148046//@description去除百度搜索跳转链接//@includehttp://www.baidu.com/*//@incl......
  • Baidu Search AutoPager
    //==UserScript==//@nameBaiduSearchAutoPager//@authorCrab//@[email protected]//@description百度搜索自动翻页,网站预览图。......
  • elasticsearch版本升级type属性的变化
    type属性的由来从Elasticsearch的第一个发布版本以来,每一个document都被存储在一个单独的index里,并被赋予了一个type,一个mapping代表一个type相关的数据类型以及索引类型。......
  • 论lightdb/postgresql中的search_path及实现兼容性管理
    上一篇介绍了lightdb/postgresqlpublic、pg_catalogschema的区别及pg_namespace概念,因为最近几个版本开发下来,遇到了很多兼容性挑战。所以这一节来专门讨论一下searc......
  • ElasticSearch-全文检索
    1.ElasticSearch-全文检索1.1简介:Elasticsearch是一个分布式的开源搜索和分析引擎,在ApacheLucene的基础上开发而成。Lucene是开源的搜索引擎工具包,Elasticsearch......
  • Elasticsearch 面试题
    Elasticsearch面试题为什么要使用Elasticsearch?系统中的数据,随着业务的发展,时间的推移,将会非常多,而业务中往往采用模糊查询进行数据的搜索,而模糊查询会导致查询引擎......
  • Elasticsearch
    Elasticsearch什么是ElasticsearchElasticsearch、Kibana、Beats和LogstashES是一个开源的高扩展的分布式全文搜索引擎全文搜索引擎这里说到的全文搜索引擎指的是......
  • Elasticsearch 查询 UV
    ES聚合指标value_count:计数cardinality:去重计数avg:平均值sum:求和max:最大值min:最小值percentiles:百分比top_hits:简单来说就是聚合分组后从每一个......
  • ElasticSearch 分组聚合统计
    统计总数:GETmytest-statistics/_search{"size":0,"query":{"bool":{"must":[{"range":{"day":{......
  • 【Vue项目】尚品汇(四)Search组件开发
    Search模块开发分析:1)编写静态页面2)编写api3)编写vuex三大件4)组件获取仓库数据,并进行动态展示1SearchSelector1编写apiexportconstreqGetSearchInfo=(params={}......