Greasy Fork

Greasy Fork is available in English.

屏蔽芊芊经典广告被拦截后的框架

芊芊经典广告被拦截后会弹出一个框架,屏蔽这个框架

当前为 2021-11-23 提交的版本,查看 最新版本

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

(function () {
    'use strict';

    let NoBlurStyle = document.createElement("style");
    NoBlurStyle.innerHTML = "" +
        "* {\n" +
        "    -webkit-filter: blur(0px);\n" +
        "    filter: blur(0px);\n" +
        "}";
    document.head.insertBefore(NoBlurStyle, document.head.firstChild);

    doElement("body>div[class$=-wrapper]", function (wrapper) {
        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;";
            element.style = "display: none; height: 0; width: 0;";
            document.body.classList.remove(displayClassNameFirst + "-blur");
        })
    }, 5000);

    function doElement(cssString, doFunction, waitMS = 0) {
        let Element = document.querySelector(cssString);
        if (Element !== null && 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;');
        }
    }
})();