Enable Copy Everywhere

Enable copy and text selection on all websites including right click

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name              Enable Copy Everywhere
// @namespace         https://greasyfork.org/en/users/1375891-wibu-elite
// @version           1.0
// @description       Enable copy and text selection on all websites including right click
// @author            Kinnena
// @match             *://*/*
// @icon              https://img.icons8.com/?size=160&id=XR4FYU3AnFyS&format=png
// @grant             none
// @license MIT
// @run-at            document-start
// ==/UserScript==

(function() {
    'use strict';

    // 1. Enable text selection via CSS
    const style = document.createElement('style');
    style.innerHTML = `
        * {
            user-select: text !important;
            -webkit-user-select: text !important;
            -ms-user-select: text !important;
        }
    `;
    document.head.appendChild(style);

    // 2. Remove event listeners that block copy
    const events = [
        'copy',
        'cut',
        'paste',
        'contextmenu',
        'selectstart',
        'mousedown',
        'mouseup',
        'keydown'
    ];

    events.forEach(event => {
        document.addEventListener(event, e => {
            e.stopPropagation();
        }, true);
    });

    // 3. Enable right click explicitly
    document.oncontextmenu = null;

    // 4. Remove inline handlers
    const all = document.querySelectorAll('*');
    all.forEach(el => {
        el.oncopy = null;
        el.oncut = null;
        el.onpaste = null;
        el.oncontextmenu = null;
        el.onselectstart = null;
        el.onmousedown = null;
    });

})();