-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.html
54 lines (51 loc) · 1.67 KB
/
background.html
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
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
/**
* Performs an XMLHttpRequest to Wikipedia
* @param callback Function If the response from fetching url has a
* HTTP status of 200, this function is called with a JSON decoded
* response. Otherwise, this function is called with null.
*/
function doAjaxRequest(url, callback) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(data) {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
var data = xhr.responseText;
callback(data);
} else {
callback(null);
}
}
}
xhr.open('GET', url, true);
xhr.send();
};
/**
* Handles data sent via chrome.extension.sendRequest().
* @param request Object Data sent in the request.
* @param sender Object Origin of the request.
* @param callback Function The method to call when the request completes.
*/
function onRequest(request, sender, callback) {
if(request.action == 'doAjaxRequest') {
doAjaxRequest(request.url, callback);
}
if(request.action == 'getSettings') {
var username = localStorage["username"];
if(username == undefined || username == '') {
chrome.tabs.create({url:chrome.extension.getURL("options.html")});
} else {
callback({username: localStorage["username"], password: localStorage["password"] });
}
}
};
// Wire up the listener.
chrome.extension.onRequest.addListener(onRequest);
</script>
</body>
</html>