-
Notifications
You must be signed in to change notification settings - Fork 3
/
options.js
43 lines (38 loc) · 1.5 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
// Saves options to chrome.storage.sync.
function save_options(e) {
e.preventDefault();
let sameTab = document.getElementById('sameTab').checked;
let removeToilet = document.getElementById('removeToilet').checked;
let maxWidth = document.getElementById('maxWidth').value;
chrome.storage.sync.set({
sameTab: sameTab,
removeToilet: removeToilet,
maxWidth: maxWidth
}, function () {
// Update status to let user know options were saved.
document.getElementById('status').style.opacity = 1;
title = sameTab ? "Open Hive in same tab" : "Open Hive in new tab";
chrome.browserAction.setTitle({
'title': title
})
setTimeout(function () {
window.close();
}, 1000);
});
}
// Restores select box and checkbox state using the preferences
// stored in chrome.storage.
function restore_options() {
// Use default sameTab = false, removeToilet = false
chrome.storage.sync.get({
sameTab: false,
removeToilet: false,
maxWidth: maxWidth
}, function (settings) {
document.getElementById('sameTab').checked = settings.sameTab;
document.getElementById('removeToilet').checked = settings.removeToilet;
document.getElementById('maxWidth').value = settings.maxWidth;
});
}
document.addEventListener('DOMContentLoaded', restore_options);
document.getElementById('settings').addEventListener('submit', save_options);