// ==UserScript== // @name 超星网课解除复制粘贴限制(自用) // @namespace http://tampermonkey.net/ // @version 2.0 // @description 解除网课复制粘贴限制(只测试超星可以,别的网站自测) // @author You // @match *://*.zhihuishu.com/* // @match *://*.chaoxing.com/* // @match *://*.edu.cn/* // @match *://*.org.cn/* // @match *://*.xueyinonline.com/* // @match *://*.hnsyu.net/* // @match *://*.qutjxjy.cn/* // @match *://*.ynny.cn/* // @match *://*.hnvist.cn/* // @match *://*.fjlecb.cn/* // @match *://*.gdhkmooc.com/* // @match *://*.cugbonline.cn/* // @match *://*.zjelib.cn/* // @match *://*.cqrspx.cn/* // @match *://*.neauce.com/* // @match *://*.zhihui-yun.com/* // @match *://*.cqie.cn/* // @match *://*.ccqmxx.com/* // @match *://*.icve.com.cn/* // @match *://*.course.icve.com.cn/* // @match *://*.courshare.cn/* // @match *://*.webtrn.cn/* // @match *://*.zjy2.icve.com.cn/* // @match *://*.zyk.icve.com.cn/* // @match *://*.icourse163.org/* // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== // @grant none // ==/UserScript== (function() { 'use strict'; const originalAddEventListener = EventTarget.prototype.addEventListener; const originalRemoveEventListener = EventTarget.prototype.removeEventListener; const eventListeners = new WeakMap(); EventTarget.prototype.addEventListener = function(type, listener, options) { if (!eventListeners.has(this)) { eventListeners.set(this, []); } eventListeners.get(this).push({ type, listener, options }); return originalAddEventListener.call(this, type, listener, options); }; EventTarget.prototype.removeEventListener = function(type, listener, options) { if (eventListeners.has(this)) { const listeners = eventListeners.get(this); const index = listeners.findIndex(l => l.type === type && l.listener === listener && (l.options === options || (l.options && options && l.options.capture === options.capture)) ); if (index !== -1) { listeners.splice(index, 1); } } return originalRemoveEventListener.call(this, type, listener, options); }; function removeAllEventListeners() { const walk = document.createTreeWalker( document.body, NodeFilter.SHOW_ELEMENT, null, false ); const root = document.body; if (eventListeners.has(root)) { const listeners = [...eventListeners.get(root)]; listeners.forEach(listener => { originalRemoveEventListener.call( root, listener.type, listener.listener, listener.options ); }); eventListeners.delete(root); } while (walk.nextNode()) { const node = walk.currentNode; if (eventListeners.has(node)) { const listeners = [...eventListeners.get(node)]; listeners.forEach(listener => { originalRemoveEventListener.call( node, listener.type, listener.listener, listener.options ); }); eventListeners.delete(node); } } } function removeGlobalEventHandlers() { document.oncopy = null; document.oncut = null; document.onpaste = null; document.onselectstart = null; document.oncontextmenu = null; document.body.oncopy = null; document.body.oncut = null; document.body.onpaste = null; document.body.onselectstart = null; document.body.oncontextmenu = null; window.oncopy = null; window.oncut = null; window.onpaste = null; window.onselectstart = null; window.oncontextmenu = null; } function removeAntiCopyCSS() { const style = document.createElement('style'); style.textContent = ` * { user-select: text !important; -webkit-user-select: text !important; -moz-user-select: text !important; -ms-user-select: text !important; pointer-events: auto !important; } [oncopy], [oncut], [onpaste], [onselectstart], [oncontextmenu] { oncopy="return true;" oncut="return true;" onpaste="return true;" onselectstart="return true;" oncontextmenu="return true;" } `; document.head.appendChild(style); } function enableInteractions() { window.addEventListener('contextmenu', function(e) { e.stopPropagation(); }, true); window.addEventListener('copy', function(e) { e.stopPropagation(); }, true); window.addEventListener('cut', function(e) { e.stopPropagation(); }, true); window.addEventListener('paste', function(e) { e.stopPropagation(); }, true); window.addEventListener('selectstart', function(e) { e.stopPropagation(); }, true); } window.addEventListener('load', function() { removeAllEventListeners(); removeGlobalEventHandlers(); removeAntiCopyCSS(); enableInteractions(); // 为方便测试,添加一个快捷键来重新执行移除操作(Ctrl+Shift+R) document.addEventListener('keydown', function(e) { if (e.ctrlKey && e.shiftKey && e.keyCode === 82) { e.preventDefault(); removeAllEventListeners(); removeGlobalEventHandlers(); removeAntiCopyCSS(); enableInteractions(); } }); }); const observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if (mutation.addedNodes && mutation.addedNodes.length > 0) { for (let i = 0; i < mutation.addedNodes.length; i++) { const node = mutation.addedNodes[i]; if (node.nodeType === 1) { if (eventListeners.has(node)) { const listeners = [...eventListeners.get(node)]; listeners.forEach(listener => { originalRemoveEventListener.call( node, listener.type, listener.listener, listener.options ); }); eventListeners.delete(node); } } } } }); }); observer.observe(document.body, { childList: true, subtree: true }); })();