-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.js
59 lines (49 loc) · 1.56 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
// Saves options to chrome.storage
function save_options() {
var modeType = document.querySelector('input[name="mode"]:checked').value;
if (modeType == 0) {
chrome.action.setPopup({ popup: "bookmarks.html" });
} else {
chrome.action.setPopup({ popup: "popup.html" });
}
chrome.storage.local.set({
modeType: modeType,
}, function() {
var status = document.getElementById('status');
status.textContent = 'Options saved. / 设置已保存';
setTimeout(function() {
status.textContent = '';
}, 5000);
});
}
// Restores select box and checkbox state using the preferences
// stored in chrome.storage.
function restore_options() {
chrome.storage.local.get({
modeType: '0',
}, function(items) {
document.getElementById('mode-' + items.modeType).checked = true;
});
}
function reset_options() {
chrome.storage.local.clear();
restore_options();
}
document.addEventListener('DOMContentLoaded', function() {
restore_options();
var shortcuts = document.getElementById('setShortcuts');
shortcuts.addEventListener('click', function() {
openShortcuts();
});
});
var inputs = document.getElementsByTagName('input');
for (let index = 0; index < inputs.length; index++) {
const input = inputs[index];
input.addEventListener('change', save_options);
}
// document.getElementById("btnReset").addEventListener('click', reset_options);
function openShortcuts() {
chrome.tabs.create({
url: 'chrome://extensions/shortcuts'
});
}