mirror of
https://github.com/YouHaveTrouble/youhavetrouble.github.io.git
synced 2026-05-11 22:06:56 +00:00
46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
const status = document.querySelector("#status");
|
|
const action = document.querySelector("#status-action");
|
|
const avatar = document.querySelector(".avatar");
|
|
|
|
updateStatus();
|
|
window.setInterval(updateStatus, 10000);
|
|
|
|
async function updateStatus() {
|
|
const result = await fetch("https://api.youhavetrouble.me/online");
|
|
|
|
if (result.status !== 200) return;
|
|
|
|
const json = await result.json();
|
|
switch (json.steam.status) {
|
|
case "ONLINE":
|
|
status.innerText = "Currently Online";
|
|
action.innerText = "";
|
|
setavatarBg("online")
|
|
return;
|
|
case "IN_GAME":
|
|
status.innerText = "Currently Online";
|
|
action.innerText = `Playing ${json.steam.game}`;
|
|
setavatarBg("online")
|
|
return;
|
|
}
|
|
|
|
if (json.discord === "DO_NOT_DISTURB" || json.discord === "ONLINE") {
|
|
status.innerText = "Currently Online";
|
|
action.innerText = "";
|
|
setavatarBg("online")
|
|
return;
|
|
}
|
|
|
|
status.innerText = "Currently Offline";
|
|
action.innerText = "";
|
|
setavatarBg("offline")
|
|
}
|
|
|
|
function setavatarBg(status) {
|
|
if (status === "online") {
|
|
avatar.style.backgroundColor = "#5a9a5a"
|
|
} else if (status === "offline") {
|
|
avatar.style.backgroundColor = "#a62d2d"
|
|
}
|
|
}
|