Multi Tab Visibility

allowing to open many tabs without browser's knowing

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

Advertisement:

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

Advertisement:

// ==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);

})();