adventskalender/2025/js/background.js hinzugefügt

This commit is contained in:
2025-11-05 21:43:15 +00:00
parent e3c2899987
commit 4f5a6b53d9

View File

@@ -0,0 +1,43 @@
// ============================================================
// Adventskalender 2025 Hintergrundwechsel nach Tag
// ============================================================
(function() {
const pathYear = window.location.pathname.match(/(\d{4})/);
const YEAR = pathYear ? parseInt(pathYear[1], 10) : new Date().getFullYear();
const DEV_MODE = window.location.search.includes("dev");
const STORAGE_BASE = `bratonien_${YEAR}_lock`;
// === Hilfsfunktion: simulierten Tag aus lock.js übernehmen ===
function getSimulatedDay() {
if (!DEV_MODE) return null;
const val = localStorage.getItem(`${STORAGE_BASE}_simday`);
return val ? parseInt(val, 10) : null;
}
// === Aktuellen oder simulierten Tag bestimmen ===
const now = new Date();
let dayToShow = now.getMonth() === 11 ? now.getDate() : 0; // Dezember = 11
// DEV-Override
const sim = getSimulatedDay();
if (DEV_MODE && sim) {
dayToShow = sim;
}
// === Bildpfad bestimmen ===
let imgPath = "assets/picture/Basisbild.png";
if (dayToShow >= 1 && dayToShow <= 24) {
const padded = String(dayToShow).padStart(2, "0");
imgPath = `assets/picture/${padded}.png`;
}
// === Anwendung auf das Kalenderbild ===
window.addEventListener("DOMContentLoaded", () => {
const kalenderBild = document.querySelector(".kalenderbild img");
if (!kalenderBild) return;
kalenderBild.src = imgPath;
console.log(`[Bratonien] Hintergrund gesetzt: ${imgPath}`);
});
})();