2026-01-16 02:30:44 +01:00
|
|
|
const API_URL = "https://api.splatcord.ink/prod/s1rotations";
|
|
|
|
|
|
|
|
|
|
function stageNames(stages, lang = "en-US") {
|
|
|
|
|
return stages.map(s => s.translatedNames[lang]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function stageImagePath(stageName) {
|
|
|
|
|
const firstWord = stageName
|
|
|
|
|
.split(" ")[0]
|
|
|
|
|
.toLowerCase()
|
|
|
|
|
.replace(/['.]/g, "");
|
|
|
|
|
|
2026-01-17 22:19:07 +01:00
|
|
|
return `/assets/stages/${firstWord}.png`;
|
2026-01-16 02:30:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function fetchRotations() {
|
2026-01-16 21:59:39 +01:00
|
|
|
try {
|
|
|
|
|
const res = await fetch(API_URL);
|
|
|
|
|
if (!res.ok) throw new Error(`HTTP error! status: ${res.status}`);
|
|
|
|
|
const data = await res.json();
|
2026-01-16 02:30:44 +01:00
|
|
|
|
2026-01-16 21:59:39 +01:00
|
|
|
const rotations = data?.pretendo?.rotations ?? {};
|
|
|
|
|
const now = new Date();
|
2026-01-16 02:30:44 +01:00
|
|
|
|
2026-01-16 21:59:39 +01:00
|
|
|
const timestamps = Object.keys(rotations).sort(
|
|
|
|
|
(a, b) => Number(a) - Number(b)
|
|
|
|
|
);
|
2026-01-16 02:30:44 +01:00
|
|
|
|
2026-01-16 21:59:39 +01:00
|
|
|
for (const ts of timestamps) {
|
|
|
|
|
const start = new Date(Number(ts));
|
|
|
|
|
const end = new Date(start.getTime() + 2 * 60 * 60 * 1000);
|
2026-01-16 02:30:44 +01:00
|
|
|
|
2026-01-16 21:59:39 +01:00
|
|
|
if (end < now) continue;
|
2026-01-16 02:30:44 +01:00
|
|
|
|
2026-01-16 21:59:39 +01:00
|
|
|
const r = rotations[ts];
|
2026-01-16 02:30:44 +01:00
|
|
|
|
2026-01-16 21:59:39 +01:00
|
|
|
return [{
|
|
|
|
|
turf: stageNames(r.turfStages).map(stageImagePath),
|
|
|
|
|
ranked: stageNames(r.rankedStages).map(stageImagePath),
|
|
|
|
|
ranked_mode: r.rankedMode?.translatedNames?.["en-US"] ?? "Ranked"
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [];
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Failed to fetch rotations:", error);
|
|
|
|
|
return [];
|
2026-01-16 02:30:44 +01:00
|
|
|
}
|
2026-01-16 21:59:39 +01:00
|
|
|
}
|
2026-01-16 02:30:44 +01:00
|
|
|
|
2026-01-16 21:59:39 +01:00
|
|
|
function animateLoadingCanvas() {
|
|
|
|
|
const canvas = document.getElementById("loading-canvas");
|
|
|
|
|
const loadingOverlay = document.getElementById("loading-overlay");
|
|
|
|
|
if (!canvas || !loadingOverlay) return;
|
|
|
|
|
|
|
|
|
|
const ctx = canvas.getContext("2d");
|
|
|
|
|
const image = new Image();
|
|
|
|
|
image.src = "/assets/loading.png";
|
|
|
|
|
|
|
|
|
|
const frameWidth = 100;
|
|
|
|
|
const frameHeight = 100;
|
|
|
|
|
const totalFrames = 17;
|
|
|
|
|
|
|
|
|
|
let currentFrame = 0;
|
|
|
|
|
let lastUpdateTime = 0;
|
2026-01-17 00:12:37 +01:00
|
|
|
const frameDuration = 50;
|
2026-01-16 21:59:39 +01:00
|
|
|
|
|
|
|
|
let animationId;
|
|
|
|
|
|
|
|
|
|
image.onload = () => {
|
|
|
|
|
function animate(timestamp = 0) {
|
|
|
|
|
if (loadingOverlay.style.display === "none") {
|
|
|
|
|
cancelAnimationFrame(animationId);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!lastUpdateTime) lastUpdateTime = timestamp;
|
|
|
|
|
const elapsed = timestamp - lastUpdateTime;
|
|
|
|
|
|
|
|
|
|
if (elapsed > frameDuration) {
|
|
|
|
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
|
|
|
ctx.drawImage(
|
|
|
|
|
image,
|
|
|
|
|
0, currentFrame * frameHeight,
|
|
|
|
|
frameWidth, frameHeight,
|
|
|
|
|
0, 0,
|
|
|
|
|
frameWidth, frameHeight
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
currentFrame = (currentFrame + 1) % totalFrames;
|
|
|
|
|
lastUpdateTime = timestamp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
animationId = requestAnimationFrame(animate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
animationId = requestAnimationFrame(animate);
|
|
|
|
|
};
|
2026-01-16 02:30:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function renderStages() {
|
2026-01-16 21:59:39 +01:00
|
|
|
const loadingOverlay = document.getElementById("loading-overlay");
|
2026-01-16 02:30:44 +01:00
|
|
|
const container = document.getElementById("stages-container");
|
2026-01-16 21:59:39 +01:00
|
|
|
|
|
|
|
|
let rotations = [];
|
|
|
|
|
try {
|
|
|
|
|
rotations = await fetchRotations();
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error("Error in renderStages:", err);
|
|
|
|
|
} finally {
|
|
|
|
|
loadingOverlay.style.display = "none"; // always hide loading
|
|
|
|
|
}
|
2026-01-16 02:30:44 +01:00
|
|
|
|
|
|
|
|
if (!rotations.length) {
|
2026-01-16 21:59:39 +01:00
|
|
|
container.innerHTML = `
|
|
|
|
|
<h2 class="error-message">
|
|
|
|
|
Something went wrong! Try reloading the page. If this problem persists you may be ratelimited.
|
|
|
|
|
</h2>
|
2026-01-17 00:12:37 +01:00
|
|
|
`;
|
2026-01-16 21:59:39 +01:00
|
|
|
|
2026-01-16 02:30:44 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const rotation of rotations) {
|
|
|
|
|
container.innerHTML += `
|
|
|
|
|
<div class="stages-section">
|
|
|
|
|
<h2>Turf War</h2>
|
|
|
|
|
<div class="stages">
|
|
|
|
|
${rotation.turf.map(img =>
|
|
|
|
|
`<img src="${img}" alt="Turf Stage">`
|
|
|
|
|
).join("")}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="stages-section">
|
|
|
|
|
<h2>Ranked Battle (${rotation.ranked_mode})</h2>
|
|
|
|
|
<div class="stages">
|
|
|
|
|
${rotation.ranked.map(img =>
|
|
|
|
|
`<img src="${img}" alt="Ranked Stage">`
|
|
|
|
|
).join("")}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
`;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-17 00:12:37 +01:00
|
|
|
animateLoadingCanvas();
|
2026-01-16 02:30:44 +01:00
|
|
|
renderStages();
|