adventskalender/shared/js/lock.js aktualisiert
This commit is contained in:
@@ -21,35 +21,51 @@ function getSimulatedDay() {
|
|||||||
function _checkDoorUnlocked(day) {
|
function _checkDoorUnlocked(day) {
|
||||||
day = parseInt(day, 10);
|
day = parseInt(day, 10);
|
||||||
|
|
||||||
// Manuell entsperrt
|
// Manuell entsperrt?
|
||||||
const forceUnlock = localStorage.getItem(`${STORAGE_BASE}_unlocked`) === "true";
|
const forceUnlock = localStorage.getItem(`${STORAGE_BASE}_unlocked`) === "true";
|
||||||
if (forceUnlock) return true;
|
if (forceUnlock) return true;
|
||||||
|
|
||||||
// Nach dem 24.12. immer offen
|
// Nach dem 24.12. dieses Jahres alles offen
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const after24 =
|
const after24 =
|
||||||
now.getFullYear() > YEAR ||
|
now.getFullYear() > YEAR ||
|
||||||
(now.getFullYear() === YEAR && now.getMonth() === 11 && now.getDate() > 24);
|
(now.getFullYear() === YEAR &&
|
||||||
|
now.getMonth() === 11 &&
|
||||||
|
now.getDate() > 24);
|
||||||
if (after24) return true;
|
if (after24) return true;
|
||||||
|
|
||||||
// Dezember -> bis aktueller Tag
|
// Im Dezember: bis heutigem Tag
|
||||||
if (now.getFullYear() === YEAR && now.getMonth() === 11) {
|
if (now.getFullYear() === YEAR && now.getMonth() === 11) {
|
||||||
return day <= now.getDate();
|
return day <= now.getDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vor Dezember alles zu
|
// Vor Dezember: alles zu
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
// Dev-Konsole
|
// Dev-Konsole bauen
|
||||||
// ============================================================
|
// ============================================================
|
||||||
|
|
||||||
function createDevConsole() {
|
function createDevConsole() {
|
||||||
const panel = document.getElementById("dev-panel");
|
// 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) {
|
if (!panel) {
|
||||||
console.warn("⚠️ Kein #dev-panel gefunden. save-progress.js muss zuerst laden.");
|
panel = document.createElement("div");
|
||||||
return;
|
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");
|
const box = document.createElement("div");
|
||||||
@@ -69,7 +85,7 @@ function createDevConsole() {
|
|||||||
title.style.marginBottom = "6px";
|
title.style.marginBottom = "6px";
|
||||||
box.appendChild(title);
|
box.appendChild(title);
|
||||||
|
|
||||||
// Tag-Buttons
|
// Grid 1–24
|
||||||
const grid = document.createElement("div");
|
const grid = document.createElement("div");
|
||||||
grid.style.cssText = `
|
grid.style.cssText = `
|
||||||
display: grid;
|
display: grid;
|
||||||
@@ -97,9 +113,9 @@ function createDevConsole() {
|
|||||||
}
|
}
|
||||||
box.appendChild(grid);
|
box.appendChild(grid);
|
||||||
|
|
||||||
// Steuer-Buttons
|
// Steuerbuttons
|
||||||
const actions = document.createElement("div");
|
const actions = document.createElement("div");
|
||||||
actions.style.cssText = "display:flex;gap:6px;";
|
actions.style.cssText = `display:flex;gap:6px;`;
|
||||||
|
|
||||||
const unlock = document.createElement("button");
|
const unlock = document.createElement("button");
|
||||||
unlock.textContent = "🚪 Sperre aufheben";
|
unlock.textContent = "🚪 Sperre aufheben";
|
||||||
@@ -145,13 +161,24 @@ function createDevConsole() {
|
|||||||
// Export + Init
|
// Export + Init
|
||||||
// ============================================================
|
// ============================================================
|
||||||
|
|
||||||
|
// von door-open.js aufrufbar
|
||||||
window.isDoorUnlocked = function (day) {
|
window.isDoorUnlocked = function (day) {
|
||||||
if (DEV_MODE) {
|
if (DEV_MODE) {
|
||||||
const sim = getSimulatedDay();
|
const sim = getSimulatedDay();
|
||||||
if (sim !== null) return parseInt(day, 10) <= sim;
|
if (sim !== null) {
|
||||||
|
return parseInt(day, 10) <= sim;
|
||||||
|
}
|
||||||
|
// dev ohne sim: alles offen
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return _checkDoorUnlocked(day);
|
return _checkDoorUnlocked(day);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (DEV_MODE) createDevConsole();
|
// Dev-Konsole erst bauen, wenn DOM fertig ist
|
||||||
|
if (DEV_MODE) {
|
||||||
|
if (document.readyState === "loading") {
|
||||||
|
document.addEventListener("DOMContentLoaded", createDevConsole);
|
||||||
|
} else {
|
||||||
|
createDevConsole();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user