96 lines
2.7 KiB
JavaScript
96 lines
2.7 KiB
JavaScript
/**
|
||
* Bratonien Adventskalender – Fortschritt speichern (shared)
|
||
* ----------------------------------------------------------
|
||
* - speichert geöffnete Türchen (Einzeltüren & Flügeltüren)
|
||
* - stellt Zustand nach Neuladen wieder her
|
||
* - Dev-Modus (?dev): zeigt Reset-Button + gemeinsames Panel für alle Dev-Elemente
|
||
*/
|
||
|
||
(function () {
|
||
const yearMatch = document.title.match(/\d{4}/);
|
||
const year = yearMatch ? yearMatch[0] : new Date().getFullYear();
|
||
const STORAGE_KEY = `bratonien_opened_${year}`;
|
||
|
||
const isDev = window.location.search.includes("dev");
|
||
window.BRATONIEN_DEV = isDev;
|
||
|
||
// === Hilfsfunktionen ===
|
||
function getOpenedDays() {
|
||
try {
|
||
return JSON.parse(localStorage.getItem(STORAGE_KEY)) || [];
|
||
} catch {
|
||
return [];
|
||
}
|
||
}
|
||
|
||
function saveOpenedDays(days) {
|
||
localStorage.setItem(STORAGE_KEY, JSON.stringify([...new Set(days)]));
|
||
}
|
||
|
||
// === Status laden ===
|
||
window.addEventListener("DOMContentLoaded", () => {
|
||
const openedDays = getOpenedDays();
|
||
|
||
openedDays.forEach(day => {
|
||
document.querySelectorAll(`.door[data-day="${day}"]`).forEach(d => d.classList.add("open"));
|
||
const left = document.querySelector(`.fluegel.left[data-day="${day}"]`);
|
||
const right = document.querySelector(`.fluegel.right[data-day="${day}"]`);
|
||
if (left && right) {
|
||
left.classList.add("rota");
|
||
right.classList.add("rota");
|
||
}
|
||
});
|
||
|
||
// === DEV-Bereich ===
|
||
if (isDev) {
|
||
// zentrales Dev-Panel
|
||
let panel = document.getElementById("dev-panel");
|
||
if (!panel) {
|
||
panel = document.createElement("div");
|
||
panel.id = "dev-panel";
|
||
panel.style.cssText = `
|
||
position: fixed;
|
||
bottom: 10px;
|
||
right: 10px;
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: flex-end;
|
||
gap: 10px;
|
||
z-index: 9999;
|
||
`;
|
||
document.body.appendChild(panel);
|
||
}
|
||
|
||
// Reset-Button
|
||
const btn = document.createElement("button");
|
||
btn.textContent = "Reset Kalender";
|
||
btn.style.cssText = `
|
||
padding: 8px 14px;
|
||
border: 2px solid gold;
|
||
border-radius: 10px;
|
||
background: #1a1a1a;
|
||
color: gold;
|
||
cursor: pointer;
|
||
font-family: sans-serif;
|
||
font-size: 14px;
|
||
`;
|
||
btn.addEventListener("click", () => {
|
||
localStorage.removeItem(STORAGE_KEY);
|
||
location.reload();
|
||
});
|
||
|
||
panel.appendChild(btn);
|
||
}
|
||
});
|
||
|
||
// === Status speichern ===
|
||
document.addEventListener("doorOpened", e => {
|
||
const day = e.detail?.day;
|
||
if (!day) return;
|
||
const opened = getOpenedDays();
|
||
if (!opened.includes(day)) {
|
||
opened.push(day);
|
||
saveOpenedDays(opened);
|
||
}
|
||
});
|
||
})(); |