RemoveAds

需要配合AdBlockPro使用!该脚本可以移除那些使用!important来规避ABP反广告功能的广告,仅此而已。

Tính đến 29-11-2018. Xem phiên bản mới nhất.

// ==UserScript==
// @name            RemoveAds
// @name:en         RemoveAds
// @version         1.5.1
// @description     需要配合AdBlockPro使用!该脚本可以移除那些使用!important来规避ABP反广告功能的广告,仅此而已。
// @description:en  This script can remove the ads which use some CSS like "style='display: block!important;'" to avoid AdBlockPro blocking them. Just it.
// @author          AnnAngela
// @match           *://*/*
// @run-at          document-start
// @grant           unsafeWindow
// @grant           none
// @namespace       https://greasyfork.org/users/129402
// ==/UserScript==

(function() {
    "use strict";
    /* 防止重复加载 */
    if (unsafeWindow.RemoveAds) return;
    console.info('RemoveAds running.');
    unsafeWindow.removedAds = [];

    if ((location.host.includes('bbs.nga.cn') || location.host.includes('bbs.ngacn.cc')) && location.pathname.includes('adpage_insert')) {
        var stylesheet = document.createElement('style');
        stylesheet.innerText = 'html, body, * { display: none!important; }';
        unsafeWindow.document.body.appendChild(stylesheet);
        var jump = function jump() {
            if (unsafeWindow.getJump) {
                var _getJump = unsafeWindow.getJump.bind(unsafeWindow);
                unsafeWindow.getJump = function() {};
                _getJump();
            }
        };
        setInterval(jump, 10);
    } else if (location.hostname === "www.ruanyifeng.com") {
        console.info("RemoveAds: removed the anti-adb checker.");
        Object.defineProperty(unsafeWindow, "checker", {
            configurable: false,
            enumerable: false,
            writable: false,
            value: function() {
                console.info("RemoveAds: Got a call to the anti-adb checker but denied.");
            }
        });
    }

    unsafeWindow.removeAd = function removeAd() {
        if (location.host.endsWith("baidu.com")) Array.from(unsafeWindow.document.querySelectorAll('span')).forEach(function(that) {
            if (/^(广告)+$/.test(that.innerText.replace(/s/g, ''))) {
                console.info('RemoveAds: ', removedAds.push(that), '\n', that, '\n', that.parentNode, '\n', that.innerText);
                that.remove();
            }
        });
        else if (location.host.endsWith('gamepedia.com'))(function loop(document) {
            var siderail = document.querySelector('#siderail');
            if (siderail) siderail.remove();
            else setTimeout(loop, 100, document);
            var globalWrapper = document.querySelector('#global-wrapper.with-siderail');
            if (globalWrapper) globalWrapper.classList.remove('with-siderail');
        })(unsafeWindow.document);
        var nodes = Array.from(unsafeWindow.document.querySelectorAll('[style*="important"]'));
        if (!nodes.length) return;
        nodes.forEach(function(that) {
            var style = (that.attributes.style.textContent + '').replace(/\s/g, '');
            var display = (style.match(/display:([a-z\-]+)\!important/ig) || []).map(n => n.match(/display:([a-z\-]+)\!important/i)[1]);
            var displayCheck = [];
            display.forEach(function(n) {
                if (n !== 'none') displayCheck.push(n);
            });
            if (displayCheck.length === 0) return;
            that.attributes.style.textContent = style.replace(/display:([a-z\-]+)\!important/ig, '');
            if (getComputedStyle(that).display === 'none' || /^(广告)+$/.test(that.innerText.replace(/s/g, ''))) {
                that.attributes.style.textContent = style + '';
                console.info('RemoveAds: ', removedAds.push(that), '\n', that, '\n', that.parentNode, '\n', that.innerText);
                that.remove();
            } else that.attributes.style.textContent = style + '';
        });
    };
    document.addEventListener('DOMContentLoaded', function() {
        if (location.href.indexOf('www.baidu.com/s') !== -1) setInterval(function() {
            removeAd();
            Array.from(unsafeWindow.document.querySelectorAll('#content_left .c-container')).forEach(function(ele) {
                if (ele.querySelector('.icon-unsafe-icon')) ele.remove();
                if (!ele.createShadowRoot) {
                    console.info('RemoveAds (shadowRoot): ', removedAds.push(ele), '\n', ele, '\n', ele.parentNode, '\n', ele.innerText);
                    var html = ele.outerHTML;
                    var node = unsafeWindow.document.createElement('div');
                    ele.before(node);
                    node.outerHTML = html;
                    ele.remove();
                }
            });
        }, 1000);
        else setInterval(function() { removeAd(); }, 1000);
    });
})();