// ==UserScript== // @name 解除网页复制和右键菜单限制 // @namespace http://tampermonkey.net/ // @version 1.0.0 // @description 解除网页对复制文本和右键菜单的限制 // @author MERCURY // @match *://*/* // @grant none // ==/UserScript== (function() { 'use strict'; // 解除复制限制 document.addEventListener('copy', function(e) { e.stopImmediatePropagation(); }, true); document.addEventListener('cut', function(e) { e.stopImmediatePropagation(); }, true); // 解除右键菜单限制 document.addEventListener('contextmenu', function(e) { e.stopImmediatePropagation(); }, true); // 移除阻止选择文本的样式 function removeSelectionStyles() { document.querySelectorAll('*').forEach(element => { element.style.userSelect = 'text !important'; element.style.webkitUserSelect = 'text !important'; element.style.MozUserSelect = 'text !important'; element.style.msUserSelect = 'text !important'; element.style.webkitTouchCallout = 'default !important'; }); } // 移除阻止拖拽的属性 function removeDragPrevention() { document.querySelectorAll('img, a').forEach(element => { element.draggable = true; element.onmousedown = null; element.ondragstart = null; }); } // 执行移除限制的函数 removeSelectionStyles(); removeDragPrevention(); // 监听DOM变化,对新添加的元素也应用这些修改 const observer = new MutationObserver(function(mutations) { removeSelectionStyles(); removeDragPrevention(); }); observer.observe(document, { childList: true, subtree: true }); // 覆盖常见的防复制函数 const disableSelectStart = function(e) { e.stopImmediatePropagation(); return true; }; document.addEventListener('selectstart', disableSelectStart, true); document.addEventListener('dragstart', disableSelectStart, true); document.addEventListener('mousedown', disableSelectStart, true); // 覆盖常见的防复制变量和函数 window.oncontextmenu = null; window.onkeydown = null; window.onkeyup = null; window.onmousedown = null; window.onmouseup = null; document.oncontextmenu = null; document.onkeydown = null; document.onkeyup = null; document.onmousedown = null; document.onmouseup = null; // 尝试覆盖常见的防复制脚本变量 const overwriteVariables = [ 'disableCopy', 'disableRightClick', 'ondragstart', 'onselectstart', 'oncontextmenu', 'onkeydown', 'onkeyup', 'onmousedown', 'onmouseup' ]; overwriteVariables.forEach(varName => { try { window[varName] = null; document[varName] = null; } catch (e) {} }); console.log('复制和右键限制已解除'); })();