forked from omrihar/mathflowy
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathoptions.js
52 lines (49 loc) · 1.79 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
/* Adapted from https://developer.chrome.com/extensions/optionsV2 */
var checkbox_options = ['inline-(', 'inline-$', 'display-[', 'display-$$',
'inline-custom', 'display-custom'];
var text_options = ['inline-custom-left', 'inline-custom-right', 'display-custom-left', 'display-custom-right'];
var storage = chrome.storage.local;
if (chrome.storage.sync) {
storage = chrome.storage.sync;
}
function save_options() {
prefs = {}
for (var i = checkbox_options.length - 1; i >= 0; i--) {
prefs[checkbox_options[i]] = document.getElementById(checkbox_options[i]).checked;
}
for (var i = text_options.length - 1; i >= 0; i--) {
prefs[text_options[i]] = document.getElementById(text_options[i]).value;
}
storage.set(prefs, function() {
// Update status to let user know options were saved.
var message = document.getElementById('message');
message.textContent = 'Options saved. Reload Workflowy tabs for changes to take effect.';
setTimeout(function() {
status.textContent = '';
}, 4000);
});
}
function restore_options() {
storage.get({
"inline-(": true,
"inline-$": true,
"display-[": true,
"display-$$": true,
"inline-custom": false,
"display-custom": false,
"inline-custom-left": "",
"inline-custom-right": "",
"display-custom-left": "",
"display-custom-right": ""
}, function(prefs) {
for (var i = checkbox_options.length - 1; i >= 0; i--) {
document.getElementById(checkbox_options[i]).checked = prefs[checkbox_options[i]];
}
for (var i = text_options.length - 1; i >= 0; i--) {
document.getElementById(text_options[i]).value = prefs[text_options[i]];
}
});
}
document.addEventListener('DOMContentLoaded', restore_options);
document.getElementById('save').addEventListener('click',
save_options);