-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
35 lines (32 loc) · 911 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
31
32
33
34
35
var options = [
'frontPageFeed',
'relatedSidebar',
'relatedEnd',
'comments',
'liveChat',
]
function saveOptions(option) {
return function () {
var obj = {}
obj[option] = document.querySelector('#' + option).checked
browser.storage.local.set(obj)
browser.runtime.sendMessage('__reloadYtCSS')
}
}
function getOptionValues() {
options.forEach(function (option) {
var gettingItem = browser.storage.local.get(option)
gettingItem.then(function (res) {
document.querySelector('#' + option).checked = res.hasOwnProperty(option)
? res[option]
// default any option to true if it is not set yet
: true
})
})
}
// set all handlers
document.addEventListener('DOMContentLoaded', getOptionValues)
options.forEach(function (option) {
var element = document.querySelector('input[id="' + option + '"]')
element.onchange = saveOptions(option)
})