-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.js
More file actions
63 lines (53 loc) · 1.93 KB
/
Copy pathoptions.js
File metadata and controls
63 lines (53 loc) · 1.93 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
55
56
57
58
59
60
61
62
const OptionsPage = {
async init() {
document
.querySelector("#saveForm")
.addEventListener("mousedown", () => this.onSaveForm(), true);
document
.querySelector("#saveFromJson")
.addEventListener("mousedown", () => this.onSaveFromJson(), true);
document
.querySelector("#showOptionsAsJson")
.addEventListener("mousedown", () => this.onShowOptionsAsJson(), true);
this.showOptions();
},
onSaveForm() {
var obj = this._getAllOptons();
saveOptions(obj);
},
_getAllOptons() {
let urlSendTo = document.getElementById("url-send-to").value;
if (!urlSendTo || urlSendTo == "") {
alert("url should not be empty");
return false;
}
let urlGetRsaPublicKey = document.getElementById("url-get-rsa-public-key").value;
let domainsToExclude = document.getElementById("domains-to-exclude").value;
return { url: urlSendTo, publickeyUrl: urlGetRsaPublicKey, excludeDomains: domainsToExclude };
},
onSaveFromJson() {
let allOptions = document.getElementById("all-options-in-json").value;
if (!allOptions || allOptions == "") {
alert("allOptions should not be empty");
return false;
}
saveOptions(JSON.parse(allOptions));
},
onShowOptionsAsJson() {
var obj = this._getAllOptons();
document.getElementById("all-options-in-json").value = JSON.stringify(obj);
},
async showOptions() {
const savedOptions = await chrome.storage.local.get(['url', 'publickeyUrl', 'excludeDomains']);
document.getElementById('url-send-to').value = savedOptions?.url||''
document.getElementById('url-get-rsa-public-key').value = savedOptions?.publickeyUrl||''
document.getElementById('domains-to-exclude').value = savedOptions?.excludeDomains||''
},
};
document.addEventListener("DOMContentLoaded", async () => {
await OptionsPage.init();
});
//保存用户配置
function saveOptions(jsonValue) {
chrome.storage.local.set(jsonValue);
}