Skip to content

Commit 02d1a45

Browse files
committed
🐛 修复GM_xhr unsafeHeader 发送错误、popup支持运行
1 parent fe96990 commit 02d1a45

File tree

21 files changed

+377
-42
lines changed

21 files changed

+377
-42
lines changed

example/cloudcat.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// ==UserScript==
2+
// @name cloudscript
3+
// @namespace https://bbs.tampermonkey.net.cn/
4+
// @version 0.1.0
5+
// @description 可以导出成nodejs可执行的包,在云端执行
6+
// @author You
7+
// @crontab * * once * *
8+
// @cloudCat
9+
// @exportCookie domain=.scriptscat.org
10+
// ==/UserScript==
11+
12+
return new Promise((resolve, reject) => {
13+
// Your code here...
14+
resolve();
15+
});
16+

pkg/cloudscript/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# 脚本上云
2+
3+

pkg/cloudscript/factory.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export interface CloudScriptParams {
2+
[key: string]: {
3+
title: string;
4+
type?: "select";
5+
options?: string[];
6+
};
7+
}
8+
9+
export default class CloudScriptFactory {
10+
static create() {}
11+
12+
static params(): { [key: string]: CloudScriptParams } {
13+
return {
14+
local: {},
15+
};
16+
}
17+
}

pkg/filesystem/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# 文件系统
2+
3+
用于同步和备份至云端
4+
5+
- zip
6+
- webdav

src/app/message/internal.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@ export default class MessageInternal
2020

2121
onDisconnect?: () => void;
2222

23+
tag: TargetTag;
24+
2325
constructor(tag: TargetTag) {
2426
super();
25-
this.reconnect(tag);
27+
this.tag = tag;
28+
this.reconnect();
2629
}
2730

28-
reconnect(tag: TargetTag) {
31+
reconnect() {
2932
this.port = chrome.runtime.connect({
30-
name: tag,
33+
name: this.tag,
3134
});
3235
this.channelManager = new WarpChannelManager((data) => {
3336
this.nativeSend(data);

src/app/migrate.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
import { db } from "./repo/dao";
33
import { Script } from "./repo/scripts";
44

5-
// 重命名字段,统一使用小峰驼
5+
// 0.10.0重构,重命名字段,统一使用小峰驼
66
function renameField(): void {
77
db.version(16)
88
.stores({
99
scripts:
1010
"++id,&uuid,name,namespace,author,originDomain,subscribeUrl,type,sort,status," +
1111
"runStatus,createtime,updatetime,checktime",
1212
logger: "++id,level,createtime",
13+
export: "++id,&scriptId",
1314
})
1415
.upgrade(async (tx) => {
1516
await tx
@@ -18,15 +19,12 @@ function renameField(): void {
1819
.modify((script: { [key: string]: any }) => {
1920
if (script.origin_domain) {
2021
script.originDomain = script.origin_domain;
21-
delete script.origin_domain;
2222
}
2323
if (script.checkupdate_url) {
2424
script.checkUpdateUrl = script.checkupdate_url;
25-
delete script.checkupdate_url;
2625
}
2726
if (script.download_url) {
2827
script.downloadUrl = script.download_url;
29-
delete script.download_url;
3028
}
3129
});
3230
});

src/app/repo/export.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { DAO, db } from "./dao";
2+
3+
export type ExportTarget = "local" | "tencentCloud" | "";
4+
5+
// 导出与本地脚本关联记录
6+
export interface Export {
7+
id: number;
8+
scriptId: number;
9+
params?: {
10+
[key: string]: {
11+
[key: string]: any;
12+
};
13+
};
14+
// 导出目标
15+
target: ExportTarget;
16+
}
17+
18+
export class ExportDAO extends DAO<Export> {
19+
public tableName = "export";
20+
21+
constructor() {
22+
super();
23+
this.table = db.table(this.tableName);
24+
}
25+
}

src/app/service/script/manager.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,13 @@ export class ScriptManager extends Manager {
212212
}
213213
} catch (e) {
214214
logger.error("prepare script failed", Logger.E(e));
215-
return;
216215
}
216+
} else {
217+
Cache.getInstance().set(CacheKey.scriptInfo(info.uuid), info);
218+
chrome.tabs.create({
219+
url: `src/install.html?uuid=${info.uuid}`,
220+
});
217221
}
218-
Cache.getInstance().set(CacheKey.scriptInfo(info.uuid), info);
219-
chrome.tabs.create({
220-
url: `src/install.html?uuid=${info.uuid}`,
221-
});
222222
})
223223
.catch((e) => {
224224
logger.error("fetch script info failed", Logger.E(e));

src/app/service/system/manager.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import IoC from "@App/app/ioc";
33
import { MessageHander } from "@App/app/message/message";
44
import { ScriptDAO } from "@App/app/repo/scripts";
55
import { SystemConfig } from "@App/pkg/config/config";
6+
import semver from "semver";
67
import Manager from "../manager";
78

89
// value管理器,负责value等更新获取等操作
@@ -47,13 +48,24 @@ export class SystemManager extends Manager {
4748
if (details.reason === "install") {
4849
chrome.tabs.create({ url: "https://docs.scriptcat.org/" });
4950
} else if (details.reason === "update") {
50-
chrome.tabs.create({
51-
url: "https://docs.scriptcat.org/docs/change/",
52-
});
51+
const version = semver.parse(ExtVersion);
52+
if (version && version.prerelease) {
53+
chrome.tabs.create({
54+
url: "https://docs.scriptcat.org/docs/change/",
55+
});
56+
} else {
57+
chrome.tabs.create({
58+
url: "https://docs.scriptcat.org/docs/change/pre-release",
59+
});
60+
}
5361
}
5462
});
5563
}
56-
// 处理
64+
// 处理pingpong
65+
this.message.setHandler("ping", () => {
66+
return Promise.resolve("pong");
67+
});
68+
// 处理外部网站调用
5769
this.message.setHandler(
5870
ExternalMessage,
5971
async (
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import { Script } from "@App/app/repo/scripts";
2+
import {
3+
Button,
4+
Checkbox,
5+
Form,
6+
Input,
7+
Modal,
8+
Select,
9+
} from "@arco-design/web-react";
10+
import FormItem from "@arco-design/web-react/es/Form/form-item";
11+
import { IconQuestionCircleFill } from "@arco-design/web-react/icon";
12+
import CloudScriptFactory from "@Pkg/cloudscript/factory";
13+
import React, { useEffect } from "react";
14+
15+
const cloudScriptParams = CloudScriptFactory.params();
16+
17+
const CloudScriptList = [
18+
{
19+
key: "local",
20+
name: "本地",
21+
},
22+
];
23+
24+
const CloudScript: React.FC<{
25+
// eslint-disable-next-line react/require-default-props
26+
script?: Script;
27+
onClose: () => void;
28+
}> = ({ script, onClose }) => {
29+
const [visible, setVisible] = React.useState(false);
30+
const [cloudScriptType, setCloudScriptType] = React.useState("local");
31+
32+
useEffect(() => {
33+
if (script) {
34+
setVisible(true);
35+
}
36+
}, [script]);
37+
return (
38+
<Modal
39+
title={
40+
<div>
41+
<span
42+
style={{
43+
height: "32px",
44+
lineHeight: "32px",
45+
}}
46+
>
47+
{script?.name} 上传至云
48+
</span>
49+
<Button
50+
type="text"
51+
icon={
52+
<IconQuestionCircleFill
53+
style={{
54+
margin: 0,
55+
}}
56+
/>
57+
}
58+
href="https://docs.scriptcat.org/docs/dev/cloudcat/"
59+
target="_blank"
60+
iconOnly
61+
/>
62+
</div>
63+
}
64+
visible={visible}
65+
onCancel={() => {
66+
setVisible(false);
67+
onClose();
68+
}}
69+
>
70+
<Form
71+
autoComplete="off"
72+
style={{
73+
width: "100%",
74+
}}
75+
layout="vertical"
76+
>
77+
<FormItem label="上传至">
78+
<Select
79+
value={cloudScriptType}
80+
onChange={(value) => {
81+
setCloudScriptType(value);
82+
}}
83+
>
84+
{CloudScriptList.map((item) => (
85+
<Select.Option key={item.key} value={item.key}>
86+
{item.name}
87+
</Select.Option>
88+
))}
89+
</Select>
90+
</FormItem>
91+
{Object.keys(cloudScriptParams[cloudScriptType]).map((key) => {
92+
const item = cloudScriptParams[cloudScriptType][key];
93+
return (
94+
<FormItem key={key} label={item.title}>
95+
<Input />
96+
</FormItem>
97+
);
98+
})}
99+
<FormItem label="值导出表达式">
100+
<Input.TextArea />
101+
</FormItem>
102+
<FormItem label="">
103+
<Checkbox>导入时覆盖原值</Checkbox>
104+
</FormItem>
105+
<FormItem label="cookie导出表达式">
106+
<Input.TextArea />
107+
</FormItem>
108+
<FormItem label="">
109+
<Checkbox>导入时覆盖原值</Checkbox>
110+
</FormItem>
111+
<Button type="primary">恢复默认值</Button>
112+
</Form>
113+
</Modal>
114+
);
115+
};
116+
117+
export default CloudScript;

0 commit comments

Comments
 (0)