Greasy Fork

Repubblica: Hide the "UsingAdBlock" alert

This script hides the alert "UsingAdBlock" that is shown when you use an ad-block.

目前为 2024-04-07 提交的版本。查看 最新版本

// ==UserScript==
// @name           Repubblica: Hide the "UsingAdBlock" alert
// @name:it        Repubblica: Nasconde l'avviso "UsingAdBlock"
// @description    This script hides the alert "UsingAdBlock" that is shown when you use an ad-block.
// @description:it Questo script nasconde l'alert "UsingAdBlock" che viene visualizzato quando si usa un ad-block.
// @match          https://*.repubblica.it/*
// @grant          none
//// @run-at         document-start
// @version        1.0.5
// @author         Cyrano68
// @license        MIT
// @namespace https://greasyfork.org/users/788550
// ==/UserScript==

(function()
{
    "use strict";

    function console_log(text)
    {
        //let now = new Date().toISOString();
        let now = new Date().toLocaleString();
        console.log(`${now} ${text}`);
    }

    console_log("==> Repubblica_HideUsingAdBlockAlert: HELLO! Loading script...");

    document.addEventListener("DOMContentLoaded", onDOMContentLoaded);
    window.addEventListener("load", onWindowLoaded);

    createMutationObserver();

    function onDOMContentLoaded()
    {
        console_log(`==> Repubblica_HideUsingAdBlockAlert: onDOMContentLoaded - document.readyState=${document.readyState}`);
        // DO NOTHING!
    }

    function onWindowLoaded()
    {
        console_log(`==> Repubblica_HideUsingAdBlockAlert: onWindowLoaded - document.readyState=${document.readyState}`);
        // DO NOTHING!
    }

    function onMutationList(mutationList, observer)
    {
        //console_log(`==> Repubblica_HideUsingAdBlockAlert: onMutationList - mutationList.length=${mutationList.length}`);
        mutationList.forEach((mutation, i) =>
        {
            //console_log(`==> Repubblica_HideUsingAdBlockAlert: onMutationList - i=${i}: mutation.type=${mutation.type}`);
            if (mutation.type === "childList")
            {
                let addedNodes = mutation.addedNodes;
                if (addedNodes.length > 0)
                {
                    //console_log(`==> Repubblica_HideUsingAdBlockAlert: onMutationList - i=${i}: addedNodes.length=${addedNodes.length}`);
                    addedNodes.forEach((addedNode, j) =>
                    {
                        //console_log(`==> Repubblica_HideUsingAdBlockAlert: onMutationList - i=${i}: onAddedNode - j=${j}: addedNode.tagName='${addedNode.tagName}'`);
                        if (addedNode.tagName === "DIV")
                        {
                            //console_log(`==> Repubblica_HideUsingAdBlockAlert: onMutationList - i=${i}: onAddedNode - j=${j}: addedNode.tagName='${addedNode.tagName}', addedNode.className='${addedNode.className}', addedNode.outerHTML='${addedNode.outerHTML}'`);
                            if (addedNode.classList.contains("fc-dialog-container"))
                            {
                                addedNode.style.display = "none";  // Hide node.
                                document.body.style.overflowY = "scroll";  // Show vertical scrollbar.
                                console_log(`==> Repubblica_HideUsingAdBlockAlert: onMutationList - 'fc-dialog-container' - i=${i}: onAddedNode - j=${j}: addedNode.tagName='${addedNode.tagName}', addedNode.classList='${addedNode.classList}' ---> HIDDEN`);
                            }
                            /*
                            else if (addedNode.classList.contains("video-frame__wrapper"))
                            {
                                // Even if the Firefox-Settings about autoplay is "Block Audio and Video" a popup containing a video-player appears
                                // on the bottom-right of screen (it appears without audio and with stopped video, but appears). Here we hide that popup.

                                addedNode.style.display = "none";  // Hide node.
                                document.body.style.overflowY = "scroll";  // Show vertical scrollbar.
                                console_log(`==> Repubblica_HideUsingAdBlockAlert: onMutationList - 'video-frame__wrapper' - i=${i}: onAddedNode - j=${j}: addedNode.tagName='${addedNode.tagName}', addedNode.classList='${addedNode.classList}' ---> HIDDEN`);
                            }
                            */
                        }
                    });
                }
            }
        });
    }

    function createMutationObserver()
    {
        console_log("==> Repubblica_HideUsingAdBlockAlert: createMutationObserver");

        // SEE: https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
        const MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;

        // Create an observer instance linked to the callback function.
        const observer = new MutationObserver(onMutationList);

        // Options for the observer (which mutations to observe).
        const config = {subtree: true, childList: true};

        // Start observing the target node for configured mutations.
        observer.observe(document, config);
    }

    console_log("==> Repubblica_HideUsingAdBlockAlert: Script loaded");
})();