-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
59 lines (54 loc) · 2.03 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const EXPIRATION_SECONDS = 60 * 60 * 24 * 5; // 5 days
const prodUrl = "https://refocused.up.railway.app/";
const devUrl = "http://127.0.0.1:3000/";
const targetUrl = prodUrl;
chrome.storage.local.set({ prodUrl });
chrome.storage.local.set({ devUrl });
chrome.storage.local.set({ targetUrl });
chrome.runtime.onMessage.addListener(
/**
* @param {{type: string, sessionId: string, token: string, loginToken: string}} msg
* @param {any} sender
* @param {function(any): void} sendResponse
*/ ({ type, sessionId, token, loginToken }, sender, sendResponse) => {
console.log(type, sessionId, token, loginToken);
if (type === "refreshCookies") {
(async () => {
let { targetUrl } = await chrome.storage.local.get("targetUrl");
let expiry = Math.floor(Date.now() / 1000) + EXPIRATION_SECONDS;
chrome.cookies.set({
url: targetUrl,
name: "focus_login_token",
value: loginToken,
expirationDate: expiry
});
chrome.cookies.set({
url: targetUrl,
name: "focus_session_id",
value: sessionId,
expirationDate: expiry
});
chrome.cookies.set({
url: targetUrl,
name: "focus_token",
value: token,
expirationDate: expiry
});
/**
* @type {{name: string}}
*/
let { value } = await chrome.cookies.get({
url: "https://brevardk12.focusschoolsoftware.com/focus",
name: "PHPSESSID"
});
chrome.cookies.set({
url: targetUrl,
name: "focus_php_session_id",
value,
expirationDate: expiry
});
})();
}
sendResponse("done");
}
);