diff --git a/adventskalender/2025/js/popup.js b/adventskalender/2025/js/popup.js index 63d745c..e438bbb 100644 --- a/adventskalender/2025/js/popup.js +++ b/adventskalender/2025/js/popup.js @@ -61,14 +61,14 @@ window.openPopup = openPopup; // ============================================================ -// Ergänzung: Gesperrte Türchen – Popup mit Zufallsspruch + Zeitangabe +// Ergänzung: Gesperrte Türchen – Popup mit Zufallsspruch + Countdown-Angabe // ============================================================ window.showLockedPopup = function (day) { const sprueche = [ "🎁 Na na na, hier wird nicht geschummelt!", "❄️ Geduld ist auch eine Form von Magie.", - "🎅 Ho ho ho – zu früh! Versuch es später nochmal.", + "🎅 Ho ho ho – zu früh! Versuch’s später nochmal.", "⏳ Die Tür klemmt noch – vielleicht morgen?", "🍪 Kein Plätzchen für Ungeduldige!", "🎄 Schön, dass du neugierig bist – aber noch ist Geheimniszeit!", @@ -83,15 +83,25 @@ window.showLockedPopup = function (day) { const yearMatch = document.title.match(/\d{4}/); const year = yearMatch ? parseInt(yearMatch[0], 10) : new Date().getFullYear(); const unlockDate = new Date(year, 11, parseInt(day, 10), 0, 0, 0); // 11 = Dezember + const now = new Date(); - // hübsches deutsches Datum - const options = { day: "2-digit", month: "long", year: "numeric", hour: "2-digit", minute: "2-digit" }; - const dateText = unlockDate.toLocaleString("de-DE", options).replace(" um", ","); + let diff = unlockDate - now; + if (diff < 0) diff = 0; + + const totalMinutes = Math.floor(diff / 60000); + const days = Math.floor(totalMinutes / (60 * 24)); + const hours = Math.floor((totalMinutes % (60 * 24)) / 60); + const minutes = totalMinutes % 60; + + let timeText = ""; + if (days > 0) timeText += `${days} Tag${days !== 1 ? "en" : ""}`; + if (hours > 0) timeText += `${timeText ? ", " : ""}${hours} Stunde${hours !== 1 ? "n" : ""}`; + if (minutes > 0 || timeText === "") timeText += `${timeText ? " und " : ""}${minutes} Minute${minutes !== 1 ? "n" : ""}`; popupContent.innerHTML = `
${zufall}
-🔓 Öffnet sich am ${dateText}
+🔓 Öffnet in ${timeText}
`; popupOverlay.classList.add("active");