-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patheventPage.js
101 lines (91 loc) · 2.64 KB
/
eventPage.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
var item = {
"id": "budgetBabe",
"title": "BudgetBabe",
"contexts": ["selection"]
};
function isInt(value) {
return !isNaN(value) &&
parseInt(Number(value)) == value &&
!isNaN(parseInt(value, 10));
}
chrome.contextMenus.create(item);
chrome.contextMenus.onClicked.addListener(function(clickData){
if (clickData.menuItemId == "budgetBabe" && 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: "get_started48.png",
title: "Over budget!",
message: "If you make this purchase you will go over budget"
};
chrome.notifications.create('limitNotif', notifOptions);
}
});
});
}
}
});
chrome.storage.onChanged.addListener(function(changes, storageName){
chrome.pageAction.setBadgeText({"text": changes.total.newValue.toString()});
});
// var menuItem = {
// "id": "budgetBabe",
// "title": "BudgetBabe",
// "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 == "budgetBabe" && 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()});
// });