屏蔽百度广告,让你百度搜索变得简单一些~

屏蔽百度广告, 尽可能的减少搜索时的广告干扰

질문, 리뷰하거나, 이 스크립트를 신고하세요.
// ==UserScript==
// @name         屏蔽百度广告,让你百度搜索变得简单一些~
// @namespace    http://tampermonkey.net/
// @version      1.1.0
// @description  屏蔽百度广告, 尽可能的减少搜索时的广告干扰
// @author       daniel
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAVoUlEQVR4Xu2debAc1XXGv9NPC3rTI8DS9CCMQ0yRmOkRlBPsmJi4AJMgCBaVlEvsYINYzC42sUogsQmBWMQqHNtgwIBFKmXAmJgiqAzlhCROOUTTgwMpnEAsTY/EoumRQOj1SQ16jzye3jJ9+3ZPL2f+ffece853zu/2m57uewnyEQVEgTEVINFGFBAFxlZAAJHuEAXGUUAAkfYQBQQQ6QFRQE0BuYKo6SZWOVFAAMlJoSVNNQUEEDXdxConCgggOSm0pKmmgACipptY5UQBASQnhZY01RQQQNR0E6ucKCCA5KTQkqaaAgKImm5ilRMFBJCcFFrSVFNAAFHTTaxyooAAkpNCS5pqCgggarqJVU4UEEByUmhJU00BAURNN7HKiQICSE4KLWmqKSCAqOkmVjlRQADJSaElTTUFBBA13cQqJwoIIDkptKSppoAAoqabWOVEAQEkJ4WWNNUUEEDUdBOrnCgggOSk0JKmmgICiJpuYpUTBQSQnBRa0lRTIFeAvPNfe+28U/9OXxiA368mV76tjEmTvA+MD/5zxow3NuVFicwDwnzwpPYGdxkzjiLgD/JS2EjzJNQBPFuYaV1OtGZbpHP12HmmAdm8wf6K7/MygA7usc4ZnZ7XGAZd3j/TeSWjCSKzgGx27Xk+8D0AxawWLyF5tQxgfr/lrE5IPFrDyCQgrfWVY8igx7UqJc7GVYB9Pra4W/2JrMmUOUBa6yvHkkGPZa1QaciHiY8rluqZWpgyBYjXrB4H5h+loZkyGyPR8WaplpkFKjOAeM3q8WB+NLONl6bEiE4wS7VMLFSZAMRr2ieA8Uiae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JKTQkuaagoIIGq6iVVOFBBAclJoSVNNAQFETTexyokCAkhOCi1pqikggKjpJlY5UUAAyUmhJU01Bf4Pr9/RMoYtvhIAAAAASUVORK5CYII=
// @include      https://www.baidu.com/*
// @require      https://libs.baidu.com/jquery/2.1.4/jquery.min.js
// @grant        unsafeWindow
// @grant        GM_openInTab
// @grant        GM.openInTab
// @grant        GM_getValue
// @grant        GM.getValue
// @grant        GM_setValue
// @grant        GM.setValue
// @grant        GM_xmlhttpRequest
// @grant        GM.xmlHttpRequest
// @grant        GM_registerMenuCommand
// ==/UserScript==

/**
 * 比较div最后一个tag内容是否等于content
 *      是: display设置为none
 * @param div   dom
 * @param tag   tag
 * @param content content
 */
function clcGuangGao(div, tag, content) {
    let $tags = $(div).find(tag)
    let tags = $tags.get()  //所有span的dom对象
    let length = tags.length;
    let targetElement = $tags.get(length - 1)   //最后一个

    if (targetElement) {
        let text = targetElement.innerText;
        if (text === content) {
            div.style.display = 'none'
        }
    }
}

/**
 * 清除广告
 */
function clearGg() {
    // 清除左边广告
    let $divs = $('#content_left > div')
    if ($divs) {
        let divs = $divs.get();  // $转为dom对象

        for (let div of divs) {
            // hideElementIfLastTagContentIsContent(div, 'span', '广告')
            // 我们发现广告的class不带result
            //     后来又发现真正的搜索结果带有id
            if (!div.id) {
                div.style.display = 'none'
            }
            // 主要针对二次弹出广告
            clcGuangGao(div, 'a', '广告');
        }
    }
    // 清除右边广告
    // let $divs_right = $('#content_right > div')
    // if ($divs_right) {
    //     let tuiguangDiv = $divs_right.get(0)
    //
    //     hideElementIfLastTagContentIsContent(tuiguangDiv, 'span', '广告')
    // }
}

/**
 * 隐藏dom,如果最后一个或者倒数第二个tag的文本内容等于content
 *  例: hideElementIfLastTagContentIsContent(element, 'span', '广告')
 *      如果 element(dom元素) 下的最后一个或者倒数第二个 span 元素的文本内容为 '广告' ,那么就隐藏该 element
 * @param element dom元素
 * @param tag   指定标签名(如 'span','a')
 * @param content 指定内容
 */
function hideElementIfLastTagContentIsContent(element, tag, content) {
    let $tags = $(element).find(tag)
    let tags = $tags.get()  //所有span的dom对象
    let length = tags.length;
    let targetElement = $tags.get(length - 1)   //最后一个span
    let secondLastElement = $tags.get(length - 2)  //倒数第二个span

    if (targetElement && secondLastElement) {
        let text = $(targetElement).text();
        let secondLast_text = $(secondLastElement).text();
        // console.log(text)
        if (text === content || secondLast_text === content) {
            element.style.display = 'none'
        }
    }
}


/**
 * 循环清除广告
 * @param n 循环次数
 */
function clearGgByCount(n) {
    let count = n
    let interval = setInterval(() => {
        if (count === 0) {
            clearInterval(interval)
            // console.log("清除广告结束...")
            return
        }
        clearGg();
        count--
    }, 500)
}

/**
 * 循环清除广告
 *      防止广告二次弹出
 * @param n 间隔时间(单位ms)
 */
function cycleClearGg(n = 500) {
    setInterval(() => {
        clearGg()
    }, n)
}


(function () {
    'use strict';

    // const $ = $ || window.$
    // Your code here...
    // 循环清理, 防止二次弹出, 因此搜索内容可能会因为屏蔽了广告而闪动一下
    cycleClearGg()
})();