Greasy Fork

Greasy Fork is available in English.

网页限制解除器

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

当前为 2025-04-06 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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();