// ==UserScript== // @name 学习通绕过解锁粘贴限制 // @namespace https://scriptcat.org/zh-CN/script-show-page/4835 // @version 1.2.1 // @description 解锁学习通 代码编辑区、UE编辑器、讨论区 的粘贴限制 // @author Muyue // @match *://*.chaoxing.com/* // @match *://mooc1-*.chaoxing.com/* // @connect sso.chaoxing.com // @grant none // @run-at document-start // @tag 学习通 // ==/UserScript== (function() { 'use strict'; const TAG = '[Unified-Paste]'; const log = (...a) => console.log(TAG, ...a); function showNotice(msg) { if (window.$ && $.toast) { $.toast({ type: 'notice', content: msg }); } else { console.log(TAG, msg); } } function initDiscussionLogic() { const checkObj = setInterval(() => { if (window.obj) { if (window.obj.circle) { window.obj.circle.prohibitReplyPasting = 0; log('Discussion config bypassed (prohibitReplyPasting=0)'); } window.obj.isManager = 1; clearInterval(checkObj); } }, 500); setTimeout(() => clearInterval(checkObj), 10000); window.addEventListener('paste', function(e) { const target = e.target; if (target.tagName === 'TEXTAREA' || target.contentEditable === 'true') { e.stopImmediatePropagation(); } }, true); } function initUEditorLogic() { const timer = setInterval(() => { if (!window.UE || !UE.instants) return; const editor = UE.instants[Object.keys(UE.instants)[0]]; if (!editor || !editor.iframe) return; const doc = editor.iframe.contentDocument; if (!doc || !doc.body) return; clearInterval(timer); log('UEditor detected, hijacking paste...'); doc.addEventListener('paste', function (e) { const cd = e.clipboardData || window.clipboardData; if (!cd) return; let hasFile = false; let hasHtml = !!cd.getData('text/html'); if (cd.items) { for (const item of cd.items) { if (item.kind === 'file') { hasFile = true; break; } } } if (hasFile || hasHtml) { e.preventDefault(); e.stopImmediatePropagation(); const text = cd.getData('text/plain'); if (text) { editor.execCommand('insertHtml', text.replace(/&/g, '&').replace(//g, '>').replace(/\n/g, '
'), true); showNotice("已绕过粘贴限制,图片等附件请通过上方菜单以附件形式上传 By.Muyue -imuyue.com"); } } }, true); }, 1000); } function initCodeEditorLogic() { const checkCodeEditor = setInterval(() => { var codeEditors = window.codeEditors || {}; if (Object.keys(codeEditors).length === 0) return; clearInterval(checkCodeEditor); log('CodeMirror detected, unlocking paste...'); for (let editorId in codeEditors) { let editor = codeEditors[editorId]; if (editor && !editor._isUnlocked) { editor.on('beforeChange', function(cm, change) { if (change.origin === 'paste') { change.cancel(); const pastedText = (event.clipboardData || window.clipboardData).getData('text'); const cursor = cm.getCursor(); cm.operation(function() { cm.replaceRange(pastedText, cursor); }); showNotice("已绕过代码粘贴限制 By.Muyue -imuyue.com"); } }); editor._isUnlocked = true; } } }, 1000); } initDiscussionLogic(); window.addEventListener('load', () => { initUEditorLogic(); initCodeEditorLogic(); }); })();