Skip to content

Commit 70554c7

Browse files
committed
✨ 本地/链接导入
1 parent 20eba92 commit 70554c7

6 files changed

Lines changed: 45 additions & 30 deletions

File tree

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.17.0-alpha.4",
3+
"version": "0.17.0-beta",
44
"description": "脚本猫,一个可以执行用户脚本的浏览器扩展,万物皆可脚本化,让你的浏览器可以做更多的事情!",
55
"author": "CodFrm",
66
"license": "GPLv3",

scripts/pack.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ if (version.prerelease.length) {
1717
betaVersion += parseInt(version.prerelease[1] || "0", 10) + 1 || 1;
1818
break;
1919
case "beta":
20-
// 第二位进1
21-
betaVersion += 10 * (parseInt(version.prerelease[1] || "0", 10) + 1 || 1);
20+
// 第三位进1
21+
betaVersion += 100 * (parseInt(version.prerelease[1] || "0", 10) + 1 || 1);
2222
break;
2323
default:
2424
throw new Error("未知的版本类型");

src/app/service/service_worker/client.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ export class ScriptClient extends Client {
8383
sortScript(active: string, over: string) {
8484
return this.do("sortScript", { active, over });
8585
}
86+
87+
importByUrl(url: string) {
88+
return this.do("importByUrl", url);
89+
}
8690
}
8791

8892
export class ResourceClient extends Client {

src/app/service/service_worker/script.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,10 @@ export class ScriptService {
534534
}
535535
}
536536

537+
importByUrl(url: string) {
538+
return this.openInstallPageByUrl(url, "user");
539+
}
540+
537541
init() {
538542
this.listenerScriptInstall();
539543

@@ -552,6 +556,7 @@ export class ScriptService {
552556
this.group.on("requestCheckUpdate", this.requestCheckUpdate.bind(this));
553557
this.group.on("isInstalled", this.isInstalled.bind(this));
554558
this.group.on("sortScript", this.sortScript.bind(this));
559+
this.group.on("importByUrl", this.importByUrl.bind(this));
555560

556561
// 定时检查更新, 每10分钟检查一次
557562
chrome.alarms.create("checkScriptUpdate", {

src/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 3,
33
"name": "__MSG_scriptcat__",
4-
"version": "0.17.0.1005",
4+
"version": "0.17.0.1100",
55
"author": "CodFrm",
66
"description": "__MSG_scriptcat_description__",
77
"options_ui": {

src/pages/components/layout/MainLayout.tsx

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
Input,
77
Layout,
88
Menu,
9+
Message,
910
Modal,
1011
Space,
1112
Typography,
@@ -18,6 +19,7 @@ import "./index.css";
1819
import { useAppDispatch, useAppSelector } from "@App/pages/store/hooks";
1920
import { selectThemeMode, setDarkMode } from "@App/pages/store/features/config";
2021
import { RiFileCodeLine, RiImportLine, RiPlayListAddLine, RiTerminalBoxLine, RiTimerLine } from "react-icons/ri";
22+
import { scriptClient } from "@App/pages/store/features/script";
2123

2224
const MainLayout: React.FC<{
2325
children: ReactNode;
@@ -48,7 +50,12 @@ const MainLayout: React.FC<{
4850
title={t("import_link")}
4951
visible={importVisible}
5052
onOk={async () => {
51-
setImportVisible(false);
53+
try {
54+
await scriptClient.importByUrl(importRef.current!.dom.value);
55+
setImportVisible(false);
56+
} catch (e) {
57+
Message.error(`${t("import_link_failure")}: ${e}`);
58+
}
5259
}}
5360
onCancel={() => {
5461
setImportVisible(false);
@@ -87,31 +94,30 @@ const MainLayout: React.FC<{
8794
onClick={() => {
8895
const el = document.getElementById("import-local");
8996
el!.onchange = (e: Event) => {
90-
// const scriptCtl = IoC.instance(ScriptController) as ScriptController;
91-
// try {
92-
// // 获取文件
93-
// // @ts-ignore
94-
// const file = e.target.files[0];
95-
// // 实例化 FileReader对象
96-
// const reader = new FileReader();
97-
// reader.onload = async (processEvent) => {
98-
// // 创建blob url
99-
// const blob = new Blob(
100-
// // @ts-ignore
101-
// [processEvent.target!.result],
102-
// {
103-
// type: "application/javascript",
104-
// }
105-
// );
106-
// const url = URL.createObjectURL(blob);
107-
// await scriptCtl.importByUrl(url);
108-
// Message.success(t("import_local_success"));
109-
// };
110-
// // 调用readerAsText方法读取文本
111-
// reader.readAsText(file);
112-
// } catch (error) {
113-
// Message.error(`${t("import_local_failure")}: ${e}`);
114-
// }
97+
try {
98+
// 获取文件
99+
// @ts-ignore
100+
const file = e.target.files[0];
101+
// 实例化 FileReader对象
102+
const reader = new FileReader();
103+
reader.onload = async (processEvent) => {
104+
// 创建blob url
105+
const blob = new Blob(
106+
// @ts-ignore
107+
[processEvent.target!.result],
108+
{
109+
type: "application/javascript",
110+
}
111+
);
112+
const url = URL.createObjectURL(blob);
113+
await scriptClient.importByUrl(url);
114+
Message.success(t("import_local_success"));
115+
};
116+
// 调用readerAsText方法读取文本
117+
reader.readAsText(file);
118+
} catch (error) {
119+
Message.error(`${t("import_local_failure")}: ${e}`);
120+
}
115121
};
116122
el!.click();
117123
}}

0 commit comments

Comments
 (0)