Greasy Fork

来自缓存

Greasy Fork is available in English.

解除复制限制

解除网页复制限制,启用右键菜单

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         解除复制限制
// @name:zh-CN   解除复制限制
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  解除网页复制限制,启用右键菜单
// @description:zh-CN  解除网页复制限制,启用右键菜单
// @author       焦灼
// @license      MIT
// @match        *://*/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // 移除页面的复制限制
    function removeCopyRestrictions() {
        // 启用右键菜单
        document.addEventListener('contextmenu', function(e) {
            e.stopPropagation();
            return true;
        }, true);

        // 启用选择
        document.addEventListener('selectstart', function(e) {
            e.stopPropagation();
            return true;
        }, true);

        // 启用复制
        document.addEventListener('copy', function(e) {
            e.stopPropagation();
            return true;
        }, true);

        // 移除禁止复制的 CSS
        const style = document.createElement('style');
        style.innerHTML = `
            * {
                -webkit-user-select: text !important;
                -moz-user-select: text !important;
                -ms-user-select: text !important;
                user-select: text !important;
            }
        `;
        document.head.appendChild(style);

        // 移除元素的鼠标事件和复制限制
        function removeEventListeners(element) {
            if (!element) return;
            
            // 移除 oncontextmenu 属性
            element.oncontextmenu = null;
            
            // 移除 onselectstart 属性
            element.onselectstart = null;
            
            // 移除 oncopy 属性
            element.oncopy = null;
            
            // 移除 oncut 属性
            element.oncut = null;
            
            // 移除 onpaste 属性
            element.onpaste = null;
            
            // 移除 ondrag 属性
            element.ondrag = null;
            
            // 移除 ondragstart 属性
            element.ondragstart = null;
        }

        // 处理所有元素
        function processElements() {
            removeEventListeners(document);
            removeEventListeners(document.body);
            
            const elements = document.getElementsByTagName('*');
            for (let element of elements) {
                removeEventListeners(element);
            }
        }

        // 初始处理
        processElements();

        // 监听 DOM 变化
        const observer = new MutationObserver(() => {
            processElements();
        });

        // 开始监听
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    }

    // 在页面加载开始时执行
    removeCopyRestrictions();
})();