Greasy Fork

Greasy Fork is available in English.

Universal Bypass

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

当前为 2024-10-04 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Universal Bypass
// @namespace    https://github.com/x3ric
// @version      1.1
// @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        unsafeWindow
// @grant        GM_registerMenuCommand
// ==/UserScript==

(function () {
    'use strict';
    const settings = {
        rightClick: true, copyPaste: true, textSelection: true, dragDrop: false, keyboardShortcuts: false,
        pointerEvents: false, scrolling: true, unlockInputs: false, stopAutoPlay: false, enableVideoControls: false,
        removeOverlays: false, removeNoCopy: true, allowPasteInPassword: false, consoleBypass: false, debuggerBypass: false
    };

    const saveSettings = () => localStorage.setItem('universalBypassSettings', JSON.stringify(settings));
    const loadSettings = () => { const storedSettings = localStorage.getItem('universalBypassSettings'); if (storedSettings) Object.assign(settings, JSON.parse(storedSettings)); };

    const applyBypasses = () => {
        const unblockEvents = () => {
            const eventsToUnblock = [];
            if (settings.rightClick) eventsToUnblock.push('contextmenu');
            if (settings.copyPaste) eventsToUnblock.push('copy', 'paste', 'cut');
            if (settings.textSelection) eventsToUnblock.push('selectstart');
            if (settings.dragDrop) eventsToUnblock.push('dragstart', 'drop');
            if (settings.keyboardShortcuts) eventsToUnblock.push('keydown', 'keypress', 'keyup');
            if (settings.pointerEvents) eventsToUnblock.push('pointerdown', 'pointerup', 'mousedown', 'mouseup', 'click');
            if (settings.scrolling) eventsToUnblock.push('wheel', 'touchmove', 'scroll');
            eventsToUnblock.forEach(eventType => document.addEventListener(eventType, e => e.stopPropagation(), true));
        };

        const removeBlockingAttributes = () => {
            const attrsToRemove = ['oncontextmenu', 'oncopy', 'onpaste', 'oncut', 'onselectstart', 'ondragstart', 'ondrop', 'onkeydown', 'onkeypress', 'onkeyup', 'onpointerdown', 'onpointerup', 'onclick', 'onscroll'];
            attrsToRemove.forEach(attr => document.querySelectorAll(`[${attr}]`).forEach(el => el.removeAttribute(attr)));
            if (settings.removeNoCopy) document.querySelectorAll('[class*="no-copy"], [class*="unselectable"]').forEach(el => el.classList.remove('no-copy', 'unselectable'));
            if (settings.allowPasteInPassword) document.querySelectorAll('input[type="password"]').forEach(input => input.onpaste = null);
        };

        if (settings.removeOverlays) document.querySelectorAll('.overlay, .modal, .popup, .lightbox, [role="dialog"]').forEach(el => el.style.display = 'none');
        if (settings.unlockInputs) document.querySelectorAll('input[disabled], textarea[disabled], select[disabled], input[readonly], textarea[readonly]').forEach(input => { input.disabled = false; input.readOnly = false; });
        if (settings.stopAutoPlay) document.querySelectorAll('video, audio').forEach(media => { media.autoplay = false; media.pause(); });
        if (settings.enableVideoControls) document.querySelectorAll('video').forEach(video => video.controls = true);
        if (settings.consoleBypass) console.clear = () => console.log("Console clear has been blocked.");
        if (settings.debuggerBypass) {
            const injectDebugger = `debugger;`;
            unsafeWindow.eval = new Proxy(unsafeWindow.eval, { apply: (target, thisArg, args) => { if (typeof args[0] === 'string') args[0] = `${injectDebugger} ${args[0]}`; return Reflect.apply(target, thisArg, args); } });
            unsafeWindow.Function = new Proxy(unsafeWindow.Function, { construct: (target, args) => { if (typeof args[args.length - 1] === 'string') args[args.length - 1] = `${injectDebugger} ${args[args.length - 1]}`; return Reflect.construct(target, args); } });
        }
        unblockEvents();
        removeBlockingAttributes();
    };

    const observeDOMChanges = () => { const observer = new MutationObserver(() => applyBypasses()); observer.observe(document.documentElement, { attributes: true, childList: true, subtree: true }); };

    const toggleSetting = (settingKey, settingName, menuCommandId) => {
        settings[settingKey] = !settings[settingKey];
        applyBypasses();
        saveSettings();
        GM_unregisterMenuCommand(menuCommandId);
        createMenu(settingKey, settingName);
    };

    const createMenu = (settingKey, settingName) => {
        const status = settings[settingKey] ? 'ON' : 'OFF';
        const menuCommandId = GM_registerMenuCommand(`${settingName} (${status})`, () => toggleSetting(settingKey, settingName, menuCommandId));
    };

    const init = () => {
        loadSettings();
        applyBypasses();
        observeDOMChanges();
        createMenu('rightClick', 'Right-Click');
        createMenu('copyPaste', 'Copy-Paste');
        createMenu('textSelection', 'Text Selection');
        createMenu('dragDrop', 'Drag-and-Drop');
        createMenu('keyboardShortcuts', 'Keyboard Shortcuts');
        createMenu('pointerEvents', 'Pointer Events');
        createMenu('scrolling', 'Scrolling');
        createMenu('unlockInputs', 'Unlock Inputs');
        createMenu('stopAutoPlay', 'Stop Auto-Play');
        createMenu('enableVideoControls', 'Enable Video Controls');
        createMenu('removeOverlays', 'Remove Overlays');
        createMenu('removeNoCopy', 'Remove No-Copy Classes');
        createMenu('allowPasteInPassword', 'Allow Paste in Password Fields');
        createMenu('consoleBypass', 'Console Bypass');
        createMenu('debuggerBypass', 'Debugger Bypass');
    };

    init();
})();