-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
42 lines (36 loc) · 1.21 KB
/
config.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
async function saveFields(event) {
event.preventDefault();
let formData = new FormData(event.target);
for (let entry of formData.entries()) {
browser.storage.sync.set({[entry[0]]: entry[1]});
}
}
async function loadFields() {
for (let field of ["pat", "repo", "org"]) {
let result = browser.storage.sync.get(field);
result.then((res) => {
document.querySelector(`input[name=${field}]`).value = res[field] || '';
});
}
}
async function saveRepo(event) {
await saveFields(event);
}
async function savePat(event) {
await saveFields(event);
hidePat(event);
}
function hidePat() {
document.getElementById("pat").style.display = "none";
document.getElementById("show-pat").style.display = "block";
}
function showPat() {
document.getElementById("pat").style.display = "block";
document.getElementById("show-pat").style.display = "none";
}
window.addEventListener("load", async function() {
await loadFields();
document.getElementById("pat").addEventListener("submit", savePat);
document.getElementById("repo").addEventListener("submit", saveRepo);
document.getElementById("show-pat").addEventListener("click", showPat);
});