Skip to content

Commit

Permalink
fix: eval问题 & GM_deleteValue 调用错误
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Nov 24, 2021
1 parent e5190e3 commit d668452
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 6 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.7.3",
"version": "0.7.4",
"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.7.3",
"version": "0.7.4",
"description": "脚本猫,一个可以执行用户脚本的浏览器扩展,万物皆可脚本化,让你的浏览器可以做更多的事情!",
"scripts": {
"test": "jest",
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.7.3";
export const ExtVersion = "0.7.4";

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

Expand Down
2 changes: 1 addition & 1 deletion src/apps/grant/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ export class FrontendGrant implements ScriptContext {

@FrontendGrant.GMFunction({ depend: ['GM_setValue'] })
public GM_deleteValue(name: string): void {
GM_setValue(name, undefined);
this.GM_setValue(name, undefined);
}

@FrontendGrant.GMFunction()
Expand Down
3 changes: 1 addition & 2 deletions src/pkg/sandbox/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ for (const key in descs) {
export function buildThis(global: any, context: any) {
let special = Object.assign({}, writables);
// 后台脚本要不要考虑不能使用eval?
let _this: any = {};
let _this: any = { eval: global.eval };
let proxy: any = new Proxy(context, {
defineProperty(_, name, desc) {
return Object.defineProperty(context, name, desc);
Expand Down Expand Up @@ -113,6 +113,5 @@ export function buildThis(global: any, context: any) {
return ret;
}
});
_this.eval = global.eval.bind(proxy);
return proxy;
}
48 changes: 48 additions & 0 deletions tests/sandbox.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// ==UserScript==
// @name 油猴兼容测试
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://bbs.tampermonkey.net.cn/
// @icon https://www.google.com/s2/favicons?domain=tampermonkey.net.cn
// @resource icon https://bbs.tampermonkey.net.cn/favicon.ico
// @resource html https://bbs.tampermonkey.net.cn/
// @resource xml https://bbs.tampermonkey.net.cn/sitemap.xml
// @grant GM_getResourceText
// @grant GM_getResourceURL
// ==/UserScript==

console.log(window.scrollX, window.scrollY);

console.log(addEventListener);

let uia = (function () {
console.log('123');
return {
tip: () => {
console.log('aqwe');
}
}
})()

uia.tip();

function evalTest() {
console.log('okk');
}

setTimeout(() => {
console.log('okk2', window.scrollX, window.scrollY);
window.scrollY = 633;
console.log('okk2', window.scrollX, window.scrollY);
}, 1000)

let f = eval('()=>{evalTest()}');
f();
console.log(this);
eval('console.log(this)');

window.onload = () => {
console.log('onload');
}

0 comments on commit d668452

Please sign in to comment.