-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpopup.js
50 lines (39 loc) · 1.34 KB
/
popup.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
$(function(){
chrome.storage.sync.get(['total','limit'],function(budget){
$('#total').text(budget.total);
$('#limit').text(budget.limit);
})
document.getElementById('amount').style.height="20px";
document.getElementById('amount').style.fontSize="14pt";
$('#spendAmount').click(function(){
chrome.storage.sync.get(['total', 'limit'], function(budget){
var newTotal = 0;
if (budget.total){
newTotal += parseInt(budget.total);
}
var amount = $('#amount').val();
if (amount){
newTotal += parseInt(amount);
}
// chrome.storage.sync.set({'total': newTotal});
chrome.storage.sync.set({'total': newTotal} , function(){
console.log(amount, newTotal, budget.limit)
if(amount && newTotal >= budget.limit){
console.log('Hello')
var notifOptions = {
type: "basic",
iconUrl: "images/get_started48.png",
title: "Over budget!",
message: "If you make this purchase you will go over budget"
};
chrome.notifications.clear('limitNotif')
chrome.notifications.create('limitNotif', notifOptions, (noteId) => {
console.log('Got notification with id: ', noteId)
});
}
});
$('#total').text(newTotal);
$('#amount').val('');
});
});
});