Skip to content

Commit d668452

Browse files
committed
fix: eval问题 & GM_deleteValue 调用错误
1 parent e5190e3 commit d668452

File tree

6 files changed

+53
-6
lines changed

6 files changed

+53
-6
lines changed

build/scriptcat/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 2,
33
"name": "ScriptCat",
4-
"version": "0.7.3",
4+
"version": "0.7.4",
55
"description": "脚本猫,一个用户脚本的框架,可编写脚本每天帮你自动处理事务.",
66
"background": {
77
"page": "background.html"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "scriptcat",
3-
"version": "0.7.3",
3+
"version": "0.7.4",
44
"description": "脚本猫,一个可以执行用户脚本的浏览器扩展,万物皆可脚本化,让你的浏览器可以做更多的事情!",
55
"scripts": {
66
"test": "jest",

src/apps/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const ExtVersion = "0.7.3";
1+
export const ExtVersion = "0.7.4";
22

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

src/apps/grant/frontend.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ export class FrontendGrant implements ScriptContext {
343343

344344
@FrontendGrant.GMFunction({ depend: ['GM_setValue'] })
345345
public GM_deleteValue(name: string): void {
346-
GM_setValue(name, undefined);
346+
this.GM_setValue(name, undefined);
347347
}
348348

349349
@FrontendGrant.GMFunction()

src/pkg/sandbox/sandbox.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ for (const key in descs) {
4242
export function buildThis(global: any, context: any) {
4343
let special = Object.assign({}, writables);
4444
// 后台脚本要不要考虑不能使用eval?
45-
let _this: any = {};
45+
let _this: any = { eval: global.eval };
4646
let proxy: any = new Proxy(context, {
4747
defineProperty(_, name, desc) {
4848
return Object.defineProperty(context, name, desc);
@@ -113,6 +113,5 @@ export function buildThis(global: any, context: any) {
113113
return ret;
114114
}
115115
});
116-
_this.eval = global.eval.bind(proxy);
117116
return proxy;
118117
}

tests/sandbox.user.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// ==UserScript==
2+
// @name 油猴兼容测试
3+
// @namespace http://tampermonkey.net/
4+
// @version 0.1
5+
// @description try to take over the world!
6+
// @author You
7+
// @match https://bbs.tampermonkey.net.cn/
8+
// @icon https://www.google.com/s2/favicons?domain=tampermonkey.net.cn
9+
// @resource icon https://bbs.tampermonkey.net.cn/favicon.ico
10+
// @resource html https://bbs.tampermonkey.net.cn/
11+
// @resource xml https://bbs.tampermonkey.net.cn/sitemap.xml
12+
// @grant GM_getResourceText
13+
// @grant GM_getResourceURL
14+
// ==/UserScript==
15+
16+
console.log(window.scrollX, window.scrollY);
17+
18+
console.log(addEventListener);
19+
20+
let uia = (function () {
21+
console.log('123');
22+
return {
23+
tip: () => {
24+
console.log('aqwe');
25+
}
26+
}
27+
})()
28+
29+
uia.tip();
30+
31+
function evalTest() {
32+
console.log('okk');
33+
}
34+
35+
setTimeout(() => {
36+
console.log('okk2', window.scrollX, window.scrollY);
37+
window.scrollY = 633;
38+
console.log('okk2', window.scrollX, window.scrollY);
39+
}, 1000)
40+
41+
let f = eval('()=>{evalTest()}');
42+
f();
43+
console.log(this);
44+
eval('console.log(this)');
45+
46+
window.onload = () => {
47+
console.log('onload');
48+
}

0 commit comments

Comments
 (0)