Greasy Fork

【屏蔽百度搜索结果中的广告】

屏蔽百度搜索结果中烦人的广告

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

// ==UserScript==
// @name         【屏蔽百度搜索结果中的广告】
// @namespace    http://tampermonkey.net/
// @version      1.0
// @icon         https://www.baidu.com/favicon.ico
// @description  屏蔽百度搜索结果中烦人的广告
// @author       wushx
// @match        *://*.baidu.com/*
// @grant        none
// @license MIT
// @require      https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js
// ==/UserScript==
let dom = {};
dom.query = jQuery.noConflict(true);
dom.query(document).ready(function ($) {
    const cycletime = 400;
    if (location.href.indexOf('www.baidu.com') > 0) {
        // 右侧栏全部关闭(大部分是广告)
        $("#content_right").remove();
        // top-ad也关闭
        $("#top-ad").remove();
        $(".ec-pl-container").remove();
        $("#content_left > div").each(function () {
            if ($(this).attr('id') === undefined && $('> style', this).attr('id') !== undefined) {
                $(this).remove();
            }
        })
        setInterval(function () {
            // 右侧栏全部关闭(大部分是广告)
            $("#content_right").remove();
            // 搜索结果中有的条目广告
            $("#content_left > div").each(function () {
                if ($(this).attr('id') === undefined && $('> div', this).attr('data-placeid') !== undefined) {
                    $(this).remove();
                }
            })
            // 有延时跳出的广告
            $("a").each(function () {
                if ($(this)[0].innerHTML === '广告') {$(this).parents(".result").remove(); }
            })
            $(".san-card").each(function () {
                if ($(this).attr("tpl") === 'feed-ad') {
                    $(this).remove()
                }
            })
        }, cycletime);
    }

});