184 lines
4.8 KiB
JavaScript
184 lines
4.8 KiB
JavaScript
// ============================================================
|
||
// Bratonien Adventskalender – Türsperren / Dev-Konsole
|
||
// ============================================================
|
||
|
||
// Jahr aus Pfad ableiten (z. B. /2025/)
|
||
const pathYear = window.location.pathname.match(/(\d{4})/);
|
||
const YEAR = pathYear ? parseInt(pathYear[1], 10) : new Date().getFullYear();
|
||
const STORAGE_BASE = `bratonien_${YEAR}_lock`;
|
||
const DEV_MODE = window.location.search.includes("dev");
|
||
|
||
// ============================================================
|
||
// Hilfsfunktionen
|
||
// ============================================================
|
||
|
||
function getSimulatedDay() {
|
||
if (!DEV_MODE) return null;
|
||
const val = localStorage.getItem(`${STORAGE_BASE}_simday`);
|
||
return val ? parseInt(val, 10) : null;
|
||
}
|
||
|
||
function _checkDoorUnlocked(day) {
|
||
day = parseInt(day, 10);
|
||
|
||
// Manuell entsperrt?
|
||
const forceUnlock = localStorage.getItem(`${STORAGE_BASE}_unlocked`) === "true";
|
||
if (forceUnlock) return true;
|
||
|
||
// Nach dem 24.12. dieses Jahres alles offen
|
||
const now = new Date();
|
||
const after24 =
|
||
now.getFullYear() > YEAR ||
|
||
(now.getFullYear() === YEAR &&
|
||
now.getMonth() === 11 &&
|
||
now.getDate() > 24);
|
||
if (after24) return true;
|
||
|
||
// Im Dezember: bis heutigem Tag
|
||
if (now.getFullYear() === YEAR && now.getMonth() === 11) {
|
||
return day <= now.getDate();
|
||
}
|
||
|
||
// Vor Dezember: alles zu
|
||
return false;
|
||
}
|
||
|
||
// ============================================================
|
||
// Dev-Konsole bauen
|
||
// ============================================================
|
||
|
||
function createDevConsole() {
|
||
// versuchen, vorhandenes Panel zu nehmen
|
||
let panel = document.getElementById("dev-panel");
|
||
|
||
// falls save-progress.js noch keins gebaut hat, hier wirklich EINS bauen
|
||
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);
|
||
}
|
||
|
||
const box = document.createElement("div");
|
||
box.className = "dev-console";
|
||
box.style.cssText = `
|
||
background: rgba(0,0,0,0.8);
|
||
color: #f1e1a6;
|
||
border: 1px solid #c8aa49;
|
||
border-radius: 8px;
|
||
padding: 10px;
|
||
max-width: 340px;
|
||
font-family: monospace;
|
||
`;
|
||
|
||
const title = document.createElement("div");
|
||
title.textContent = `DEV ${YEAR}`;
|
||
title.style.marginBottom = "6px";
|
||
box.appendChild(title);
|
||
|
||
// Grid 1–24
|
||
const grid = document.createElement("div");
|
||
grid.style.cssText = `
|
||
display: grid;
|
||
grid-template-columns: repeat(8, minmax(28px, 1fr));
|
||
gap: 4px;
|
||
margin-bottom: 8px;
|
||
`;
|
||
for (let i = 1; i <= 24; i++) {
|
||
const b = document.createElement("button");
|
||
b.textContent = i;
|
||
b.style.cssText = `
|
||
background: #333;
|
||
color: #fff;
|
||
border: 1px solid #666;
|
||
border-radius: 4px;
|
||
cursor: pointer;
|
||
font-size: 11px;
|
||
padding: 3px 0;
|
||
`;
|
||
b.onclick = () => {
|
||
localStorage.setItem(`${STORAGE_BASE}_simday`, String(i));
|
||
location.reload();
|
||
};
|
||
grid.appendChild(b);
|
||
}
|
||
box.appendChild(grid);
|
||
|
||
// Steuerbuttons
|
||
const actions = document.createElement("div");
|
||
actions.style.cssText = `display:flex;gap:6px;`;
|
||
|
||
const unlock = document.createElement("button");
|
||
unlock.textContent = "🚪 Sperre aufheben";
|
||
unlock.style.cssText = `
|
||
background: #2e6f40;
|
||
color: #fff;
|
||
border: none;
|
||
padding: 4px 8px;
|
||
border-radius: 4px;
|
||
cursor: pointer;
|
||
font-size: 11px;
|
||
`;
|
||
unlock.onclick = () => {
|
||
localStorage.setItem(`${STORAGE_BASE}_unlocked`, "true");
|
||
location.reload();
|
||
};
|
||
|
||
const relock = document.createElement("button");
|
||
relock.textContent = "🔒 Alle sperren";
|
||
relock.style.cssText = `
|
||
background: #8b0000;
|
||
color: #fff;
|
||
border: none;
|
||
padding: 4px 8px;
|
||
border-radius: 4px;
|
||
cursor: pointer;
|
||
font-size: 11px;
|
||
`;
|
||
relock.onclick = () => {
|
||
localStorage.removeItem(`${STORAGE_BASE}_unlocked`);
|
||
localStorage.removeItem(`${STORAGE_BASE}_simday`);
|
||
location.reload();
|
||
};
|
||
|
||
actions.appendChild(unlock);
|
||
actions.appendChild(relock);
|
||
box.appendChild(actions);
|
||
|
||
panel.appendChild(box);
|
||
}
|
||
|
||
// ============================================================
|
||
// Export + Init
|
||
// ============================================================
|
||
|
||
// von door-open.js aufrufbar
|
||
window.isDoorUnlocked = function (day) {
|
||
if (DEV_MODE) {
|
||
const sim = getSimulatedDay();
|
||
if (sim !== null) {
|
||
return parseInt(day, 10) <= sim;
|
||
}
|
||
// dev ohne sim: alles offen
|
||
return true;
|
||
}
|
||
return _checkDoorUnlocked(day);
|
||
};
|
||
|
||
// Dev-Konsole erst bauen, wenn DOM fertig ist
|
||
if (DEV_MODE) {
|
||
if (document.readyState === "loading") {
|
||
document.addEventListener("DOMContentLoaded", createDevConsole);
|
||
} else {
|
||
createDevConsole();
|
||
}
|
||
} |