-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
42 lines (38 loc) · 1.25 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
document.addEventListener('DOMContentLoaded', function() {
// 获取DOM元素
const proxyEnabled = document.getElementById('proxyEnabled');
const proxyHost = document.getElementById('proxyHost');
const proxyPort = document.getElementById('proxyPort');
const saveButton = document.getElementById('saveButton');
const toast = document.getElementById('toast');
// 加载保存的设置
chrome.storage.local.get(['proxyEnabled', 'proxyHost', 'proxyPort'], function(result) {
proxyEnabled.checked = result.proxyEnabled || false;
proxyHost.value = result.proxyHost || '';
proxyPort.value = result.proxyPort || '';
});
// 显示提示框的函数
function showToast() {
toast.classList.add('show');
setTimeout(() => {
toast.classList.remove('show');
}, 2000);
}
// 保存设置
saveButton.addEventListener('click', function() {
const config = {
proxyEnabled: proxyEnabled.checked,
proxyHost: proxyHost.value,
proxyPort: proxyPort.value
};
chrome.storage.local.set(config, function() {
// 通知background.js更新代理设置
chrome.runtime.sendMessage({
type: 'updateProxy',
config: config
});
// 显示保存成功提示
showToast();
});
});
});