阻止切屏检测

阻止各类切屏检测

目前為 2024-03-07 提交的版本,檢視 最新版本

// ==UserScript==
// @name         阻止切屏检测
// @namespace    http://tampermonkey.net/
// @version      0.1.1
// @description  阻止各类切屏检测
// @author       PRO
// @match        https://*.yuketang.cn/*
// @run-at       document-start
// @icon         http://yuketang.cn/favicon.ico
// @grant        unsafeWindow
// @license      gpl-3.0
// ==/UserScript==

// Log: Block `mouseleave` event
(function () {
    'use strict';
    const window = unsafeWindow;
    const blackList = new Set(["visibilitychange", "blur", "pagehide", "mouseleave"]);
    const isDebug = false;
    const log = console.log.bind(console, "[阻止切屏检测]");
    const debug = isDebug ? log : () => { };
    window._addEventListener = window.addEventListener;
    window.addEventListener = (...args) => {
        if (!blackList.has(args[0])) {
            debug("allow window.addEventListener", ...args);
            return window._addEventListener(...args);
        } else {
            log("block window.addEventListener", ...args);
            return undefined;
        }
    };
    document._addEventListener = document.addEventListener;
    document.addEventListener = (...args) => {
        if (!blackList.has(args[0])) {
            debug("allow document.addEventListener", ...args);
            return window._addEventListener(...args);
        } else {
            log("block document.addEventListener", ...args);
            return undefined;
        }
    };
    log("addEventListener hooked!");
    if (isDebug) { // DEBUG ONLY: find out all timers
        window._setInterval = window.setInterval;
        window.setInterval = (...args) => {
            const id = window._setInterval(...args);
            debug("calling window.setInterval", id, ...args);
            return id;
        };
        debug("setInterval hooked!");
        window._setTimeout = window.setTimeout;
        window.setTimeout = (...args) => {
            const id = window._setTimeout(...args);
            debug("calling window.setTimeout", id, ...args);
            return id;
        };
        debug("setTimeout hooked!");
    }
    Object.defineProperties(document, {
        hidden: {
            value: false
        },
        visibilityState: {
            value: "visible"
        },
        hasFocus: {
            value: () => true
        },
        onvisibilitychange: {
            get: () => undefined,
            set: () => { }
        },
        onblur: {
            get: () => undefined,
            set: () => { }
        }
    });
    log("document properties set!");
    Object.defineProperties(window, {
        onblur: {
            get: () => undefined,
            set: () => { }
        },
        onpagehide: {
            get: () => undefined,
            set: () => { }
        },
    });
    log("window properties set!");
})();