-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
63 lines (58 loc) · 2.09 KB
/
popup.js
File metadata and controls
63 lines (58 loc) · 2.09 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
(async () => {
/**
* @type {{targetUrl: string}}
*/
const { targetUrl: url } = await chrome.storage.local.get("targetUrl");
/**
* @type {{name: string, value: string}[]}
*/
let cookies = [
await chrome.cookies.get({
url,
name: "focus_token"
}),
await chrome.cookies.get({
url,
name: "focus_session_id"
}),
await chrome.cookies.get({
url,
name: "focus_php_session_id"
}),
await chrome.cookies.get({
url,
name: "focus_login_token"
})
];
if (cookies.every((cookie) => cookie !== null)) {
document.getElementById(
"description"
).innerHTML = `Existing Auth Cookies found: <br>
${cookies
.map(
(cookie) =>
`${cookie.name}: ${cookie.value.substring(0, 5)}...`
)
.join("<br>")}`;
document.getElementById("loginButton").innerText = "Refresh Session";
} else {
document.getElementById("description").innerText =
"No Cookies found, please login to Focus to authenticate.";
document.getElementById("loginButton").innerText = "Log In";
}
let { prodUrl } = await chrome.storage.local.get("prodUrl");
let { devUrl } = await chrome.storage.local.get("devUrl");
document.getElementById("prodLabel").innerText = prodUrl;
document.getElementById("localLabel").innerText = devUrl;
// set the correct radio button to selected based on the current activeUrl
document.getElementById("prod").checked = url === prodUrl;
document.getElementById("local").checked = url === devUrl;
document
.getElementById("targetUrlSelector")
.addEventListener("change", () => {
let newTargetUrl = prodUrl;
if (document.getElementById("local").checked) newTargetUrl = devUrl;
console.log("Setting new turl: " + newTargetUrl);
chrome.storage.local.set({ targetUrl: newTargetUrl });
});
})();