-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
40 lines (38 loc) · 1.31 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
BASE_URL = "https://e3p.nycu.edu.tw";
// handle fetching data
var options;
chrome.runtime.onConnect.addListener(function(port) {
if (port.name) {
port.onMessage.addListener(function(response) {
if (response["type"] == "main") {
options = {
headers: {
Cookie: `MoodleSession=${response["session"]}`
}
};
fetch(BASE_URL, options)
.then(res => {
return res.text();
})
.then(html => {
port.postMessage({
"type": "main",
"data": html
});
})
} else if (response["type"] == "course") {
let url = `${BASE_URL}/local/courseextension/index.php?courseid=${response["id"]}&scope=assignment`
fetch(url, options)
.then(res => {
return res.text();
})
.then(html => {
port.postMessage({
"type": "course",
"data": html
});
})
}
})
}
})