This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
63 lines (56 loc) · 2.23 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
function setEnabled(){
document.getElementById('enabledText').style.display = '';
document.getElementById('disabledText').style.display = 'none';
document.getElementById('disableButtonText').style.display = '';
document.getElementById('EnableButtonText').style.display = 'none';
chrome.storage.local.set({'isEnabled': true}, null);
}
function setDisabled(){
document.getElementById('enabledText').style.display = 'none';
document.getElementById('disabledText').style.display = '';
document.getElementById('disableButtonText').style.display = 'none';
document.getElementById('EnableButtonText').style.display = '';
chrome.storage.local.set({'isEnabled': false}, null);
}
function setDefaultValue(){
return new Promise((resolve, reject) => {
chrome.storage.local.get(["isEnabled", "selection", "locals"], (conf) => {
if(typeof conf.isEnabled == 'undefined') chrome.storage.local.set({'isEnabled': true}, null);
if(typeof conf.selection == 'undefined') chrome.storage.local.set({'selection': 'hant'}, null);
if(typeof conf.locals == 'undefined') chrome.storage.local.set({'locals': 'tw'}, null);
resolve()
});
});
}
function initConfigUi(){
return new Promise((resolve, reject) => {
chrome.storage.local.get(["isEnabled", "selection", "locals"], (conf) => {
conf.isEnabled ? setEnabled() : setDisabled();
document.getElementById('selection').value = conf.selection
document.getElementById('locals').value = conf.locals
});
});
}
(async () => {
await setDefaultValue();
await initConfigUi();
} )()
document.getElementById('isEnabled').addEventListener('click', () => {
chrome.storage.local.get("isEnabled", (conf) => {
if(conf.isEnabled) {
setDisabled();
} else {
setEnabled();
}
});
});
document.getElementById('selection').addEventListener('change', () => {
chrome.storage.local.set({
'selection': document.getElementById('selection').value
}, null);
});
document.getElementById('locals').addEventListener('change', () => {
chrome.storage.local.set({
'locals': document.getElementById('locals').value
}, null);
});