// ==UserScript== // @name 为什么不让我复制?(解除如飞书、钉钉、百度文库等的复制限制) // @namespace http://tampermonkey.net/ // @version 1.1 // @description 恢复被网站禁用的复制功能,例如飞书、钉钉、百度文库等。支持右键菜单复制,支持ctrl+c、command+c复制 // @author HuSheng // @match *://*/* // @grant none // @run-at document-start // @license GPL-2.0-only // @downloadURL https://update.greasyfork.icu/scripts/541782/%E4%B8%BA%E4%BB%80%E4%B9%88%E4%B8%8D%E8%AE%A9%E6%88%91%E5%A4%8D%E5%88%B6%EF%BC%9F%EF%BC%88%E8%A7%A3%E9%99%A4%E5%A6%82%E9%A3%9E%E4%B9%A6%E3%80%81%E9%92%89%E9%92%89%E3%80%81%E7%99%BE%E5%BA%A6%E6%96%87%E5%BA%93%E7%AD%89%E7%9A%84%E5%A4%8D%E5%88%B6%E9%99%90%E5%88%B6%EF%BC%89.user.js // @updateURL https://update.greasyfork.icu/scripts/541782/%E4%B8%BA%E4%BB%80%E4%B9%88%E4%B8%8D%E8%AE%A9%E6%88%91%E5%A4%8D%E5%88%B6%EF%BC%9F%EF%BC%88%E8%A7%A3%E9%99%A4%E5%A6%82%E9%A3%9E%E4%B9%A6%E3%80%81%E9%92%89%E9%92%89%E3%80%81%E7%99%BE%E5%BA%A6%E6%96%87%E5%BA%93%E7%AD%89%E7%9A%84%E5%A4%8D%E5%88%B6%E9%99%90%E5%88%B6%EF%BC%89.meta.js // ==/UserScript== (function() { 'use strict'; // 原始事件 const originalAddEventListener = EventTarget.prototype.addEventListener; const originalPreventDefault = Event.prototype.preventDefault; const originalStopPropagation = Event.prototype.stopPropagation; const originalStopImmediatePropagation = Event.prototype.stopImmediatePropagation; // 覆盖addEventListener EventTarget.prototype.addEventListener = function(type, listener, options) { if (type === 'copy') { return; } // 拦截Ctrl+C、Command+C if (type === 'keydown') { const listenerStr = listener.toString(); if (listenerStr.includes('keyCode:67') || listenerStr.includes('keyCode===67') || listenerStr.includes('key:"c"') || (listenerStr.includes('ctrlKey') && listenerStr.includes('67')) || (listenerStr.includes('metaKey') && listenerStr.includes('67'))) { return; } } originalAddEventListener.call(this, type, listener, options); }; // 覆盖事件方法 Event.prototype.preventDefault = function() { if (this.type === 'copy' || (this.type === 'keydown' && this.keyCode === 67 && (this.ctrlKey || this.metaKey))) { return; } originalPreventDefault.call(this); }; Event.prototype.stopPropagation = function() { if (this.type === 'copy' || (this.type === 'keydown' && this.keyCode === 67 && (this.ctrlKey || this.metaKey))) { return; } originalStopPropagation.call(this); }; Event.prototype.stopImmediatePropagation = function() { if (this.type === 'copy' || (this.type === 'keydown' && this.keyCode === 67 && (this.ctrlKey || this.metaKey))) { return; } originalStopImmediatePropagation.call(this); }; // 添加右键菜单复制支持 document.addEventListener('contextmenu', function(e) { e.stopImmediatePropagation(); }, true); })();