-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfocusCS.js
More file actions
63 lines (53 loc) · 1.96 KB
/
focusCS.js
File metadata and controls
63 lines (53 loc) · 1.96 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
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
/**
* @type {string}
*/
let targetUrl;
chrome.storage.local
.get("targetUrl")
.then((/** @type {{targetUrl: string}} */ { targetUrl: res }) => {
targetUrl = res;
}); // Can't use await here, so we have to use a promise
let url = new URL(window.location.href);
let urlParams = new URLSearchParams(url.search);
let redir = urlParams.get("redir");
if (redir) {
chrome.storage.local.set({ redir });
}
const hideElems = document.createElement("style");
hideElems.innerHTML = "*{display:none !important;}";
document.documentElement.appendChild(hideElems);
// Register an event listener for the page to finish loading and then copy the auth token + go to redir + remove redir
document.addEventListener("DOMContentLoaded", async () => {
/**
* @type {{redir: string}}
*/
let { redir } = await chrome.storage.local.get("redir");
chrome.storage.local.set({ redir: null });
if (!redir) {
hideElems.remove();
}
// We get the token from the mobile app because it gives us access to more Controllers
let mobileHTML = await fetch(
"https://brevardk12.focusschoolsoftware.com/focus/mobileApps/community/?expo=true"
).then((r) => r.text());
let sessionId =
/static get session_id\(\) {\n[\s]*return "([\w+=/]+)";/g.exec(
mobileHTML
)[1];
let token = /__Module__\.token = "([\w+=/.-]+)"/g.exec(mobileHTML)[1];
let loginToken = /"login_token":"([\w]*)"/g.exec(mobileHTML)[1];
// Send a message to the background script to refresh the end cookies
chrome.runtime.sendMessage({
type: "refreshCookies",
token,
sessionId,
loginToken
});
// If there is a redir parameter set, go to that page and remove the redir parameter
if (redir) {
window.location.replace(redir
.replace("ref", targetUrl)
// remove any more than one `/` in a row, except for the protocol
.replace(/(?<!:)(\/{2,})/g, "/"));
}
});