Greasy Fork

Repubblica: Hide the "UsingAdBlock" alert

This script hides the alert "UsingAdBlock".

目前为 2024-03-23 提交的版本。查看 最新版本

// ==UserScript==
// @name           Repubblica: Hide the "UsingAdBlock" alert
// @name:it        Repubblica: Nasconde l'avviso "UsingAdBlock"
// @description    This script hides the alert "UsingAdBlock".
// @description:it Questo script nasconde l'alert "UsingAdBlock".
// @match          https://*.repubblica.it/*
// @require        https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js
// @grant          none
//// @run-at         document-start
// @version        1.0.1
// @author         Cyrano68
// @license        MIT
// @namespace https://greasyfork.org/users/788550
// ==/UserScript==

(function()
{
    "use strict";

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

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

    createMutationObserver();

    var myCounter = 0;

    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)
    {
        // We can simply check the presence of the popup in the DOM tree.
        var divContainer = $("div.fc-dialog-container:visible");
        //console.log(`==> Repubblica_HideUsingAdBlockAlert: onMutationList - divContainer.length=${divContainer.length}`);
        if (divContainer.length > 0)
        {
            divContainer.hide();
            divContainer.remove();
            $("body").css("overflow-y", "scroll"); // Show vertical scrollbar
            console.log(`==> Repubblica_HideUsingAdBlockAlert: onMutationList - divContainer.length=${divContainer.length} ---> HIDDEN/REMOVED`);
        }

        /*
        // 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 video, but appears). Here we hide that popup.
        var divWrapper = $("div.video-frame__wrapper:visible");
        //console.log(`==> Repubblica_HideUsingAdBlockAlert: onMutationList - divWrapper.length=${divWrapper.length}`);
        if (divWrapper.length > 0)
        {
            divWrapper.hide();
            divWrapper.remove();
            $("body").css("overflow-y", "scroll"); // Show vertical scrollbar
            console.log(`==> Repubblica_HideUsingAdBlockAlert: onMutationList - divWrapper.length=${divWrapper.length} ---> HIDDEN/REMOVED`);
        }
        */
    }

    function createMutationObserver()
    {
        console.log("==> Repubblica_HideUsingAdBlockAlert: createMutationObserver");

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

        var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;

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

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

    console.log("==> Repubblica_HideUsingAdBlockAlert: Script loaded");
})();