We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
环境描述
系统:Windows 10 浏览器:Chrome 122.0.6261.95(正式版本) (64 位) OCS版本:4.8.8 页面链接:https://mooc1.chaoxing.com/mycourse/studentstudy*
BUG 描述
当该页面无需进行输入时或无复制粘贴限制时,日志输出报错:[错误]:[通用 - 页面复制粘贴限制解除] : Cannot read properties of null (reading 'append')
[错误]:[通用 - 页面复制粘贴限制解除] : Cannot read properties of null (reading 'append')
重现方法
预期行为
Cannot read properties of null (reading 'append') --> 已解除输入框无法复制粘贴限制
Cannot read properties of null (reading 'append')
已解除输入框无法复制粘贴限制
屏幕截图
解决方案
添加对对象的存在性的检查,确保在访问属性或方法之前进行验证;添加错误处理,以捕获可能出现的错误并输出到控制台,从而避免导致代码崩溃。
检查 null 或 undefined 的情况,在访问对象的属性或方法之前,始终检查对象是否为 null 或 undefined。
null
undefined
创建 enableCopyIfNeeded 函数,该函数会检查目标元素是否存在,并且只有在元素存在时才会执行复制粘贴解除操作。在 onactive 和 oncomplete 事件处理程序中,进行函数调用,确保在需要时启用复制粘贴功能,避免因为尝试在不存在的元素上执行操作而导致的报错,并且避免了重复执行相同的操作。
enableCopyIfNeeded
file path: ./packages/scripts/src/projects/common.ts
./packages/scripts/src/projects/common.ts
render: RenderScript, hack: new Script({ name: '页面复制粘贴限制解除', url: [['所有页面', /.*/]], hideInPanel: true, onactive() { enableCopyIfNeeded(); }, oncomplete() { enableCopyIfNeeded(); } }); function enableCopyIfNeeded() { const targetElements = [document, document.body]; targetElements.forEach(element => { if (element) { enableCopy(element); insertCopyableStyle(); } }); }
user.js
copyHack: new Script({ name: "\u5C4F\u853D\u590D\u5236\u7C98\u8D34\u9650\u5236", hideInPanel: true, url: [["\u6240\u6709\u9875\u9762", /.*/]], methods() { return { hackEditorPaste() { try { const instants = ($gm.unsafeWindow && $gm.unsafeWindow.UE && $gm.unsafeWindow.UE.instants) || []; for (const key in instants) { const ue = instants[key]; if (ue && ue.textarea) { ue.body.addEventListener("click", async () => { if (CXProject && CXProject.scripts.study && CXProject.scripts.study.cfg.showTextareaWhenEdit) { const defaultText = el("span", { innerHTML: ue.textarea.value }).textContent; $modal("prompt", { content: "\u8BF7\u5728\u6B64\u6587\u672C\u6846\u8FDB\u884C\u7F16\u8F91\uFF0C\u9632\u6B62\u8D85\u661F\u65E0\u6CD5\u590D\u5236\u7C98\u8D34\u3002(\u5982\u9700\u5173\u95ED\u8BF7\u524D\u5F80\u8BBE\u7F6E: \u8BFE\u7A0B\u5B66\u4E60-\u7F16\u8F91\u65F6\u663E\u793A\u81EA\u5B9A\u4E49\u7F16\u8F91\u6846)", width: 800, inputDefaultValue: defaultText || "", modalInputType: "textarea", onConfirm: (val = "") => { ue.setContent( val.split("\n").map((line) => `<p>${line}</p>`).join("") ); } }); } }); if ($gm.unsafeWindow.editorPaste) { ue.removeListener("beforepaste", $gm.unsafeWindow.editorPaste); } if ($gm.unsafeWindow.myEditor_paste) { ue.removeListener("beforepaste", $gm.unsafeWindow.myEditor_paste); } } } } catch (error) { console.error("An error occurred while hacking editor paste:", error); } } }; }, oncomplete() { const hackInterval = setInterval(() => { if ($gm.unsafeWindow && $gm.unsafeWindow.UE) { clearInterval(hackInterval); this.methods.hackEditorPaste(); console.log("\u5DF2\u89E3\u9664\u8F93\u5165\u6846\u65E0\u6CD5\u590D\u5236\u7C98\u8D34\u9650\u5236"); } }, 500); } })
Note: Code Generated By ChatGPT
The text was updated successfully, but these errors were encountered:
enncy
No branches or pull requests
环境描述
系统:Windows 10
浏览器:Chrome 122.0.6261.95(正式版本) (64 位)
OCS版本:4.8.8
页面链接:https://mooc1.chaoxing.com/mycourse/studentstudy*
BUG 描述
当该页面无需进行输入时或无复制粘贴限制时,日志输出报错:
[错误]:[通用 - 页面复制粘贴限制解除] : Cannot read properties of null (reading 'append')
重现方法
预期行为
Cannot read properties of null (reading 'append')
-->已解除输入框无法复制粘贴限制
屏幕截图
解决方案
添加对对象的存在性的检查,确保在访问属性或方法之前进行验证;添加错误处理,以捕获可能出现的错误并输出到控制台,从而避免导致代码崩溃。
检查
null
或undefined
的情况,在访问对象的属性或方法之前,始终检查对象是否为null
或undefined
。创建
enableCopyIfNeeded
函数,该函数会检查目标元素是否存在,并且只有在元素存在时才会执行复制粘贴解除操作。在 onactive 和 oncomplete 事件处理程序中,进行函数调用,确保在需要时启用复制粘贴功能,避免因为尝试在不存在的元素上执行操作而导致的报错,并且避免了重复执行相同的操作。file path:
./packages/scripts/src/projects/common.ts
user.js
Note: Code Generated By ChatGPT
The text was updated successfully, but these errors were encountered: