Skip to content

Commit

Permalink
🚑 紧急修复GM沙盒问题
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Oct 11, 2022
1 parent 259077b commit fbe6e05
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build/scriptcat/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "ScriptCat",
"version": "0.9.2",
"version": "0.9.3",
"description": "脚本猫,一个用户脚本的框架,可编写脚本每天帮你自动处理事务.",
"background": {
"page": "background.html"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scriptcat",
"version": "0.9.2",
"version": "0.9.3",
"description": "脚本猫,一个可以执行用户脚本的浏览器扩展,万物皆可脚本化,让你的浏览器可以做更多的事情!",
"scripts": {
"lint": "eslint --ext .js,.ts,.tsx tests/ src/",
Expand Down
2 changes: 1 addition & 1 deletion src/apps/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const ExtVersion = '0.9.2';
export const ExtVersion = '0.9.3';

export const Server = process.env.NODE_ENV == 'production' ? 'https://sc.icodef.com/' : 'http://localhost:8080/';

Expand Down
2 changes: 1 addition & 1 deletion src/injected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ browserMsg.listen('scripts', (msg) => {
return;
}
if ((<{ [key: string]: () => void }><unknown>window)[script.flag]) {
(<{ [key: string]: (context: ScriptContext) => void }><unknown>window)[script.flag].apply(context, [context]);
(<{ [key: string]: (GM_Info:any, context: ScriptContext) => void }><unknown>window)[script.flag].apply(context, [GMInfo,context]);
}
Object.defineProperty(window, script.flag, {
get: () => { return undefined; },
Expand Down
10 changes: 5 additions & 5 deletions src/pkg/sandbox/compile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FrontenApiValue, SandboxContext, ScriptContext } from '@App/apps/grant/frontend';
import { FrontenApiValue, FrontendGrant, SandboxContext, ScriptContext } from '@App/apps/grant/frontend';
import { ScriptCache, Script } from '@App/model/do/script';

// 编译脚本代码字符串
Expand All @@ -14,11 +14,11 @@ export function compileScriptCode(script: ScriptCache): string {
});
code = require + code;
return (
'with (context) return ((GM_info ,context, fapply, CDATA, uneval, define, module, exports)=>{\n' +
'with (context) return ((context, fapply, CDATA, uneval, define, module, exports)=>{\n' +
code +
'\n//# sourceURL=' +
chrome.runtime.getURL('/' + encodeURI(script.name) + '.user.js') +
'\n})(GM_info, context)'
'\n})(context)'
);
}

Expand Down Expand Up @@ -53,7 +53,7 @@ export function createSandboxContext(script: ScriptCache): SandboxContext {
return <SandboxContext>createContext(context, script);
}

export function createContext(context: ScriptContext, script: Script): ScriptContext {
export function createContext(context: ScriptContext, script: ScriptCache): ScriptContext {
context['postRequest'] = context.postRequest;
context['script'] = context.script;
if (script.metadata['grant']) {
Expand All @@ -72,7 +72,7 @@ export function createContext(context: ScriptContext, script: Script): ScriptCon
setDepend(context, apiVal);
});
}
context['GM_info'] = context.GM_info();
context['GM_info'] = FrontendGrant.GM_info(script);

// 去除原型链
return Object.assign({}, context);
Expand Down

0 comments on commit fbe6e05

Please sign in to comment.