-
Notifications
You must be signed in to change notification settings - Fork 63
/
options.js
34 lines (31 loc) · 1.53 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
31
32
33
34
function renderOptions() {
var config = getConfig();
document.querySelector('#feature-1-enable').checked = config['feature-1-enable'];
document.querySelector('#feature-2-enable').checked = config['feature-2-enable'];
document.querySelector('#feature-2-interval').value = config['feature-2-interval'];
document.querySelector('#feature-2-type').value = config['feature-2-type'];
document.querySelector('#feature-3-tab-size').value = config['feature-3-tab-size'] || '4'; // set to 4 by default
document.querySelector('#feature-4-enable').checked = config['feature-4-enable'];
renderOptionsStates();
}
function renderOptionsStates() {
document.querySelector('#feature-2-interval').disabled = !(document.querySelector('#feature-2-enable').checked);
document.querySelector('#feature-2-type').disabled = !(document.querySelector('#feature-2-enable').checked);
}
function storeConfig() {
localStorage.setItem('gm_config', JSON.stringify({
'feature-1-enable': document.querySelector('#feature-1-enable').checked,
'feature-2-enable': document.querySelector('#feature-2-enable').checked,
'feature-2-interval': document.querySelector('#feature-2-interval').value,
'feature-2-type': document.querySelector('#feature-2-type').value,
'feature-3-tab-size': document.querySelector('#feature-3-tab-size').value,
'feature-4-enable': document.querySelector('#feature-4-enable').checked,
}));
}
window.onload = function() {
renderOptions();
document.onchange = function() {
storeConfig();
renderOptionsStates();
};
}