-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpopup.js
126 lines (116 loc) · 3.98 KB
/
popup.js
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
document.addEventListener("DOMContentLoaded", function () {
//给不同按钮绑定不同事件
let beginButton = document.getElementById("begin");
beginButton.onclick = () => {
chrome.tabs.getSelected(null, function (tab) {
chrome.tabs.sendRequest(
tab.id,
{ action: "begin", tabId: tab.id },
() => {}
);
});
};
let stopButton = document.getElementById("stop");
stopButton.onclick = () => {
chrome.tabs.getSelected(null, function (tab) {
// chrome.tabs.sendRequest(tab.id, { action: "exportFile" }, () => {});
chrome.tabs.sendRequest(tab.id, { action: "stop" }, () => {});
});
};
let continueButton = document.getElementById("continue");
continueButton.onclick = () => {
chrome.tabs.getSelected(null, function (tab) {
chrome.tabs.sendRequest(
tab.id,
{ action: "continue", tabId: tab.id },
() => {}
);
});
};
let reContinueButton = document.getElementById("reContinue");
reContinueButton.onclick = () => {
chrome.tabs.getSelected(null, function (tab) {
chrome.tabs.sendRequest(tab.id, { action: "reContinue" }, () => {});
});
};
let clearCommitButton = document.getElementById("clearCommit");
clearCommitButton.onclick = () => {
chrome.tabs.getSelected(null, function (tab) {
chrome.tabs.sendRequest(tab.id, { action: "clearCommit" }, () => {});
});
};
let stopMusicButton = document.getElementById("stopMusic");
stopMusicButton.onclick = () => {
chrome.tabs.getSelected(null, function (tab) {
chrome.tabs.sendRequest(tab.id, { action: "stopMusic" }, () => {});
});
};
let showOrderButton = document.getElementById("showOrder");
showOrderButton.onclick = () => {
chrome.tabs.getSelected(null, function (tab) {
chrome.tabs.sendRequest(tab.id, { action: "showOrder" }, () => {});
});
};
//导入分页数据
let importInput = document.getElementById("importFile");
importInput.onchange = (e) => {
const file = importInput.files && importInput.files[0];
var reader = new FileReader();
reader.onload = function () {
if (reader.result) {
const pagination = JSON.parse(reader.result);
//显示文件内容
//隐藏导出。因为数据会出问题。
document
.getElementById("exportFile")
.setAttribute("style", "display: none");
document
.getElementById("baseOption")
.setAttribute("style", "display: none");
//提示导入的数据
document.getElementById(
"paginationLabel"
).textContent = `已支持1~${pagination.length}页的跳转(越小越早),请在下方输入页码跳转:`;
//展示跳转功能
document
.getElementById("pagination")
.setAttribute("style", "display: block");
chrome.tabs.getSelected(null, function (tab) {
chrome.tabs.sendRequest(
tab.id,
{ action: "importPagination", data: pagination },
() => {}
);
});
}
};
reader.readAsText(file);
};
//导出分页txt文件的内容
let exportFileButton = document.getElementById("exportFile");
exportFileButton.onclick = () => {
chrome.tabs.getSelected(null, function (tab) {
chrome.tabs.sendRequest(tab.id, { action: "exportFile" }, () => {});
});
};
let jumpPaginationButton = document.getElementById("jumpPage");
jumpPaginationButton.onclick = () => {
var page = document.getElementById("paginationInput").value;
if (page) {
chrome.tabs.getSelected(null, function (tab) {
chrome.tabs.sendRequest(
tab.id,
{ action: "jumpPagination", data: page },
() => {}
);
});
}
};
chrome.runtime.onMessage.addListener(function (request, sender) {
// 触发不同的功能
if (request.action === "updateTime") {
document.getElementById("content").textContent =
"已爬取" + request.time + "次";
}
});
});