From f23ccdead4429a39d8478851e0405a7e3e6a4257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=80=E4=B9=8B?= Date: Thu, 15 Dec 2022 15:48:31 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E6=B2=99?= =?UTF-8?q?=E7=9B=92=E6=A8=A1=E5=BC=8F=E6=97=A0=E6=B3=95=E4=BB=8Ewindow?= =?UTF-8?q?=E8=AF=BB=E5=8F=96GM=5Finfo=E7=9A=84=E9=97=AE=E9=A2=98=20#126?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/runtime/content/exec_script.ts | 12 ++++++++++-- src/runtime/content/utils.ts | 7 +++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/runtime/content/exec_script.ts b/src/runtime/content/exec_script.ts index 561d2090..d3744bf2 100644 --- a/src/runtime/content/exec_script.ts +++ b/src/runtime/content/exec_script.ts @@ -34,6 +34,9 @@ export default class ExecScript { proxyMessage: ProxyMessageManager; + // eslint-disable-next-line camelcase + GM_info: any; + constructor( scriptRes: ScriptRunResouce, message: MessageManager, @@ -45,6 +48,7 @@ export default class ExecScript { id: this.scriptRes.id, name: this.scriptRes.name, }); + this.GM_info = GMApi.GM_info(this.scriptRes); this.proxyMessage = new ProxyMessageManager(message); if (scriptFunc) { this.scriptFunc = scriptFunc; @@ -57,7 +61,11 @@ export default class ExecScript { this.proxyContent = window; } else { // 构建脚本GM上下文 - this.sandboxContent = createContext(scriptRes, this.proxyMessage); + this.sandboxContent = createContext( + scriptRes, + this.GM_info, + this.proxyMessage + ); this.proxyContent = proxyContext(window, this.sandboxContent); } } @@ -71,7 +79,7 @@ export default class ExecScript { this.logger.debug("script start"); return this.scriptFunc.apply(this.proxyContent, [ this.proxyContent, - GMApi.GM_info(this.scriptRes), + this.GM_info, ]); } diff --git a/src/runtime/content/utils.ts b/src/runtime/content/utils.ts index 96113056..660817de 100644 --- a/src/runtime/content/utils.ts +++ b/src/runtime/content/utils.ts @@ -56,6 +56,7 @@ function setDepend(context: { [key: string]: any }, apiVal: ApiValue) { // 构建沙盒上下文 export function createContext( scriptRes: ScriptRunResouce, + GMInfo: any, message: MessageManager ): GMApi { // 按照GMApi构建 @@ -70,7 +71,8 @@ export function createContext( connect: GMApi.prototype.connect, runFlag: uuidv4(), valueUpdate: GMApi.prototype.valueUpdate, - GM: {}, + GM: { Info: GMInfo }, + GM_info: GMInfo, }; if (scriptRes.metadata.grant) { scriptRes.metadata.grant.forEach((val) => { @@ -193,9 +195,6 @@ export function proxyContext(global: any, context: any) { return undefined; }, has(_, name) { - if (name === "GM_info") { - return false; - } return true; }, set(_, name: string, val) {