forked from Khan/KhanAcademyDots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
40 lines (37 loc) · 1.08 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
/*global chrome, document*/
/**
* Saves options to chrome.storage
*
* This code is mostly copy-pasta from Chrome documentation example
* https://developer.chrome.com/extensions/options
*
* @returns {undefined}
*/
function saveOptions() {
const locale = document.getElementById('locale').value;
chrome.storage.sync.set({
locale: locale,
}, function() {
// Update status to let user know options were saved.
const status = document.getElementById('status');
status.textContent = 'Options saved.';
setTimeout(function() {
status.textContent = '';
}, 1500);
});
}
/**
* Restores select box and checkbox state on options page
* using the preferences stored in chrome.storage.
*
* @returns {undefined}
*/
function restoreOptions() {
chrome.storage.sync.get({
locale: 'not-set',
}, function(items) {
document.getElementById('locale').value = items.locale;
});
}
document.addEventListener('DOMContentLoaded', restoreOptions);
document.getElementById('save').addEventListener('click', saveOptions);