Force Copy/Paste Everywhere

Re-enable copy, paste, cut, text selection, and right-click on restrictive websites.

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

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

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

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

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

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

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

Advertisement:

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

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

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

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

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

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

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

Advertisement:

// ==UserScript==
// @name         Force Copy/Paste Everywhere
// @namespace    https://greasyfork.org/en/users/1573616-marito
// @version      1.0
// @description  Re-enable copy, paste, cut, text selection, and right-click on restrictive websites.
// @match        *://*/*
// @run-at       document-start
// @grant        none
// @license      Unlicense
// ==/UserScript==

(function () {
    'use strict';

    const stop = (e) => {
        e.stopImmediatePropagation();
    };

    [
        'copy',
        'cut',
        'paste',
        'contextmenu',
        'selectstart',
        'mousedown',
        'mouseup',
        'dragstart',
        'keydown',
        'keyup'
    ].forEach(event => {
        window.addEventListener(event, stop, true);
        document.addEventListener(event, stop, true);
    });

    const unlock = () => {
        document.querySelectorAll('*').forEach(el => {
            el.oncopy = null;
            el.oncut = null;
            el.onpaste = null;
            el.oncontextmenu = null;
            el.onselectstart = null;
            el.onmousedown = null;
            el.onmouseup = null;

            el.removeAttribute('oncopy');
            el.removeAttribute('oncut');
            el.removeAttribute('onpaste');
            el.removeAttribute('oncontextmenu');
            el.removeAttribute('onselectstart');

            el.style.userSelect = 'text';
            el.style.webkitUserSelect = 'text';
            el.style.MozUserSelect = 'text';
            el.style.msUserSelect = 'text';
        });
    };

    document.addEventListener('DOMContentLoaded', unlock);
    window.addEventListener('load', unlock);

    const observer = new MutationObserver(unlock);
    observer.observe(document.documentElement, {
        childList: true,
        subtree: true
    });
})();