forked from joeyespo/inbox-by-gmail-checker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
76 lines (70 loc) · 2.88 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
function restoreOptions() {
chrome.storage.sync.get({
defaultUser: '0',
pollInterval: '3',
quietHours: '',
useSnoozeColor: true,
useDesktopNotifications: true,
openInEmptyTab: false
}, function(items) {
document.getElementById('defaultUser').value = items.defaultUser;
document.getElementById('pollInterval').value = items.pollInterval || 3;
document.getElementById('quietHours').value = items.quietHours;
document.getElementById('useSnoozeColor').checked = !!items.useSnoozeColor;
document.getElementById('useDesktopNotifications').checked = !!items.useDesktopNotifications;
document.getElementById('openInEmptyTab').checked = !!items.openInEmptyTab;
});
}
function saveOptions(e) {
e.preventDefault();
// Normalize
var defaultUser = Math.max(0, parseInt(document.getElementById('defaultUser').value) || 0);
var pollInterval = Math.max(0, Math.min(3600, parseInt(document.getElementById('pollInterval').value) || 3));
var quietHours = document.getElementById('quietHours').value;
var useSnoozeColor = document.getElementById('useSnoozeColor').checked;
var useDesktopNotifications = document.getElementById('useDesktopNotifications').checked;
var openInEmptyTab = document.getElementById('openInEmptyTab').checked;
chrome.storage.sync.set({
defaultUser: defaultUser,
pollInterval: pollInterval,
quietHours: quietHours,
useSnoozeColor: useSnoozeColor,
useDesktopNotifications: useDesktopNotifications,
openInEmptyTab: openInEmptyTab
}, function() {
// Update status to let user know options were saved.
var status = document.getElementById('status');
status.textContent = 'Options saved.';
setTimeout(function() {
status.textContent = '';
}, 3000);
});
// Show normalized values
restoreOptions();
return false;
}
function defaultOptions() {
document.getElementById('defaultUser').value = 0;
document.getElementById('pollInterval').value = 3;
document.getElementById('quietHours').value = '';
document.getElementById('useSnoozeColor').checked = true;
document.getElementById('useDesktopNotifications').checked = true;
document.getElementById('openInEmptyTab').checked = false;
}
function main() {
if (!chrome || !chrome.storage || !chrome.storage.sync) {
var status = document.getElementById('status');
status.style.cssText = 'color:red;';
status.textContent = 'Error: Could not load settings. Please upgrade Chrome.';
return;
}
document.addEventListener('DOMContentLoaded', restoreOptions);
document.getElementById('defaults').addEventListener('click', defaultOptions);
document.getElementById('optionsForm').addEventListener('submit', saveOptions);
document.getElementById('exampleQuietHours').addEventListener('click', function(e) {
e.preventDefault();
document.getElementById('quietHours').value = '9,10,11,12,13,14,15,16,17,18';
return false;
});
}
main();