-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
41 lines (36 loc) · 1.23 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
// Saves options to chrome.storage
function save_options() {
chrome.storage.sync.set({
infiniteAirhorns: this.checked
}, function() {
// Update status to let user know options were saved.
var status = document.getElementById('status');
status.textContent = 'Options saved!';
status.classList.add('update');
// Reload background page to update options
// (in this case, it's not critical we keep the extension running)
chrome.runtime.getBackgroundPage(function(backgroundWindow) {
backgroundWindow.location.reload();
});
// Yeah, I know this animation sucks
setTimeout(function() {
status.classList.remove('update');
setTimeout(function() {
status.textContent = '';
}, 301);
}, 750);
});
}
// Restores select box and checkbox state using the preferences
// stored in chrome.storage.
function restore_options() {
// Use default value (infiniteAirhorns: true)
// if we can't find any stored options
chrome.storage.sync.get({
infiniteAirhorns: true
}, function(items) {
document.getElementById('infiniteAirhorns').checked = items.infiniteAirhorns;
});
}
document.addEventListener('DOMContentLoaded', restore_options);
document.getElementById('infiniteAirhorns').addEventListener('change', save_options);