-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.js
63 lines (51 loc) · 1.7 KB
/
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
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
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse){
/*https://developer.chrome.com/extensions/xhr#extension-origin
https://developer.chrome.com/extensions/runtime#event-onMessage
https://developer.chrome.com/extensions/runtime#method-sendMessage*/
if(request.action == "xhttp"){
//creating XMLHttpRequest object
var xhttp = new XMLHttpRequest();
//waits for request to be finished and response is ready
xhttp.onload = function(){
//returning response data as a string
var response = xhttp.responseText;
sendResponse(response);
};
//specifies request
//url is a file on the server
xhttp.open(request.method, request.url, true);
//send request to server
xhttp.send();
return true;
}
else if(request.action == "schedule"){
var xhttp = new XMLHttpRequest();
xhttp.onload = function(){
var response = xhttp.responseText;
sendResponse(response);
};
//initializing request
xhttp.open(request.method, request.url, true);
//send request
xhttp.send();
return true;
}
// else if(request.greeting == "hello"){
// sendResponse({farewell: "goodbye"});
// }
// else if(request.injectSpecific){
// chrome.runtime.reload();
// chrome.tabs.query({url:"https://www.beartracks.ualberta.ca/psp/uahebprd/EMPLOYEE/HRMS/c/SA_LEARNER_SERVICES*"}, function(tabs){
// for(var i = 0; i < tabs.length; i++){
// chrome.tabs.executeScript(tab[i].id, {file: "content.js"}, function(){
// sendResponse({done: true});
// });
// }
// })
// //var name = getSpecificName(sender.url);
// // chrome.tabs.executeScript(sender.tab.id, {file: "content.js"}, function(){
// // sendResponse({done: true});
// // });
// return true;
// }
});