Greasy Fork is available in English.

Repubblica: Nasconde l'overlay "ExitIntent"

Questo script nasconde l'overlay "ExitIntent" che a volte viene visualizzato quando si vuole uscire dalla pagina corrente del sito.

// ==UserScript==
// @name           Repubblica: Hide the "ExitIntent" overlay
// @name:it        Repubblica: Nasconde l'overlay "ExitIntent"
// @description    This script hides the "ExitIntent" overlay that sometimes is shown when you want to exit from the current page of the site.
// @description:it Questo script nasconde l'overlay "ExitIntent" che a volte viene visualizzato quando si vuole uscire dalla pagina corrente del sito.
// @match          https://*.repubblica.it/*
// @grant          none
//// @run-at         document-start
// @version        1.0.6
// @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_HideExitIntentOverlay: HELLO! Loading script...");

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

    createMutationObserver();

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

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

    function onMutationList(mutationList, observer)
    {
        //console_log(`==> Repubblica_HideExitIntentOverlay: onMutationList - mutationList.length=${mutationList.length}`);
        mutationList.forEach((mutation, i) =>
        {
            //console_log(`==> Repubblica_HideExitIntentOverlay: onMutationList - i=${i}: mutation.type=${mutation.type}`);
            if (mutation.type === "childList")
            {
                let addedNodes = mutation.addedNodes;
                if (addedNodes.length > 0)
                {
                    //console_log(`==> Repubblica_HideExitIntentOverlay: onMutationList - i=${i}: addedNodes.length=${addedNodes.length}`);
                    addedNodes.forEach((addedNode, j) =>
                    {
                        //console_log(`==> Repubblica_HideExitIntentOverlay: onMutationList - i=${i}: onAddedNode - j=${j}: addedNode.tagName='${addedNode.tagName}'`);
                        if (addedNode.tagName === "DIV")
                        {
                            //console_log(`==> Repubblica_HideExitIntentOverlay: onMutationList - i=${i}: onAddedNode - j=${j}: addedNode.tagName='${addedNode.tagName}', addedNode.className='${addedNode.className}', addedNode.outerHTML='${addedNode.outerHTML}'`);
                            if (addedNode.id === "adagio-overlay-try-buy")
                            {
                                addedNode.style.display = "none";  // Hide node.
                                document.body.style.overflowY = "scroll";  // Show vertical scrollbar.
                                console_log(`==> Repubblica_HideExitIntentOverlay: onMutationList - 'adagio-overlay-try-buy' - i=${i}: onAddedNode - j=${j}: addedNode.tagName='${addedNode.tagName}', addedNode.id='${addedNode.id}' ---> HIDDEN`);
                            }
                        }
                    });
                }
            }
        });
    }

    function createMutationObserver()
    {
        console_log("==> Repubblica_HideExitIntentOverlay: 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_HideExitIntentOverlay: Script loaded");
})();