-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
35 lines (27 loc) · 1.49 KB
/
scripts.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
// Handles frontend UI logic.
// Variables/UI elements
const comments_button = document.getElementById('comments-disabler');
const comments_checkbox = document.getElementById('comment-disabler-checkbox');
const comments_type = document.getElementById('comment-disabler-type');
function restoreOptions() {
chrome.storage.sync.get({'comments-enable-type' : 'none'}, function (result) {
comments_checkbox.checked = result['comments-enable-type'] == 'none' ? false : true;
comments_type.style.visibility = comments_checkbox.checked ? 'visible' : 'hidden';
});
chrome.storage.sync.get({'comments-enable-selection' : 'new'}, function (result) {
comments_type.value = result['comments-enable-selection'];
});
}
restoreOptions();
comments_button.addEventListener('click', function() {
comments_checkbox.checked = !comments_checkbox.checked;
comments_type.style.visibility = comments_checkbox.checked ? 'visible' : 'hidden';
const enable_type = comments_checkbox.checked ? comments_type.value == 'new' ? 'new' : 'all' : 'none';
chrome.storage.sync.set({'comments-enable-type': enable_type}, () => { })
chrome.storage.sync.set({'comments-enable-selection': comments_type.value}, () => { })
});
comments_type.onchange = () => {
const enable_type = comments_type.value == 'new' ? 'new' : 'all';
chrome.storage.sync.set({'comments-enable-type': enable_type}, () => { })
chrome.storage.sync.set({'comments-enable-selection': comments_type.value}, () => { })
}