Multi Tab Visibility

allowing to open many tabs without browser's knowing

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name             Multi Tab Visibility
// @namespace        violentmonkey/tampermonkey script 
// @version          3.0
// @description      allowing to open many tabs without browser's knowing 
// @author           Ojo Ngono
// @include          *://*/*
// @icon             https://i.ibb.co.com/XJSPdz0/large.png
// @exclude          /^(https?:\/\/)([^\/]+\.)?((cloudflare|github|aliyun|reddit|bing|yahoo|microsoft|whatsapp|amazon|ebay|payoneer|paypal|skrill|stripe|stripecdn|tipalti|wise|discord|tokopedia|taobao|taboola|aliexpress|netflix|citigroup|spotify|bankofamerica|hsbc|blogger|(accounts|studio).youtube|atlassian|pinterest|twitter|x|live|linkedin|fastbull|tradingview|deepseek|chatgpt|openai|grok|bilibili|indodax|bmcdn6|fbsbx|googlesyndication|amazon-adsystem|pubmatic|gstatic).com|(greasyfork|openuserjs|telegram|wikipedia|lichess).org|(doubleclick|yahoo).net|proton.me|stripe.network|meta.ai|codepen.io|(shopee|lazada|rakuten|maybank|binance).*|(dana|ovo|bca.co|bri.co|bni.co|bankmandiri.co|desa|(.*).go).id|(.*).(edu|gov))(\/.*)/
// @exclude          /^https?:\/\/(?!(www\.google\.com\/(recaptcha\/|url)|docs\.google\.com\/|drive\.google\.com\/)).*google\..*/
// @exclude          /^https?:\/\/([a-z0-9]+\.)*(facebook|instagram|tiktok)\.com\/(?!(flx\/warn\/|linkshim\/|link\/v2)).*/
// @grant            none
// @license          Copyright OjoNgono
// ==/UserScript==


 (() => {
    'use strict';

    // =========================
    // Visibility
    // =========================

    Object.defineProperty(document, 'hidden', {
        configurable: true,
        get: () => false
    });

    Object.defineProperty(document, 'visibilityState', {
        configurable: true,
        get: () => 'visible'
    });

    document.hasFocus = () => true;

    // =========================
    // Block visibility listeners
    // =========================

    const blockedEvents = new Set([
        'visibilitychange',
        'webkitvisibilitychange',
        'mozvisibilitychange',
        'msvisibilitychange'
    ]);

    const originalAddEventListener =
        EventTarget.prototype.addEventListener;

    EventTarget.prototype.addEventListener =
        function(type, listener, options) {

        if (blockedEvents.has(type)) {

            const wrapped = function(e) {

                Object.defineProperty(document, 'hidden', {
                    configurable: true,
                    get: () => false
                });

                Object.defineProperty(document, 'visibilityState', {
                    configurable: true,
                    get: () => 'visible'
                });

                return listener.call(this, e);
            };

            return originalAddEventListener.call(
                this,
                type,
                wrapped,
                options
            );
        }

        return originalAddEventListener.call(
            this,
            type,
            listener,
            options
        );
    };

    // =========================
    // IntersectionObserver
    // =========================

    if (window.IntersectionObserver) {

        const OriginalIO = window.IntersectionObserver;

        window.IntersectionObserver =
            class extends OriginalIO {

            constructor(callback, options) {

                super((entries, observer) => {

                    entries.forEach(entry => {

                        try {

                            Object.defineProperty(
                                entry,
                                'isIntersecting',
                                {
                                    configurable: true,
                                    get: () => true
                                }
                            );

                            Object.defineProperty(
                                entry,
                                'intersectionRatio',
                                {
                                    configurable: true,
                                    get: () => 1
                                }
                            );

                        } catch(e) {}

                    });

                    callback(entries, observer);

                }, options);
            }
        };
    }

    // =========================
    // elementFromPoint fallback
    // =========================

    const originalElementFromPoint =
        document.elementFromPoint.bind(document);

    document.elementFromPoint = function(x, y) {

        const el = originalElementFromPoint(x, y);

        if (el) return el;

        return document.body;
    };

    // =========================
    // userActivation
    // =========================

    if (navigator.userActivation) {

        try {

            Object.defineProperty(
                navigator.userActivation,
                'isActive',
                {
                    configurable: true,
                    get: () => true
                }
            );

            Object.defineProperty(
                navigator.userActivation,
                'hasBeenActive',
                {
                    configurable: true,
                    get: () => true
                }
            );

        } catch(e) {}
    }

    // =========================
    // Neutralize blur
    // =========================

    window.onblur = null;
    document.onvisibilitychange = null;

    // =========================
    // Keep alive
    // =========================

    setInterval(() => {

        window.dispatchEvent(new Event('focus'));

        document.dispatchEvent(
            new Event('visibilitychange')
        );

    }, 15000);

})();