-
Notifications
You must be signed in to change notification settings - Fork 3
/
options.js
64 lines (56 loc) · 1.38 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* @file ccc/options.js
* @license MIT
* @version 1
*/
'use strict';
// --------------------------------------------------
let _getRulesToTextarea = function(textarea) {
return browser.runtime.sendMessage({
topic: 'ccc_get_rules'
}).then(function(json) {
let parsed = JSON.parse(json);
textarea.value = JSON.stringify(parsed, null, ' ');
});
};
let _setRulesFromTextarea = function(textarea) {
return browser.runtime.sendMessage({
topic: 'ccc_set_rules',
data: textarea.value
});
};
// --------------------------------------------------
let txtJSON = document.getElementById('txtJSON');
let btnSave = document.getElementById('btnSave');
btnSave.addEventListener('click', function(event) {
_setRulesFromTextarea(txtJSON);
}, {
capture: false,
once: false,
passive: true
});
let btnReload = document.getElementById('btnReload');
btnReload.addEventListener('click', function(event) {
browser.runtime.sendMessage({
topic: 'ccc_read_storage'
}).then(function() {
return _getRulesToTextarea(txtJSON);
});
}, {
capture: false,
once: false,
passive: true
});
let btnReset = document.getElementById('btnReset');
btnReset.addEventListener('click', function(event) {
browser.runtime.sendMessage({
topic: 'ccc_clear_storage'
}).then(function() {
return _getRulesToTextarea(txtJSON);
});
}, {
capture: false,
once: false,
passive: true
});
_getRulesToTextarea(txtJSON);