Multi Tab Visibility

allowing to open many tabs without browser's knowing

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

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

})();