Greasy Fork

Greasy Fork is available in English.

屏蔽芊芊经典广告拦截框架

芊芊经典广告被拦截后会弹出一个框架,屏蔽的框架。屏蔽简书广告

当前为 2021-12-10 提交的版本,查看 最新版本

// ==UserScript==
// @license      MIT
// @name         屏蔽芊芊经典广告拦截框架
// @namespace    http://tampermonkey.net/
// @version      0.6.3
// @description  芊芊经典广告被拦截后会弹出一个框架,屏蔽的框架。屏蔽简书广告
// @author       Tenfond
// @match        http*://myqqjd.com/*
// @match        http*://www.jianshu.com/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    let NoBlurStyle = document.createElement("style");
    NoBlurStyle.innerHTML = "" +
        "body > *:not(#wpadminbar):not(.afsuo-cagwq-modal):not(.afsuo-cagwq-wrapper):not(.afsuo-cagwq-blackout) {\n" +
        "    -webkit-filter: blur(0px);\n" +
        "    filter: blur(0px);\n" +
        "    pointer-events: auto;\n" +
        "}\n" +
        "ins.adsbygoogle,ins.adsbygoogle * {\n" +
        "    display: none;\n" +
        "    width: 0px;\n" +
        "    height: 0px;\n" +
        "    max-width: 0px;\n" +
        "    max-height: 0px;\n" +
        "}\n" +
        "aside[id^=advert],section[aria-label$=-ad] {\n" +
        "    display: none;\n" +
        "    height: 0;\n" +
        "    width: 0;\n" +
        "    max-width: 0px;\n" +
        "    max-height: 0px;\n" +
        "}\n" +
        ".search-wrap.wow.fadeInDown.animated {\n" +
        "    position: fixed;\n" +
        "    margin: auto;\n" +
        "}";
    document.head.insertBefore(NoBlurStyle, document.head.firstChild);

    // 以下代码似乎没有效果
        document.oncontextmenu = function (event) {
            // 开启右键
            event.returnValue = true;
        }

        document.onselectstart = function (event) {
            // 开启选中文字
            event.returnValue = true;
        }

        document.ondragstart = function (event) {
            // 允许拖拽图片
            event.returnValue = true;
        }

        document.oncopy = function (event) {
            // 允许复制
            event.returnValue = true;
        }

    doElement("aside[id^=advert]", function (ADaside) {
        for (let i = 0; i < ADaside.length; i++) {
            ADaside[i].style = "display: none; height: 0; width: 0;";
        }
    }, 5000);
    doElement("body>div[class$=-wrapper]", function (wrapper) {
        console.log("检测到了wapper")
        let displayClassNameFirst = wrapper.className.match(/([\w-]+)-wrapper/)[1];
        doElement("body>div." + displayClassNameFirst + "-blackout.active,body>div." + displayClassNameFirst + "-modal.active", function (element) {
            wrapper.style = "display: none; height: 0; width: 0; max-height: 0; max-width: 0;";
            element.style = "display: none; height: 0; width: 0; max-height: 0; max-width: 0;";
            document.body.classList.remove(displayClassNameFirst + "-blur");
        })
    }, 5000);

    function doElement(cssString, doFunction, waitMS = 0) {
        let Element = document.querySelector(cssString);
        if (Element && Element.nodeType === 1) {
            doFunction(Element);
            console.log("已为 " + cssString + " 进行了操作");
        } else if (document.readyState !== "complete" || waitMS > 0) {
            console.log("正在查找 " + cssString);
            setTimeout(function () {
                doElement(cssString, doFunction, document.readyState !== "complete" ? waitMS : waitMS - 310);    // TODO 10毫秒约函数执行时间
            }, 300);
        } else {
            console.log("%c未找到 " + cssString, 'color: #f00;');
        }
    }
})();