-
Notifications
You must be signed in to change notification settings - Fork 2
/
options.js
51 lines (48 loc) · 1.87 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
// Saves options to chrome.storage
function save_options() {
var syntaxHighlight = document.getElementById('syntaxHighlight').checked;
var lineNumbers = document.getElementById('lineNumbers').checked;
var wrapLines = document.getElementById('wrapLines').checked;
var matchTag = document.getElementById('matchTag').checked;
var matchBracket = document.getElementById('matchBracket').checked;
var codeHint = document.getElementById('codeHint').checked;
chrome.storage.sync.set({
syntaxHighlight: syntaxHighlight,
lineNumbers: lineNumbers,
wrapLines : wrapLines,
matchTag: matchTag,
matchBracket : matchBracket,
codeHint : codeHint
}, function() {
// Update status to let user know options were saved.
var status = document.getElementById('status');
status.textContent = 'Options saved.';
setTimeout(function() {
status.textContent = '';
}, 750);
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, "refresh");
});
});
}
function restore_options() {
//Use default values if the storage is empty. Enable everything
chrome.storage.sync.get({
syntaxHighlight: true,
lineNumbers: true,
wrapLines : true,
matchTag: true,
matchBracket : true,
codeHint : true
}, function(items) {
document.getElementById('syntaxHighlight').checked = items.syntaxHighlight;
document.getElementById('lineNumbers').checked = items.lineNumbers;
document.getElementById('wrapLines').checked = items.wrapLines;
document.getElementById('matchTag').checked = items.matchTag;
document.getElementById('matchBracket').checked = items.matchBracket;
document.getElementById('codeHint').checked = items.codeHint;
});
}
document.addEventListener('DOMContentLoaded', restore_options);
document.getElementById('save').addEventListener('click',
save_options);