-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
options.js
47 lines (43 loc) · 1.83 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
// https://developer.chrome.com/docs/extensions/mv2/options/
// Saves options to chrome.storage
function save_options() {
var backgroundColor = document.getElementById('backgroundColor').value;
var textColor = document.getElementById('textColor').value;
var buttonTitle = document.getElementById('buttonTitle').value;
var openInNewPage = document.getElementById('openInNewPage').checked;
var adaptToTheme = document.getElementById('adaptToTheme').checked;
chrome.storage.sync.set({
textColor: textColor,
backgroundColor: backgroundColor,
buttonTitle: buttonTitle,
openInNewPage: openInNewPage,
adaptToTheme: adaptToTheme,
}, function() {
// Update status to let user know options were saved.
var status = document.getElementById('status');
status.textContent = 'Options saved.';
setTimeout(function() {
status.textContent = '';
}, 750);
});
}
// Restores select box and checkbox state using the preferences
// stored in chrome.storage.
function restore_options() {
// Use default value
chrome.storage.sync.get({
backgroundColor: '#fafbfc',
textColor: '#24292e',
buttonTitle: 'View on Github1s',
openInNewPage: false,
adaptToTheme: true
}, function(items) {
document.getElementById('backgroundColor').value = items.backgroundColor;
document.getElementById('textColor').value = items.textColor;
document.getElementById('buttonTitle').value = items.buttonTitle;
document.getElementById('openInNewPage').checked = items.openInNewPage;
document.getElementById('adaptToTheme').checked = items.adaptToTheme;
});
}
document.addEventListener('DOMContentLoaded', restore_options);
document.getElementById('save').addEventListener('click', save_options);