-
Notifications
You must be signed in to change notification settings - Fork 15
/
options.js
111 lines (104 loc) · 4.52 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
function save_options() {
var useComma = document.getElementById('useComma').checked;
var useMM = document.getElementById('useMM').checked;
var useRounding = document.getElementById('useRounding').checked;
var useMO = document.getElementById('useMO').checked;
var useGiga = document.getElementById('useGiga').checked;
var useSpaces = document.getElementById('useSpaces').checked;
var useKelvin = document.getElementById('useKelvin').checked;
var useBold = document.getElementById('useBold').checked;
var useBrackets = document.getElementById('useBrackets').checked;
var useMetricOnly = document.getElementById('useMetricOnly').checked;
var convertBracketed = document.getElementById('convertBracketed').checked;
var matchIn = document.getElementById('matchIn').checked;
var includeQuotes = document.getElementById('includeQuotes').checked;
var includeImproperSymbols = document.getElementById('includeImproperSymbols').checked;
chrome.storage.sync.set({
useComma: useComma,
useMM: useMM,
useRounding: useRounding,
isFirstRun: false,
useMO: useMO,
useGiga: useGiga,
useSpaces: useSpaces,
useKelvin: useKelvin,
useBold: useBold,
useBrackets: useBrackets,
useMetricOnly: useMetricOnly,
convertBracketed: convertBracketed,
matchIn: matchIn,
includeQuotes: includeQuotes,
includeImproperSymbols: includeImproperSymbols
}, function() {
// Update status to let user know options were saved.
var status = document.getElementById('status');
status.textContent = 'Saved. Refresh individual pages to see changes.';
chrome.runtime.sendMessage(
"reload settings",
function(response) {
}
);
/*setTimeout(function() {
status.textContent = '';
window.close();
}, 3000);*/
});
}
function restore_options() {
try {
chrome.storage.sync.get({
useComma: true,
useMM: false,
useRounding: true,
isFirstRun: false,
useMO: false,
useGiga: false,
useSpaces: true,
useKelvin: false,
useBold: false,
useBrackets: true,
useMetricOnly: false,
convertBracketed: true,
matchIn: false,
includeQuotes: true,
includeImproperSymbols: true
}, function(items) {
document.getElementById('useComma').checked = items.useComma;
document.getElementById('useMM').checked = items.useMM;
document.getElementById('useRounding').checked = items.useRounding;
document.getElementById('useMO').checked = items.useMO;
document.getElementById('useGiga').checked = items.useGiga;
document.getElementById('useSpaces').checked = items.useSpaces;
document.getElementById('useKelvin').checked = items.useKelvin;
document.getElementById('useBold').checked = items.useBold;
document.getElementById('useBrackets').checked = items.useBrackets;
document.getElementById('useMetricOnly').checked = items.useMetricOnly;
document.getElementById('convertBracketed').checked = items.convertBracketed;
document.getElementById('matchIn').checked = items.matchIn;
document.getElementById('includeQuotes').checked = items.includeQuotes;
document.getElementById('includeImproperSymbols').checked = items.includeImproperSymbols;
});
} catch (err) {
console.log(err.message);
}
}
restore_options();
document.addEventListener("DOMContentLoaded", restore_options);
document.getElementById('save').addEventListener('click', save_options);
document.getElementById('useComma').addEventListener('click', save_options);
document.getElementById('useMM').addEventListener('click', save_options);
document.getElementById('useRounding').addEventListener('click', save_options);
document.getElementById('useGiga').addEventListener('click', save_options);
document.getElementById('useSpaces').addEventListener('click', save_options);
document.getElementById('useKelvin').addEventListener('click', save_options);
document.getElementById('useBold').addEventListener('click', save_options);
document.getElementById('useBrackets').addEventListener('click', save_options);
document.getElementById('useMetricOnly').addEventListener('click', save_options);
document.getElementById('convertBracketed').addEventListener('click', save_options);
document.getElementById('matchIn').addEventListener('click', save_options);
document.getElementById('includeQuotes').addEventListener('click', save_options);
document.getElementById('includeImproperSymbols').addEventListener('click', save_options);
var _selector = document.querySelector('input');
_selector.addEventListener('change', function(event) {
save_options();
});