-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
54 lines (45 loc) · 1.67 KB
/
popup.js
File metadata and controls
54 lines (45 loc) · 1.67 KB
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
document.addEventListener('DOMContentLoaded', async () => {
const urlInput = document.getElementById('urlInput');
const exclusionInput = document.getElementById('exclusionInput');
const autoCloseCheckbox = document.getElementById('autoCloseCheckbox');
const startBtn = document.getElementById('startBtn');
// 1. 加载上次保存的配置
const data = await chrome.storage.local.get(['lastUrl', 'savedExclusions', 'autoCloseSource']);
if (data.lastUrl) urlInput.value = data.lastUrl;
if (data.savedExclusions) exclusionInput.value = data.savedExclusions;
// 恢复自动关闭选项的状态 (默认为 true)
if (data.autoCloseSource !== undefined) {
autoCloseCheckbox.checked = data.autoCloseSource;
} else {
autoCloseCheckbox.checked = true;
}
// 2. 绑定点击事件
startBtn.addEventListener('click', () => {
const url = urlInput.value.trim();
const exclusionText = exclusionInput.value.trim();
const autoClose = autoCloseCheckbox.checked;
if (!url) {
alert("请输入有效的 URL");
return;
}
// 将排除文本转换为数组,过滤空行
const exclusions = exclusionText.split('\n')
.map(line => line.trim())
.filter(line => line.length > 0);
// 保存当前配置,方便下次使用
chrome.storage.local.set({
lastUrl: url,
savedExclusions: exclusionText,
autoCloseSource: autoClose
});
// 发送消息给 background.js 开始任务
chrome.runtime.sendMessage({
action: "START_ANALYSIS",
url: url,
exclusions: exclusions,
autoClose: autoClose // 传递自动关闭参数
});
// 关闭 popup
window.close();
});
});