-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (29 loc) · 1.27 KB
/
index.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
// Global variables used for popup
let pageInfo;
let pageType;
let tabId;
// Registration tasks are handled in registrationTasks.js
initTaskRemovalTimeouts();
// Check if tab is a registration page
client.tabs.query({ active: true, currentWindow: true }, async (tabs) => {
tabId = tabs[0].id;
let tabUrl = tabs[0].url;
if (!/https:\/\/tiss.tuwien.ac.at\/education\/course\/(courseRegistration|groupList|examDateList)/.test(tabUrl)) return;
// Determine type of registration
if (/courseRegistration/.test(tabUrl)) pageType = "lva";
else if (/groupList/.test(tabUrl)) pageType = "group";
else if (/examDate/.test(tabUrl)) pageType = "exam";
// Switch the info text from "wrong url" to "loading"
document.getElementById("info-wrong-url").hidden = true;
document.getElementById("info-page-load").hidden = false;
// Get the page info from the content script
// This is necessary because the popup can be opened before the content script has loaded
while (!pageInfo) {
// Catch empty because it just means the tab hasn't loaded yet
pageInfo = await client.tabs.sendMessage(tabId, { action: "getPageInfo" }).catch(() => {});
}
// Hide loading text
document.getElementById("info-page-load").hidden = true;
// Option selector is handled in optionSelector.js
initOptionSelector();
});