forked from 404-novel-project/novel-downloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton.ts
68 lines (64 loc) · 1.86 KB
/
button.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { createApp } from "vue";
import { GmWindow } from "../global";
import { createEl, createStyle } from "../lib/dom";
import { _GM_info } from "../lib/GM";
import { log } from "../log";
import { getRule } from "../router/download";
import { getUI, UIObject } from "../router/ui";
import { iconJump, iconSetting, iconStart0, iconStart1 } from "../setting";
import buttonHtml from "./button.html";
import buttonCss from "./button.less";
import { vm as settingVM } from "./setting";
export const style = createStyle(buttonCss, "button-div-style");
export const el = createEl('<div id="nd-button"></div>');
export const vm = createApp({
data(): {
imgStart: string;
imgSetting: string;
imgJump: string;
isSettingSeen: boolean;
uiObj: UIObject;
} {
return {
imgStart: iconStart0,
imgSetting: iconSetting,
imgJump: iconJump,
isSettingSeen: _GM_info.scriptHandler !== "Greasemonkey",
uiObj: { type: "download" },
};
},
methods: {
startButtonClick() {
if ((window as GmWindow).downloading) {
alert("正在下载中,请耐心等待……");
return;
}
const self = this;
self.imgStart = iconStart1;
async function run() {
const ruleClass = await getRule();
await ruleClass.run();
}
run()
.then(() => {
self.imgStart = iconStart0;
})
.catch((error) => log.error(error));
},
settingButtonClick() {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
settingVM.openSetting();
},
jumpButtonClick() {
this.uiObj.jumpFunction();
},
},
mounted() {
Object.assign(this.uiObj, getUI()());
if (typeof (this.uiObj as UIObject).isSettingSeen !== "undefined") {
this.isSettingSeen = this.uiObj.isSettingSeen;
}
},
template: buttonHtml,
});