-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheventPage.js
More file actions
executable file
·44 lines (38 loc) · 1.5 KB
/
eventPage.js
File metadata and controls
executable file
·44 lines (38 loc) · 1.5 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
var menuItem = {
"id": "spendMoney",
"title": "Spend Money",
"contexts": ["selection"]
};
function isInt(value) {
return !isNaN(value) &&
parseInt(Number(value)) == value &&
!isNaN(parseInt(value, 10));
}
chrome.contextMenus.create(menuItem);
chrome.contextMenus.onClicked.addListener(function(clickData){
if (clickData.menuItemId == "spendMoney" && clickData.selectionText){
if (isInt(clickData.selectionText)){
chrome.storage.sync.get(['total','limit'], function(budget){
var newTotal = 0;
if (budget.total){
newTotal += parseInt(budget.total);
}
newTotal += parseInt(clickData.selectionText);
chrome.storage.sync.set({'total': newTotal}, function(){
if (newTotal >= budget.limit){
var notifOptions = {
type: "basic",
iconUrl: "icon48.png",
title: "Limit reached!",
message: "Uh oh, look's like you've reached your alloted limit."
};
chrome.notifications.create('limitNotif', notifOptions);
}
});
});
}
}
});
chrome.storage.onChanged.addListener(function(changes, storageName){
chrome.browserAction.setBadgeText({"text": changes.total.newValue.toString()});
});