Universal Bypass

Bypass common web restrictions: right-click, copy-paste, text selection, drag/drop, scrolling, video controls, console, debugger, and more.

目前為 2024-10-04 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Universal Bypass
// @namespace    https://github.com/x3ric
// @version      1.2
// @description  Bypass common web restrictions: right-click, copy-paste, text selection, drag/drop, scrolling, video controls, console, debugger, and more.
// @author       x3ric
// @license      MIT
// @match        *://*/*
// @run-at       document-start
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_registerMenuCommand
// @grant        GM_notification
// @grant        GM_unregisterMenuCommand
// @grant        unsafeWindow
// ==/UserScript==

(function() {
    'use strict';
    const settings = GM_getValue('universalBypassSettings', {
        rightClick: true,
        copyPaste: true,
        textSelection: true,
        consoleBypass: true,
        debuggerBypass: true
    });
    const saveSettings = () => GM_setValue('universalBypassSettings', settings);
    const applyBypasses = () => {
        if (settings.rightClick) {
            document.addEventListener('contextmenu', handleContextMenu, true);
            unsafeWindow.oncontextmenu = null;
        }
        if (settings.copyPaste) {
            ['copy', 'paste', 'cut'].forEach(ev =>
                document.addEventListener(ev, handleCopyPaste, true)
            );
        }
        if (settings.textSelection) {
            document.addEventListener('selectstart', handleTextSelection, true);
            applyTextSelectionStyle();
        }
        if (settings.consoleBypass) {
            applyConsoleBypass();
        }
        if (settings.debuggerBypass) {
            applyDebuggerBypass();
        }
        // Override common protection methods
        overrideProtectionMethods();
    };
    const handleContextMenu = (e) => {
        e.stopImmediatePropagation();
        unsafeWindow.oncontextmenu = null;
        return true;
    };
    const handleCopyPaste = (e) => {
        e.stopImmediatePropagation();
        return true;
    };
    const handleTextSelection = (e) => {
        e.stopImmediatePropagation();
        return true;
    };
    const applyTextSelectionStyle = () => {
        const style = document.createElement('style');
        style.textContent = `
            * {
                user-select: text !important;
                -webkit-user-select: text !important;
                -moz-user-select: text !important;
                -ms-user-select: text !important;
            }
            ::selection {
                background: #b3d4fc !important;
                color: #000 !important;
            }
        `;
        document.head.appendChild(style);
    };
    const applyConsoleBypass = () => {
        const noop = () => {};
        const consoleProxy = new Proxy(console, {
            get: (target, prop) => {
                if (['clear', 'debug', 'error', 'info', 'log', 'warn'].includes(prop)) {
                    return noop;
                }
                return target[prop];
            }
        });
        Object.defineProperty(unsafeWindow, 'console', {
            get: () => consoleProxy,
            set: () => {},
            configurable: false
        });
    };
    const applyDebuggerBypass = () => {
        const handler = {
            get: (target, prop) => {
                if (prop === 'toString') {
                    return () => 'function () { [native code] }';
                }
                return typeof target[prop] === 'function' ?
                    target[prop].bind(target) : target[prop];
            }
        };
        unsafeWindow.Function = new Proxy(unsafeWindow.Function, handler);
        unsafeWindow.eval = new Proxy(unsafeWindow.eval, {
            apply: (target, thisArg, args) => {
                args[0] = args[0].replace(/debugger/g, '');
                return Reflect.apply(target, thisArg, args);
            }
        });
    };
    const overrideProtectionMethods = () => {
        const overrides = {
            preventDefault: Event.prototype.preventDefault,
            stopPropagation: Event.prototype.stopPropagation,
            stopImmediatePropagation: Event.prototype.stopImmediatePropagation
        };

        Object.keys(overrides).forEach(method => {
            Event.prototype[method] = new Proxy(overrides[method], {
                apply: (target, thisArg, args) => {
                    if (!['contextmenu', 'copy', 'paste', 'cut', 'selectstart'].includes(thisArg.type)) {
                        return Reflect.apply(target, thisArg, args);
                    }
                }
            });
        });
    };
    const menuCommands = {};
    const updateMenuCommand = (key) => {
        if (menuCommands[key]) {
            GM_unregisterMenuCommand(menuCommands[key]);
        }
        menuCommands[key] = GM_registerMenuCommand(
            `${key.replace(/([A-Z])/g, ' $1').trim()} (${settings[key] ? 'ON' : 'OFF'})`,
            () => toggleSetting(key)
        );
    };

    const toggleSetting = key => {
        settings[key] = !settings[key];
        saveSettings();
        applyBypasses();
        updateMenuCommand(key);
        GM_notification({
            text: `${key.replace(/([A-Z])/g, ' $1').trim()} is now ${settings[key] ? 'ON' : 'OFF'}`,
            title: 'Universal Bypass',
            timeout: 3000
        });
    };
    Object.keys(settings).forEach(updateMenuCommand);
    // Initial application
    applyBypasses();
    // Reapply on possible DOM changes
    const observer = new MutationObserver(applyBypasses);
    observer.observe(document, { childList: true, subtree: true });
    // Reapply on navigation events
    ['load', 'popstate', 'pushstate', 'replacestate'].forEach(event =>
        window.addEventListener(event, applyBypasses, true)
    );
})();