Greasy Fork

Repubblica: Hide the "ExitIntent" overlay

This script hides the "ExitIntent" overlay that sometimes is shown when you want to exit from the current page of the site.

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

// ==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/*
// @require        https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js
// @grant          none
//// @run-at         document-start
// @version        1.0.4
// @author         Cyrano68
// @license        MIT
// @namespace https://greasyfork.org/users/788550
// ==/UserScript==

(function()
{
    "use strict";

    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)
    {
        // We can simply check the presence of the popup in the DOM tree.
        var divOverlay = $("div#adagio-overlay-try-buy:visible");
        //console.log(`==> Repubblica_HideExitIntentOverlay: onMutationList - divOverlay.length=${divOverlay.length}`);
        if (divOverlay.length > 0)
        {
            divOverlay.hide();
            divOverlay.remove();
            console.log(`==> Repubblica_HideExitIntentOverlay: onMutationList - divOverlay.length=${divOverlay.length} ---> HIDDEN/REMOVED`);
        }
    }

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