Skip to content

Commit 2769a24

Browse files
authored
🐛 修复两个@require 没分号导致的错误 #917 (#921)
1 parent 05a7e7e commit 2769a24

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/app/service/content/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ export function compileScriptCode(scriptRes: ScriptRunResource, scriptCode?: str
4141

4242
export function compileScriptCodeByResource(resource: CompileScriptCodeResource): string {
4343
const sourceURL = `//# sourceURL=${chrome.runtime.getURL(`/${encodeURI(resource.name)}.user.js`)}`;
44-
const requireCode = resource.require.map((r) => r.content).join("\n");
45-
const preCode = [requireCode].join("\n"); // 不需要 async 封装
44+
const requireCode = resource.require.map((r) => r.content).join("\n;");
45+
const preCode = requireCode; // 不需要 async 封装
4646
const code = [resource.code, sourceURL].join("\n"); // 需要 async 封装, 可top-level await
4747
// context 和 name 以unnamed arguments方式导入。避免代码能直接以变量名存取
4848
// this = context: globalThis
4949
// arguments = [named: Object, scriptName: string]
50-
// 使用sandboxContext时,arguments[0]为undefined, this.$则为一次性Proxy变量,用於全域拦截context
50+
// 使用sandboxContext时,arguments[0]为undefined, this.$则为一次性Proxy变量,用于全域拦截context
5151
// 非沙盒环境时,先读取 arguments[0],因此不会读取页面环境的 this.$
52-
// 在UserScripts API中,由於执行不是在物件导向裡呼叫,使用arrow function的话会把this改变。须使用 .call(this) [ 或 .bind(this)() ]
52+
// 在UserScripts API中,由于执行不是在物件导向里呼叫,使用arrow function的话会把this改变。须使用 .call(this) [ 或 .bind(this)() ]
5353
return `try {
5454
with(arguments[0]||this.$){
5555
${preCode}

0 commit comments

Comments
 (0)