-
Notifications
You must be signed in to change notification settings - Fork 0
/
contentScript.js
45 lines (41 loc) · 1.3 KB
/
contentScript.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
let updateStatus = true;
let lastSavedStatus;
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.operation === "checkStatus") {
// We wait 500 ms so that the XUI scripts
// have time to inject the result into the DOM
setTimeout(checkIfStandby, 500);
} else if (request.operation === "stopUpdating") {
updateStatus = false;
document.body.classList.remove("standby-lb-detector-css");
}
});
const checkIfStandby = () => {
const statusInfo = document.getElementById("status").innerText.toLowerCase();
if (status !== lastSavedStatus) {
if (statusInfo.includes("standby")) {
saveStatus("standby");
if (updateStatus) {
document.body.className = "standby-lb-detector-css";
chrome.runtime.sendMessage({ operation: "activateButton" });
}
} else {
// We enable updating if the box is active
// So that we notify if the box goes standby -> active -> standby
saveStatus("active");
updateStatus = true;
document.body.classList.remove("standby-lb-detector-css");
chrome.runtime.sendMessage({ operation: "deactivateButton" });
}
}
};
const saveStatus = status => {
chrome.storage.local.set(
{
[location.hostname]: status
},
() => {
lastSavedStatus = status;
}
);
};