Greasy Fork

Greasy Fork is available in English.

阻止阻止复制

干烂剪切板接口,这样就不能阻止我复制了

当前为 2021-06-15 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         阻止阻止复制
// @namespace    https://lab.wsl.moe/
// @version      0.2
// @description  干烂剪切板接口,这样就不能阻止我复制了
// @author       MisakaMikoto
// @match        http://*/*
// @match        https://*/*
// @run-at       document-start
// @grant        none
// ==/UserScript==

(function() {

    const realExecCommand = document.execCommand;
    const realAddEventListener = Element.prototype.addEventListener;

    let userSelected = false;
    let userAllowed = false;

    const setExecuteCommand = () => {
        window.Clipboard = undefined;
        try {
            navigator.clipboard.writeText = undefined;
        } catch (e) {}
        if (document && document.oncopy) {
            if (!userSelected) {
                userSelected = true;
                userAllowed = confirm('该网站希望在全局页面上添加复制监听器,是否允许?');
            }
            if (!userAllowed) {
                console.warn('Permission denied to control clipboard.');
                document.oncopy = null;
                return;
            }
        }
        if (document && document.body && document.body.oncopy) {
            if (!userSelected) {
                userSelected = true;
                userAllowed = confirm('该网站希望在全局页面上添加复制监听器,是否允许?');
            }
            if (!userAllowed) {
                console.warn('Permission denied to control clipboard.');
                document.body.oncopy = undefined;
                return;
            }
        }
        Document.prototype.execCommand = (cmd) => {
            switch (cmd) {
                case "copy":
                case "cut":
                case "paste":
                    if (!userSelected) {
                        userSelected = true;
                        userAllowed = confirm('该网站希望请求一次修改剪贴板的权限,是否允许?');
                    }
                    if (!userAllowed) {
                        console.warn('Permission denied to control clipboard.');
                        return;
                    }
                    break;
            }
            realExecCommand(cmd);
        };
        Element.prototype.realAddEventListener = realAddEventListener;
        Element.prototype.addEventListener = function(t, p) {
            //const functionCode = p.toString();
            switch (t) {
                case "copy":
                case "cut":
                case "paste":
                    if (!userSelected) {
                        userSelected = true;
                        userAllowed = confirm('该网站希望在某个元素上添加复制事件监听器,是否允许?');
                    }
                    if (!userAllowed) {
                        console.warn('Permission denied to control clipboard.');
                        return;
                    }
                    break;
            }
            return this.realAddEventListener(t, p);
        }
    };
    setExecuteCommand();
    const intervalId = setInterval(setExecuteCommand, 1000);
})();