109 lines
3.4 KiB
JavaScript
109 lines
3.4 KiB
JavaScript
// ============================================================
|
||
// Bratonien Adventskalender – Türsperren / Dev-Konsole
|
||
// ============================================================
|
||
|
||
// Jahr automatisch aus Ordnernamen ableiten
|
||
const YEAR = window.location.pathname.match(/(\d{4})/)?.[1] || "0000";
|
||
const STORAGE_KEY = `bratonien_lock_${YEAR}`;
|
||
let devMode = window.location.search.includes("?dev");
|
||
|
||
// ===============================
|
||
// Sperrlogik
|
||
// ===============================
|
||
function isDoorUnlocked(day) {
|
||
// Dev-Modus immer alles offen
|
||
if (devMode) return true;
|
||
|
||
// Nach 24.12. immer alles offen
|
||
const now = new Date();
|
||
if (now.getFullYear() > YEAR || (now.getFullYear() == YEAR && now.getMonth() > 11 && now.getDate() > 24))
|
||
return true;
|
||
|
||
// Falls der Benutzer alles entsperrt hat
|
||
if (localStorage.getItem(`${STORAGE_KEY}_unlocked`) === "true")
|
||
return true;
|
||
|
||
// Normale Regel: Türchen <= aktueller Tag freigegeben
|
||
const today = now.getDate();
|
||
return parseInt(day) <= today;
|
||
}
|
||
|
||
// ===============================
|
||
// Dev-Konsole (nur bei ?dev)
|
||
// ===============================
|
||
function createDevConsole() {
|
||
// Prüfen, ob Reset-Button existiert (von save-progress.js)
|
||
let resetBtn = document.getElementById("dev-reset");
|
||
let devBox = document.createElement("div");
|
||
devBox.className = "dev-console";
|
||
devBox.style.cssText = `
|
||
display:flex; flex-wrap:wrap; gap:6px;
|
||
margin:10px 0 0 0; padding:8px;
|
||
background:#111; border:1px solid #c8aa49;
|
||
border-radius:8px; color:#c8aa49; font-family:monospace;
|
||
justify-content:flex-start;
|
||
`;
|
||
|
||
// Sperrbutton
|
||
const lockBtn = document.createElement("button");
|
||
lockBtn.textContent = "🔒 Alle sperren";
|
||
lockBtn.onclick = () => {
|
||
localStorage.removeItem(`${STORAGE_KEY}_unlocked`);
|
||
localStorage.removeItem(`bratonien_opened_${YEAR}`);
|
||
console.log("Alle Türchen gesperrt.");
|
||
location.reload();
|
||
};
|
||
devBox.appendChild(lockBtn);
|
||
|
||
// Tag-Buttons 1–24
|
||
for (let i = 1; i <= 24; i++) {
|
||
const b = document.createElement("button");
|
||
b.textContent = i;
|
||
b.style.minWidth = "32px";
|
||
b.onclick = () => {
|
||
localStorage.setItem(`${STORAGE_KEY}_simulateDay`, i);
|
||
console.log(`Simuliere Tag ${i}`);
|
||
location.reload();
|
||
};
|
||
devBox.appendChild(b);
|
||
}
|
||
|
||
// Sperre aufheben
|
||
const unlockBtn = document.createElement("button");
|
||
unlockBtn.textContent = "🚪 Sperre aufheben";
|
||
unlockBtn.onclick = () => {
|
||
localStorage.setItem(`${STORAGE_KEY}_unlocked`, "true");
|
||
console.log("Alle Türchen entsperrt.");
|
||
location.reload();
|
||
};
|
||
devBox.appendChild(unlockBtn);
|
||
|
||
// Einfügen unterhalb des Reset-Buttons (falls vorhanden)
|
||
if (resetBtn) {
|
||
resetBtn.insertAdjacentElement("afterend", devBox);
|
||
} else {
|
||
document.body.appendChild(devBox);
|
||
}
|
||
}
|
||
|
||
// ===============================
|
||
// Simulationsfunktion (nur Dev)
|
||
// ===============================
|
||
function getSimulatedDay() {
|
||
if (!devMode) return null;
|
||
const simDay = parseInt(localStorage.getItem(`${STORAGE_KEY}_simulateDay`));
|
||
return simDay || null;
|
||
}
|
||
|
||
// ===============================
|
||
// Export (global für andere Skripte)
|
||
// ===============================
|
||
window.isDoorUnlocked = function (day) {
|
||
// Simulation berücksichtigen
|
||
const simDay = getSimulatedDay();
|
||
if (devMode && simDay) return parseInt(day) <= simDay;
|
||
return isDoorUnlocked(day);
|
||
};
|
||
|
||
// Dev-Konsole aktivieren
|
||
if (devMode) createDevConsole(); |