[260112] Initial Build
This commit is contained in:
68
script.js
Normal file
68
script.js
Normal file
@@ -0,0 +1,68 @@
|
||||
// ping
|
||||
async function checkStatus() {
|
||||
const cards = document.querySelectorAll(".card");
|
||||
|
||||
cards.forEach(async (card) => {
|
||||
const url = card.getAttribute("data-url");
|
||||
const dot = card.querySelector(".bolt.tr");
|
||||
|
||||
try {
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
||||
|
||||
await fetch(url, {
|
||||
mode: "no-cors",
|
||||
cache: "no-cache",
|
||||
signal: controller.signal,
|
||||
});
|
||||
|
||||
dot.classList.remove("status-offline");
|
||||
dot.classList.add("status-online");
|
||||
clearTimeout(timeoutId);
|
||||
} catch (e) {
|
||||
dot.classList.remove("status-online");
|
||||
dot.classList.add("status-offline");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
checkStatus();
|
||||
setInterval(checkStatus, 300000);
|
||||
|
||||
// bolt animation
|
||||
function startBoltAction() {
|
||||
const allBolts = document.querySelectorAll(".bolt, .header-bolt");
|
||||
if (allBolts.length === 0) return;
|
||||
|
||||
const availableBolts = Array.from(allBolts).filter(
|
||||
(bolt) => !bolt.classList.contains("bolt-acting")
|
||||
);
|
||||
|
||||
if (availableBolts.length > 0) {
|
||||
const randomBolt =
|
||||
availableBolts[Math.floor(Math.random() * availableBolts.length)];
|
||||
|
||||
const baseRot =
|
||||
randomBolt.getAttribute("data-rotate") ||
|
||||
randomBolt.style.getPropertyValue("--r") ||
|
||||
"0";
|
||||
|
||||
randomBolt.style.setProperty(
|
||||
"--r",
|
||||
baseRot.toString().replace("deg", "") + "deg"
|
||||
);
|
||||
|
||||
randomBolt.classList.add("bolt-acting");
|
||||
|
||||
setTimeout(() => {
|
||||
randomBolt.classList.remove("bolt-acting");
|
||||
}, 8100);
|
||||
}
|
||||
|
||||
const nextInterval = Math.random() * 4000 + 3000;
|
||||
setTimeout(startBoltAction, nextInterval);
|
||||
}
|
||||
|
||||
window.addEventListener("load", () => {
|
||||
setTimeout(startBoltAction, 2000);
|
||||
});
|
||||
Reference in New Issue
Block a user