Greasy Fork

Greasy Fork is available in English.

【去广告 屏蔽广告 广告拦截 百度广告 百度联盟广告 谷歌广告】@LYS-广告拜拜助手(适配手机)

1、净化百度搜索结果中插入广告;2、净化推送广告;3、指定规则净化页面插入广告……

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

// ==UserScript==
// @name         【去广告 屏蔽广告 广告拦截 百度广告 百度联盟广告 谷歌广告】@LYS-广告拜拜助手(适配手机)
// @namespace    http://tampermonkey.net/
// @version      1.7
// @description  1、净化百度搜索结果中插入广告;2、净化推送广告;3、指定规则净化页面插入广告……
// @author       LYS
// @match        */*
// @run-at       document-end
// @icon         none
// @grant        none
// @license      MIT
// ==/UserScript==
(function () {
    'use strict';
    
    //判断是否为百度搜索页面,则判断手机/PC端后直接开始循环屏蔽页面插入广告,不进入后面过程
    var url = window.location.href
    if (url.includes("www.baidu.com/") || url.includes("m.baidu.com/")) {

        if (url.includes("m.baidu.com/")) {
            setInterval(function () {
                $('.ec_ad_results').hide();
            }, 500);
        } else {
            setInterval(function () {
                $('#content_left div:contains("广告")').slideUp()
            }, 500)
        }

    } else {

        //定义预设推送域:csdn广告、百度广告、谷歌广告等,后续可继续按格式添加(HTML页面内容清除为空白)
        var ads = ["kunpeng-sc.csdnimg.cn/",
            "pos.baidu.com/",
            "g.doubleclick.net",
            "pagead2.googlesyndication.com",
            "tpc.googlesyndication.com",
            "cs.emxdgt.com",
            "sync.richaudience.com",
            "gum.criteo.com",
            "ads.pubmatic.com",
            "eus.rubiconproject.com",
            "hde.tynt.com",
            "ssbsync.smartadserver.com",
            "simage2.pubmatic.com",
            "onetag-sys.com",
            "sync.aniview.com",
            "imasdk.googleapis.com",
            "mp.4dex.io",
            "acdn.adnxs.com",
            "safeframe.googlesyndication.com",
            "s.amazon-adsystem.com",
            "rtb.gumgum.com",
            "ap.lijit.com",
            "usersync.gumgum.com",
            "sync.inmobi.com"
        ]

        //定义预设屏蔽规则:油猴、opgg、csdn等,后续可继续按格式添加
        var adsattr = [
            ["greasyfork.org/", ".ad.ad-ca", "#carbonads"],
            ["op.gg/", "[id*='mobile-app-install']", "[class*='einfil']"],
            [".csdn.net/", "[class*='ad-box']", "#kp_box_www_swiper"]
        ]

        var attr = ["", ""]

        //判断当前页是否属于预设推送广告域,是则已清除全页面,非则继续判断jquery
        var nopush = false
        for (var i = 0; i < ads.length; i++) {
            if (url.includes(ads[i])) {
                document.getElementsByTagName('head').innerHTML = "";
                document.getElementsByTagName('title').innerHTML = "";
                document.getElementsByTagName('body')[0].innerHTML = "";
                nopush = true
                break
            }
        }

        if (nopush == false) {

            //判断页面是否存在引用jquery
            var isjqexist = false
            var sp = document.getElementsByTagName('script')
            Array.prototype.slice.bind(sp)
            for (var l = 0; l < sp.length; l++) {
                if (sp[l].getAttribute("src") != null) {
                    if (sp[l].getAttribute("src").includes("jquery")) {
                        console.log(sp[l].getAttribute("src"))
                        isjqexist = true
                        break
                    }
                }
            }
            //如未引用则加载jquery
            if (isjqexist) {
                console.log("无需额外引用jQuery!")
            } else {
                var script = document.createElement("script");
                script.type = "text/javascript";
                script.src = "https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js";
                document.getElementsByTagName('head')[0].appendChild(script);
            }

            isjqexist = false


            //判断jquery资源是否加载完成
            var isjq = setInterval(function () {
                if (typeof jQuery != "undefined") {
                    console.log("jQuery已经加载完成!")
                    clearInterval(isjq);
                    getcurruturl();
                    if (attr[0] != "") {
                        setInterval(function () {
                            killinnerads();
                        }, 1000);
                    }

                } else {
                    console.log("等待jQuery加载完成!")
                }
            }, 100)
        }

    }



    //当前页面规则匹配
    var getcurruturl = function () {
        for (var i = 0; i < adsattr.length; i++) {
            if (url.includes(adsattr[i][0])) {
                attr = adsattr[i]
                return attr
            }
        }
    }

    //按规则筛选屏蔽屏蔽DOM
    var killinnerads = function () {
        console.log("正在针对[" + attr[0] + "]规则进行监控!")
        for (var j = 1; j < attr.length; j++) {
            $(attr[j]).hide()
        }
    }

})();