-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.js
30 lines (27 loc) · 959 Bytes
/
options.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
'use strict';
document.querySelectorAll('input[type=checkbox]').forEach(function(checkbox) {
const option = checkbox.parentNode.parentNode.id;
chrome.storage.sync.get([option], function(result) {
const checked = result[option];
checkbox.checked = checked;
if (checked) {
checkbox.parentNode.parentNode.classList.toggle('checked');
}
});
checkbox.onclick = function() {
const option = this.parentNode.parentNode.id;
const checked = this.checked;
let kv = {};
kv[option] = checked;
chrome.storage.sync.set(kv);
this.parentNode.firstElementChild.classList.remove('invisible');
this.parentNode.parentNode.classList.toggle('checked');
}
});
document.querySelectorAll('.why').forEach(function(why) {
why.onclick = function() {
const option = this.parentNode.id;
const explanation = document.querySelector('#' + option + '-explanation');
explanation.classList.toggle('invisible');
}
});