// ==UserScript== // @name 超星 - 考试与作业解除粘贴限制,允许拉伸输入框 // @description 合并类似脚本并极大幅改进,使用多种方法解除粘贴限制,允许拉伸输入框的同时,支持设置输入框默认高度。 // @namespace UnKnown // @author UnKnown // @icon https://imgsrc.baidu.com/forum/pic/item/6a63f6246b600c33c3d714d61c4c510fd9f9a106.jpg // @version 1.0 // @match *://*.chaoxing.com/work/doHomeWorkNew // @match *://*.chaoxing.com/exam/test/reVersionTestStartNew // @grant none // @run-at document-start // @downloadURL none // ==/UserScript== "use strict"; // 自定义输入框默认高度 // false / null / undefined / 0 /空字符串 "" 表示不自定义 // 非零数字表示像素,别设成负数 // 字符串表示 CSS 长度,例如 10rem,详搜 “CSS 长度单位” const customHeight = 0; // 解除粘贴限制 Object.defineProperties( unsafeWindow, { // 将 allowPaste 设死为 0 以允许粘贴 // 注意,在神秘莫测的超星前端眼中,0 表示允许粘贴,1 表示禁止粘贴 "allowPaste": { configurable: false, enumerable: true, writable: false, value: 0 }, // 将 umyEditor_paste 设死为 null,干掉阻止粘贴的函数 "myEditor_paste": { configurable: false, enumerable: true, writable: false, value: null } } ); // 允许拉伸输入框 document.addEventListener( "DOMContentLoaded", () => { document.head.appendChild( document.createElement("style") ).textContent = ".edui-default .edui-editor-iframeholder { resize: vertical; }"; }, { once: true } ); ( onload => document.readyState !== "complete" ? window.addEventListener( "load", onload, { once: true } ) : onload() )( () => setTimeout( () => { // 解除粘贴限制 备用方案 if ( /* 超星在这里用了 == */ unsafeWindow.allowPaste == 1 && unsafeWindow.myEditor_paste instanceof Function && unsafeWindow.UE instanceof Object ) { const UE = unsafeWindow.UE; // 清除 beforepaste // UEditor 咋把 instances 叫成 instants… if ( Array.isArray(UE.instants) ) { UE.instants.forEach( instance => instance.removeListener("beforepaste", myEditor_paste) ); } else if ( UE.getEditor instanceof Function ) { document.querySelectorAll('textarea[id]').forEach( textarea => UE.getEditor(textarea.id).removeListener("beforepaste", myEditor_paste) ); } } // 设置输入框默认高度 const height = (() => { if (customHeight) { switch ( Object.prototype.toString.call(customHeight).slice(8, -1) ) { case "Number": return customHeight + "px"; case "String": return customHeight; default: return false; } } })(); height && document.querySelectorAll(".edui-editor-iframeholder").forEach( iframeholder => iframeholder.style.height = height ); }, 500 ) );