forked from infokiller/web-search-navigator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
76 lines (73 loc) · 3.01 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Based on https://developer.chrome.com/extensions/optionsV2
// Saves options to chrome.storage.sync.
const saveOptions = () => {
chrome.storage.sync.set(
{
wrapNavigation: document.getElementById('wrap-navigation').checked,
autoSelectFirst: document.getElementById('auto-select-first').checked,
nextKey: document.getElementById('next-key').value,
previousKey: document.getElementById('previous-key').value,
navigateKey: document.getElementById('navigate-key').value,
navigateNewTabKey:
document.getElementById('navigate-new-tab-key').value,
navigateSearchTab:
document.getElementById('navigate-search-tab').value,
navigateImagesTab:
document.getElementById('navigate-images-tab').value,
navigateVideosTab:
document.getElementById('navigate-videos-tab').value,
navigateMapsTab:
document.getElementById('navigate-maps-tab').value,
navigateNewsTab:
document.getElementById('navigate-news-tab').value,
},
() => {
// Update status to let user know options were saved.
let status = document.getElementById('status');
status.textContent = 'Options saved.';
setTimeout(function() {
status.textContent = '';
}, 3000);
});
};
// Restores select box and checkbox state using the preferences
// stored in chrome.storage.
const restoreOptions = () => {
chrome.storage.sync.get(
{
wrapNavigation: false,
autoSelectFirst: true,
nextKey: 'down, j',
previousKey: 'up, k',
navigateKey: 'return, space',
navigateNewTabKey: 'ctrl+return, command+return, ctrl+space',
navigateSearchTab: 'a, s',
navigateImagesTab: 'i',
navigateVideosTab: 'v',
navigateMapsTab: 'm',
navigateNewsTab: 'n'
},
(items) => {
document.getElementById('wrap-navigation').checked =
items.wrapNavigation;
document.getElementById('auto-select-first').checked =
items.autoSelectFirst;
document.getElementById('next-key').value = items.nextKey;
document.getElementById('previous-key').value = items.previousKey;
document.getElementById('navigate-key').value = items.navigateKey;
document.getElementById('navigate-new-tab-key').value =
items.navigateNewTabKey;
document.getElementById('navigate-search-tab').value =
items.navigateSearchTab;
document.getElementById('navigate-images-tab').value =
items.navigateImagesTab;
document.getElementById('navigate-videos-tab').value =
items.navigateVideosTab;
document.getElementById('navigate-maps-tab').value =
items.navigateMapsTab;
document.getElementById('navigate-news-tab').value =
items.navigateNewsTab;
});
};
document.addEventListener('DOMContentLoaded', restoreOptions);
document.getElementById('save').addEventListener('click', saveOptions);