-
Notifications
You must be signed in to change notification settings - Fork 1
/
popup.js
36 lines (32 loc) · 1 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
$(function () {
chrome.storage.sync.get(["total", "limit"], function (budget) {
$("#total").text(budget.total);
$("#limit").text(budget.limit);
});
$("#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 }, function () {
if (amount && newTotal >= budget.limit) {
var notifOptions = {
type: "basic",
iconUrl: "icon48.png",
title: "limit reached!",
message: "Uh oh! Looks like you have reached your limit!",
};
chrome.notifications.create("limitNotif", notifOptions);
chrome.notifications.clear("limitNotif");
}
});
$("#total").text(newTotal);
$("#amount").val("");
});
});
});