From 729b4a2d59ff8314850c9fec67c8e80cc809e567 Mon Sep 17 00:00:00 2001 From: Bratonien Cosplay Date: Mon, 10 Nov 2025 14:34:40 +0100 Subject: [PATCH] Day01 Fehlerbehebung --- adventskalender/2025/content/day01.html | 14 +++--- adventskalender/2025/js/background.js | 57 ++++++++++++++++++++++--- adventskalender/2025/js/popup.js | 29 ++++++++++--- 3 files changed, 81 insertions(+), 19 deletions(-) diff --git a/adventskalender/2025/content/day01.html b/adventskalender/2025/content/day01.html index 7e39d73..3e12831 100644 --- a/adventskalender/2025/content/day01.html +++ b/adventskalender/2025/content/day01.html @@ -2,10 +2,10 @@

🎁 Türchen 01

- + + + + @@ -87,9 +87,9 @@ - + \ No newline at end of file diff --git a/adventskalender/2025/js/background.js b/adventskalender/2025/js/background.js index 68dc1a8..49a2200 100644 --- a/adventskalender/2025/js/background.js +++ b/adventskalender/2025/js/background.js @@ -19,9 +19,10 @@ const sim = getSimulatedDay(); if (DEV_MODE && sim) dayToShow = sim; - const padded = (dayToShow >= 1 && dayToShow <= 24) - ? String(dayToShow).padStart(2, "0") - : "Basisbild"; + const padded = + dayToShow >= 1 && dayToShow <= 24 + ? String(dayToShow).padStart(2, "0") + : "Basisbild"; const filename = padded; const basePath = `/${YEAR}/assets/images/`; @@ -50,23 +51,67 @@ if (!picture || !img || !sources) return; + // === Daumenkino (nur für Tag 1) === + if (dayToShow === 1) { + const thumbkino = document.querySelector(".thumbkino-video"); + if (thumbkino) { + const formats = ["webm", "mp4"]; + const resolutions = [ + "nHD", + "FWVGA", + "qHD", + "HD", + "HDplus", + "FullHD", + "1440p", + "4K", + ]; + const breakpoints = [640, 854, 960, 1280, 1600, 1920, 2560, 3840]; + + // alte Quellen entfernen + while (thumbkino.firstChild) thumbkino.removeChild(thumbkino.firstChild); + + formats.forEach((format) => { + resolutions.forEach((res, i) => { + const mediaQuery = + i === resolutions.length - 1 + ? "(min-width: 2561px)" + : `(max-width: ${breakpoints[i]}px)`; + + const source = document.createElement("source"); + source.src = `/${YEAR}/assets/videos/${res}/${format}/${padded}.${format}`; + source.type = `video/${format}`; + source.media = mediaQuery; + thumbkino.appendChild(source); + }); + }); + + thumbkino.load(); + thumbkino.play().catch(() => {}); + + console.log(`[Bratonien] Daumenkino gesetzt für Tag ${padded}`); + } + } + const breakpoints = [420, 768, 1024, 1366, 1600, 1920, 2560, 3840]; // === für AVIF und WebP aktualisieren === - sources.forEach(source => { + sources.forEach((source) => { const type = source.getAttribute("type"); const format = type?.split("/")[1]; // "avif" oder "webp" if (!format) return; const newSrcset = breakpoints - .map(bp => `${basePath}${bp}/${format}/${filename}.${format} ${bp}w`) + .map( + (bp) => `${basePath}${bp}/${format}/${filename}.${format} ${bp}w` + ) .join(", "); source.setAttribute("srcset", newSrcset); }); // === (JPEG-Fallback) === const jpegSrcset = breakpoints - .map(bp => `${basePath}${bp}/jpeg/${filename}.jpeg ${bp}w`) + .map((bp) => `${basePath}${bp}/jpeg/${filename}.jpeg ${bp}w`) .join(", "); img.setAttribute("src", `${basePath}1920/jpeg/${filename}.jpeg`); diff --git a/adventskalender/2025/js/popup.js b/adventskalender/2025/js/popup.js index 5a3608d..019a681 100644 --- a/adventskalender/2025/js/popup.js +++ b/adventskalender/2025/js/popup.js @@ -5,6 +5,8 @@ const popupBox = document.getElementById("popup-box"); const popupContent = document.getElementById("popup-content"); const popupClose = document.getElementById("popup-close"); +let activeSound = null; // aktuell laufender Hintergrundsound + // === Platzhalterfunktion === function placeholder(text) { return ` @@ -65,9 +67,9 @@ function openPopup(day) { setTimeout(() => { try { // --- Soundeffekt FallingSnow --- - const sound = new Audio("/2025/assets/sounds/FallingSnow.mp3"); - sound.volume = 0.5; - sound.play().catch(() => {}); + activeSound = new Audio("/2025/assets/sounds/FallingSnow.mp3"); + activeSound.volume = 0.5; + activeSound.play().catch(() => {}); // --- Daumenkino-Video (Fallback-Start) --- const thumbkino = popupContent.querySelector(".thumbkino-video"); @@ -114,7 +116,7 @@ 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 unlockDate = new Date(year, 11, parseInt(day, 10), 0, 0, 0); const now = new Date(); let diff = unlockDate - now; @@ -140,9 +142,24 @@ window.showLockedPopup = function (day) { }; // === Schließen === -popupClose.addEventListener("click", () => popupOverlay.classList.remove("active")); +popupClose.addEventListener("click", () => { + popupOverlay.classList.remove("active"); + if (activeSound) { + activeSound.pause(); + activeSound.currentTime = 0; + activeSound = null; + } +}); + popupOverlay.addEventListener("click", e => { - if (e.target === popupOverlay) popupOverlay.classList.remove("active"); + if (e.target === popupOverlay) { + popupOverlay.classList.remove("active"); + if (activeSound) { + activeSound.pause(); + activeSound.currentTime = 0; + activeSound = null; + } + } }); // === Export für door-open.js ===