网页限制解除器

深度解除网页复制内容限制 智能恢复右键菜单/文本选择/剪贴板操作/拖拽功能

Verze ze dne 06. 04. 2025. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         网页限制解除器
// @description  深度解除网页复制内容限制 智能恢复右键菜单/文本选择/剪贴板操作/拖拽功能
// @version      1.0.1
// @author       念柚
// @namespace    https://github.com/MiPoNianYou/UserScripts
// @license      GPL-3.0
// @match        *://*/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

class CopyRestrictionRemover {
    constructor() {
        this.InitializeObserver();
        this.ExecuteCoreFeatures();
    }

    ExecuteCoreFeatures() {
        this.RemoveEventListeners(document);
        this.RemoveEventListeners(document.body);
        this.InjectLiberationStyles();
        this.BindGlobalEventHandlers();
        this.ProcessExistingElements();
    }

    BindGlobalEventHandlers() {
        const EventConfigurations = [
            ['contextmenu', this.HandleContextMenu],
            ['selectstart', this.HandleSelection],
            ['copy', this.HandleClipboard],
            ['cut', this.HandleClipboard],
            ['paste', this.HandleClipboard]
        ];

        EventConfigurations.forEach(([eventType, handler]) => {
            document.addEventListener(eventType, handler.bind(this), true);
        });
    }

    HandleContextMenu(event) {
        event.stopPropagation();
        return true;
    }

    HandleSelection(event) {
        event.stopPropagation();
        return true;
    }

    HandleClipboard(event) {
        event.stopPropagation();
        return true;
    }

    InjectLiberationStyles() {
        const StyleDeclaration = `
            * {
                -webkit-user-select: text !important;
                -moz-user-select: text !important;
                -ms-user-select: text !important;
                user-select: text !important;
                -webkit-user-drag: auto !important;
                -moz-user-drag: auto !important;
                user-drag: auto !important;
            }
        `;

        const StyleElement = document.createElement('style');
        StyleElement.textContent = StyleDeclaration;
        document.head.appendChild(StyleElement);
    }

    ProcessExistingElements() {
        document.querySelectorAll('*').forEach(element => {
            this.RemoveEventListeners(element);
        });
    }

    RemoveEventListeners(element) {
        if (!element) return;

        const RestrictedProperties = [
            'oncontextmenu', 'onselectstart',
            'oncopy', 'oncut', 'onpaste',
            'ondrag', 'ondragstart'
        ];

        RestrictedProperties.forEach(property => {
            element[property] = null;
        });
    }

    InitializedMutationHandler(mutationsList) {
        for (const mutation of mutationsList) {
            if (mutation.type === 'childList') {
                mutation.addedNodes.forEach(node => {
                    if (node.nodeType === Node.ELEMENT_NODE) {
                        this.RemoveEventListeners(node);
                        node.querySelectorAll('*').forEach(child => {
                            this.RemoveEventListeners(child);
                        });
                    }
                });
            }
        }
    }

    InitializeObserver() {
        this.DomObserver = new MutationObserver(this.InitializedMutationHandler.bind(this));
        this.DomObserver.observe(document.documentElement, {
            childList: true,
            subtree: true,
            attributes: false,
            characterData: false
        });
    }
}

new CopyRestrictionRemover();