Bypass Fullscreen e Focus

Inganna il controllo dello schermo intero e del focus

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

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

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

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

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

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

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

Advertisement:

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

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

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

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

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

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

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

Advertisement:

// ==UserScript==
// @name         Bypass Fullscreen e Focus
// @namespace    http://tampermonkey.net/
// @version      2.1
// @description  Inganna il controllo dello schermo intero e del focus
// @match        *://*/*
// @run-at       document-start
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // --- 1. BYPASS VISIBILITA' E FOCUS ---
    Object.defineProperty(document, 'visibilityState', { get: () => 'visible' });
    Object.defineProperty(document, 'hidden', { get: () => false });

    const blockFocusEvents = (e) => {
        e.stopImmediatePropagation();
        e.preventDefault();
    };

    window.addEventListener('visibilitychange', blockFocusEvents, true);
    document.addEventListener('visibilitychange', blockFocusEvents, true);
    window.addEventListener('blur', blockFocusEvents, true);
    document.addEventListener('blur', blockFocusEvents, true);


    // --- 2. BYPASS SCHERMO INTERO ---
    // Creiamo un finto elemento da restituire quando il sito chiede se siamo in Fullscreen
    const mockFullscreenElement = document.documentElement;

    const fullscreenProps = [
        'fullscreenElement',
        'webkitFullscreenElement',
        'mozFullScreenElement',
        'msFullscreenElement'
    ];

    // Sovrascriviamo le proprietà in modo che non restituiscano mai "null"
    fullscreenProps.forEach(prop => {
        Object.defineProperty(document, prop, {
            get: () => mockFullscreenElement,
            configurable: true
        });
    });

    // Blocchiamo gli eventi di cambio schermo intero
    const blockFullscreenEvents = (e) => {
        e.stopImmediatePropagation();
        // Nota: non usiamo preventDefault() qui perché l'azione di base (uscire) è forzata dal browser
    };

    const fullscreenEvents = [
        'fullscreenchange',
        'webkitfullscreenchange',
        'mozfullscreenchange',
        'MSFullscreenChange'
    ];

    fullscreenEvents.forEach(evt => {
        document.addEventListener(evt, blockFullscreenEvents, true);
        window.addEventListener(evt, blockFullscreenEvents, true);
    });

})();