-
Notifications
You must be signed in to change notification settings - Fork 0
/
remoodle.js
38 lines (33 loc) · 1.38 KB
/
remoodle.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
// init globals
var REFRESH_DELAY = 5; // minutes
var MOODLE_AUTH_URL = "https://moodle2.cs.huji.ac.il/nu20/auth/saml/index.php";
var MOODLE_LOGGED_IN_REDIRECT = "https://moodle2.cs.huji.ac.il/nu20/parent_reload.php";
(function() {
// we are using the chrome namespace instead of browser even though it is not standard,
// simply because Firefox supports these namespace and chrome is a bully.
// setup alarm
chrome.alarms.clearAll();
chrome.alarms.onAlarm.addListener((alarm) => {
// sanity I guess
if (alarm.name != "remoodle") {
return;
}
// just poll - I think an opaque response is ok here
fetch(MOODLE_AUTH_URL, {mode: "no-cors"})
.then(function (response) {
// log some stuff
if (response.url == MOODLE_LOGGED_IN_REDIRECT) {
console.log("Login refreshed...");
} else if (!response.url) {
console.log("Due to cors, can't see if logged in or not.");
} else {
console.log("Probably not logged in? Got url " + response.url);
}
})
.catch(function (error) {
console.log("Error: " + error);
});
});
// start polling
chrome.alarms.create("remoodle", {periodInMinutes: REFRESH_DELAY});
})();