-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
65 lines (55 loc) · 2 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
function saveOptions() {
var interval = getElementValue("interval");
var sound = getElementValue("sound");
var messageCount = getElementValue("message-count");
var displayTime = getElementValue("display-time");
var notificationClick = getElementValue("notification-click");
var selectedCategories = $("#categories").val();
chrome.storage.sync.set({
"sound": sound,
"interval": interval,
"messageCount": messageCount,
"displayTime": displayTime,
"notificationClick": notificationClick,
"selectedCategories": selectedCategories
}, function() {
var submit = document.getElementById('save');
var oldText = submit.innerHTML;
submit.innerHTML = 'OK...';
setTimeout(function() {
submit.innerHTML = oldText;
}, 1200);
});
}
function getElementValue(elementId) {
var element = document.getElementById(elementId);
var value = parseInt(element.value);
if (element.getAttribute("min") != null && value < element.getAttribute("min")) {
element.value = element.getAttribute("min");
} else if (element.getAttribute("max") != null && value > element.getAttribute("max")) {
element.value = element.getAttribute("max");
}
return element.value;
}
function restoreOptions() {
chrome.storage.sync.get({
"sound": "no-sound",
"interval": 5,
"messageCount": 3,
"displayTime": 10,
"notificationClick": "open",
"selectedCategories": []
}, function(items) {
$('#interval').val(items['interval']);
$('#sound').val(items['sound']);
$('#message-count').val(items['messageCount']);
$('#display-time').val(items['displayTime']);
$('#notification-click').val(items['notificationClick']);
$('#categories').val(items['selectedCategories']);
$('select').material_select();
});
}
$(document).ready(function() {
restoreOptions();
$('#save').bind('click', saveOptions);
});