-
Notifications
You must be signed in to change notification settings - Fork 14
/
background.js
36 lines (32 loc) · 987 Bytes
/
background.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 getVersion() {
var version = 'Unknown';
var xhr = new XMLHttpRequest();
xhr.open('GET', chrome.extension.getURL('manifest.json'), false);
xhr.send(null);
var manifest = JSON.parse(xhr.responseText);
return manifest.version;
}
function handleLogRequest(request) {
$.post("http://dominion-point-counter.appspot.com/log_game", request);
}
function handleFetchRequest(request, sendResponse) {
$.get(request.url, function(response) {
console.log("response");
sendResponse({ data: response });
})
}
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
var type = request.type;
delete request.type;
if (type == "log") {
handleLogRequest(request);
} else if (type == "version") {
sendResponse(getVersion());
} else if (type == "fetch") {
handleFetchRequest(request, sendResponse);
} else {
console.log("Unknown request type '" + type + "' in: " +
JSON.stringify(request));
}
});