forked from ryanodd/nyt-pencil-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
34 lines (30 loc) · 1.07 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
const NYTPencilExtensionOptions = "NYTPencilExtensionOptions";
const DefaultPencilKeyCode = "ShiftLeft";
const KeyCodeId = "KeyCode";
const StatusId = "status";
// Saves options to chrome.storage
const saveOptions = () => {
const keyCode = document.getElementById(KeyCodeId).value;
chrome.storage.sync.set(
{ NYTPencilExtensionOptions: { pencilKeyCode: keyCode } },
() => {
// Update status to let user know options were saved.
const status = document.getElementById(StatusId);
status.textContent = "Options saved.";
setTimeout(() => {
status.textContent = "";
}, 1500);
}
);
};
// Restores select box with value stored in chrome.storage.
const restoreOptions = () => {
chrome.storage.sync.get(
{ NYTPencilExtensionOptions: { pencilKeyCode: `${DefaultPencilKeyCode}` } },
(items) => {
document.getElementById(KeyCodeId).value = items.NYTPencilExtensionOptions.pencilKeyCode;
}
);
};
document.addEventListener("DOMContentLoaded", restoreOptions);
document.getElementById("save").addEventListener("click", saveOptions);