Greasy Fork

Greasy Fork is available in English.

阻止阻止复制

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

(function() {
    'use strict';

    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) {}
        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, 100);
    setTimeout(() => clearInterval(intervalId), 2000);
})();