-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathoptions.js
30 lines (25 loc) · 1.02 KB
/
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
!function (global) {
var theme = document.getElementById('theme');
var exceptions = document.getElementById('exceptions');
var darken = document.getElementById('darken');
theme.value = global.localStorage.getItem('theme');
exceptions.value = global.localStorage.getItem('exceptions');
darken.checked = global.localStorage.getItem('darken') === 'true';
function bindToLocalStorage(key, cb, attribute) {
return function (e) {
var value = e.target[attribute || 'value'];
global.localStorage.setItem(key, value);
if (cb) cb(value);
};
}
function setStyles(theme) {
document.documentElement.classList[
(theme === 'light' ? 'add' : 'remove')]('dark-theme-everywhere-off');
}
theme.addEventListener('change', bindToLocalStorage('theme', setStyles));
exceptions.addEventListener('change', bindToLocalStorage('exceptions'));
exceptions.addEventListener('keyup', bindToLocalStorage('exceptions'));
darken.addEventListener(
'change', bindToLocalStorage('darken', undefined, 'checked'));
setStyles(theme.value);
}(this);