RemoveAds

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

Versione datata 11/01/2018. Vedi la nuova versione l'ultima versione.

// ==UserScript==
// @name            RemoveAds
// @name:en         RemoveAds
// @version         1.4.3
// @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-idle
// @grant           unsafeWindow
// @grant           none
// @namespace https://greasyfork.org/users/129402
// ==/UserScript==

(function() {
    "use strict";
    /* 防止重复加载 */
    if (unsafeWindow.RemoveAds) return;
    console.debug('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);
    }

    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.debug('RemoveAds: ', removedAds.push(that), '\n', that, '\n', that.parentNode, '\n', that.innerText);
                that.remove();
            }
        });
        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.debug('RemoveAds: ', removedAds.push(that), '\n', that, '\n', that.parentNode, '\n', that.innerText);
                that.remove();
            } else that.attributes.style.textContent = style + '';
        });
    };
    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.debug('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 removeAd();
})();