Skip to content

Commit ec3d072

Browse files
Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 6640899 commit ec3d072

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/preload.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -945,9 +945,13 @@ async function injectUserscriptWhenReady() {
945945
setupTurnstileCallbackBridge();
946946
setupHexMd5Polyfill();
947947

948-
// 在页面上下文执行 userscript。
949-
const runner = new Function(payload.scriptText);
950-
runner();
948+
// 在页面上下文执行 userscript:通过注入 <script> 元素到页面世界。
949+
const scriptEl = document.createElement("script");
950+
// 为了便于调试,可以给脚本一个可识别的 sourceURL(不会影响安全性)。
951+
scriptEl.textContent = String(payload.scriptText) + "\n//# sourceURL=elxmoj-userscript.js";
952+
(document.documentElement || document.head || document.body).appendChild(scriptEl);
953+
// 插入后即可移除标签;代码已经在页面上下文执行。
954+
scriptEl.parentNode.removeChild(scriptEl);
951955

952956
window.__ELXMOJ_INJECTION_STATUS__ = {
953957
ok: true,

0 commit comments

Comments
 (0)