// ==UserScript== // @name 阻止阻止复制 // @namespace https://lab.wsl.moe/ // @version 0.3 // @description 干烂剪切板接口,这样就不能阻止我复制了 // @author MisakaMikoto // @match http://*/* // @match https://*/* // @run-at document-start // @grant none // @downloadURL 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; } } if (document && document.onselectstart) { if (!userSelected) { userSelected = true; userAllowed = confirm('该网站希望在全局页面上添加复制监听器,是否允许?'); } if (!userAllowed) { console.warn('Permission denied to control clipboard.'); document.onselectstart = null; return; } } if (document && document.body && document.body.onselectstart) { if (!userSelected) { userSelected = true; userAllowed = confirm('该网站希望在全局页面上添加选择文本监听器,是否允许?'); } if (!userAllowed) { console.warn('Permission denied to control clipboard.'); document.body.onselectstart = undefined; return; } } if (document && document.onkeydown && document.onkeydown.toString().indexOf('var handledFunctionFingerprint=1;handledFunctionFingerprint=0;') === -1) { const originalCallbackFunction = document.onkeydown; document.onkeydown = (event) => { var handledFunctionFingerprint=1;handledFunctionFingerprint=0; if(event && event.code === 'F12') { return; } originalCallbackFunction(event); }; } if (document && document.body && document.body.onkeydown && document.body.onkeydown.toString().indexOf('var handledFunctionFingerprint=1;handledFunctionFingerprint=0;') === -1) { const originalCallbackFunction = document.body.onkeydown; document.onkeydown = (event) => { var handledFunctionFingerprint=1;handledFunctionFingerprint=0; if(event && event.code === 'F12') { return; } originalCallbackFunction(event); }; } 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); })();