// ==UserScript== // @name 学习通绕过解锁粘贴限制 // @namespace https://scriptcat.org/zh-CN/script-show-page/4835 // @version 1.1.0 // @description 解锁粘贴限制 // @author Muyue -imuyue.com // @match *://*.chaoxing.com/* // @match *://mooc1-*.chaoxing.com/* // @connect sso.chaoxing.com // @grant none // @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 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"); } else { 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); log('Code inserted via bypass'); }); showNotice("已绕过粘贴限制 By.Muyue -imuyue.com"); } }); editor._isUnlocked = true; } } }, 1000); } window.addEventListener('load', () => { initUEditorLogic(); initCodeEditorLogic(); }); })();