-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.js
More file actions
49 lines (46 loc) · 1.57 KB
/
Copy pathoptions.js
File metadata and controls
49 lines (46 loc) · 1.57 KB
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
var validInput = function(val) {
console.log("val" + val);
return !isNaN(val);
}
document.addEventListener('DOMContentLoaded', function() {
chrome.storage.local.get(['superhappy', 'happy', 'neutral', 'sad', 'limit'], function(items) {
if (!items.superhappy) {
$("#superhappybox").val("6");
$("#happybox").val("11");
$("#neutralbox").val("16");
$("#sadbox").val("21");
} else {
$("#superhappybox").val(items.superhappy);
$("#happybox").val(items.happy);
$("#neutralbox").val(items.neutral);
$("#sadbox").val(items.sad);
$("#limitbox").prop('checked', items.limit);
}
});
$("#savebutton").click(function() {
var superhappy = parseInt($('#superhappybox').val());
var happy = parseInt($('#happybox').val());
var neutral = parseInt($('#neutralbox').val());
var sad = parseInt($('#sadbox').val());
var limit = $('#limitbox').is(':checked');
if (!validInput(superhappy) || !validInput(happy) || !validInput(neutral) || !validInput(sad)) {
alert("Please put in integers only :(");
return;
} else if (!(superhappy < happy && happy < neutral && neutral < sad)) {
alert("Please make sure each number is progressively higher (happy " +
"is a lower number than neutral for example)");
return;
} else {
var items = {
'superhappy': superhappy,
'happy': happy,
'neutral': neutral,
'sad': sad,
'limit': limit
};
chrome.storage.local.set(items, function() {
console.log('finished saving');
});
}
});
});