-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.js
More file actions
32 lines (29 loc) · 1.03 KB
/
Copy pathbackground.js
File metadata and controls
32 lines (29 loc) · 1.03 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
function sendRequest(url) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
console.log("XHTTP URL: " + url);
console.log("XHTTP response: " + xhttp.responseText);
return xhttp.responseText;
}
};
xhttp.open("GET", url, true);
xhttp.send();
}
function scrapeCourse(courseCode) {
// Need to be logged into https://ust.space
// TODO: Open tab to log into USTSPACE if not logged in
var spaceURL = "https://ust.space/review/" + courseCode;
console.log("USTSPACE URL: " + spaceURL);
return sendRequest(spaceURL);
}
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log("Received message from " + request.code);
var response = scrapeCourse(request.code);
sendResponse(response);
}
);
chrome.browserAction.onClicked.addListener(function() {
chrome.tabs.create({'url': "https://w5.ab.ust.hk/wcq/cgi-bin/1710/"});
});