-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
56 lines (52 loc) · 2.13 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
const DEFAULT_COLOR = "000000"
const DEFAULT_BOLD = false
const DEFAULT_SHOW_COPY = false
const DEFAULT_COPY_PREFIX = ""
const DEFAULT_COPY_SEP = ", "
const DEFAULT_COPY_SUFFIX = ""
function save_options() {
var bold = document.getElementById('bold').checked;
var color = document.getElementById('id-color').value;
var copy = document.getElementById('show-copy').checked;
var pref = document.getElementById('copy-prefix').value;
var sep = document.getElementById('copy-sep').value;
var suff = document.getElementById('copy-suffix').value;
chrome.storage.sync.set({
boldId: bold,
idColor: color,
showCopy: copy,
copyPrefix: pref,
copySep: sep,
copySuffix: suff
}, function() {
window.close();
});
}
function reset_defaults() {
document.getElementById('bold').checked = DEFAULT_BOLD;
document.getElementById('show-copy').checked = DEFAULT_SHOW_COPY;
document.getElementById('id-color').color.fromString("#"+DEFAULT_COLOR);
document.getElementById('copy-prefix').value = DEFAULT_COPY_PREFIX;
document.getElementById('copy-sep').value = DEFAULT_COPY_SEP;
document.getElementById('copy-suffix').value = DEFAULT_COPY_SUFFIX;
}
function restore_options() {
chrome.storage.sync.get({
boldId: DEFAULT_BOLD,
showCopy: DEFAULT_SHOW_COPY,
idColor: DEFAULT_COLOR,
copyPrefix: DEFAULT_COPY_PREFIX,
copySep: DEFAULT_COPY_SEP,
copySuffix: DEFAULT_COPY_SUFFIX
}, function(items) {
document.getElementById('bold').checked = items.boldId;
document.getElementById('show-copy').checked = items.showCopy;
document.getElementById('id-color').color.fromString(items.idColor);
document.getElementById('copy-prefix').value = items.copyPrefix;
document.getElementById('copy-sep').value = items.copySep;
document.getElementById('copy-suffix').value = items.copySuffix;
});
}
document.addEventListener('DOMContentLoaded', restore_options);
document.getElementById('save').addEventListener('click', save_options);
document.getElementById('defaults').addEventListener('click', reset_defaults);