forked from vishwapatel/BitsurfCE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
80 lines (69 loc) · 3.1 KB
/
background.js
File metadata and controls
80 lines (69 loc) · 3.1 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
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
console.log("Something happened.");
function onMessage(request, sender, sendResponse) {
if (request.action == 'getJSON') {
console.log("getJSON");
$.ajax({url:request.url,
dataType: 'json',
success:function(data) {
sendResponse(data);
}})};
if (request.action == 'post') {
console.log("post");
$.ajax({url:request.url,
type: 'POST',
data: { email: request.email, password: request.pass},
success:function(data) {
sendResponse(data);
}})};
if(request.method == "send-payment") {
console.log("hey");
chrome.storage.local.get("bitcoin_addr", function(data) {
if (!($.isEmptyObject(data))) {
var callUrl = 'http://ec2-23-22-205-148.compute-1.amazonaws.com:8000/send-payment?bitcoin_addr=' + data['bitcoin_addr'] + '&website=' + request.url;
console.log(callUrl);
onMessage({action:'getJSON',url:callUrl}, null, function (data2) {
if (data2.capped == false) {
var total_earned = data2['total_earned'];
chrome.storage.local.set({"total_earned": total_earned}, function(response) {});
//chrome.storage.local.get({"total_earned": total_earned}, function(response) {});
var notifCount;
chrome.storage.local.get('notifCount', function (data3) {
if (!($.isEmptyObject(data3))) {
console.log(data3['notifCount']);
notifCount = data3['notifCount'];
}
else {
console.log("else");
notifCount = 0;
}
chrome.storage.local.set({'notifCount': (notifCount + 1)}, function(response) {});
var newId = 'id' + notifCount;
console.log(newId);
chrome.notifications.create(
newId,{
type: 'basic',
iconUrl: 'toolbar_icon.png',
title: 'bitSurf',
message: 'You now have ' + data2['total_earned'] + ' BTC',
priority: 0},
function() { /* Error checking goes here */}
);
});
}
/*chrome.tabs.query({active: true, currentWindow: true}, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, {"total_earned": total_earned}, function(response) {
console.log(response);
});
});*/
});
}
});
}
return true;
};
function notificationClosed(notID, bByUser) {
console.log("NOTIF CLOSED:" + notID);
//chrome.notifications.clear(notID, function() {});
}
chrome.runtime.onMessage.addListener(onMessage);
chrome.notifications.onClosed.addListener(notificationClosed);