adventskalender/2025/js/background.js aktualisiert
This commit is contained in:
@@ -19,16 +19,11 @@
|
|||||||
const sim = getSimulatedDay();
|
const sim = getSimulatedDay();
|
||||||
if (DEV_MODE && sim) dayToShow = sim;
|
if (DEV_MODE && sim) dayToShow = sim;
|
||||||
|
|
||||||
let padded = "Basisbild";
|
const padded = (dayToShow >= 1 && dayToShow <= 24) ? String(dayToShow).padStart(2, "0") : "Basisbild";
|
||||||
if (dayToShow >= 1 && dayToShow <= 24) {
|
const filename = padded;
|
||||||
padded = String(dayToShow).padStart(2, "0");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Basename ohne Extension
|
|
||||||
const filename = `${padded}`;
|
|
||||||
const basePath = "assets/images/";
|
const basePath = "assets/images/";
|
||||||
|
|
||||||
// === Funktion zum Setzen des Favicons (.webp reicht völlig aus) ===
|
// === Favicon setzen (.webp) ===
|
||||||
function setFavicon(path) {
|
function setFavicon(path) {
|
||||||
let link = document.querySelector('link[rel="icon"]');
|
let link = document.querySelector('link[rel="icon"]');
|
||||||
if (!link) {
|
if (!link) {
|
||||||
@@ -47,27 +42,28 @@
|
|||||||
|
|
||||||
if (!picture || !img || !sources) return;
|
if (!picture || !img || !sources) return;
|
||||||
|
|
||||||
// Durch alle <source> durchgehen und neuen srcset setzen
|
const breakpoints = [420, 768, 1024, 1280, 1600, 1920, 2560, 3840];
|
||||||
|
|
||||||
|
// === <source> für AVIF und WebP aktualisieren ===
|
||||||
sources.forEach(source => {
|
sources.forEach(source => {
|
||||||
const type = source.getAttribute("type");
|
const type = source.getAttribute("type");
|
||||||
const format = type?.split("/")[1]; // "avif" oder "webp"
|
const format = type?.split("/")[1]; // "avif" oder "webp"
|
||||||
if (!format) return;
|
if (!format) return;
|
||||||
|
|
||||||
const newSrcset = [
|
const newSrcset = breakpoints
|
||||||
`assets/images/420/${format}/${filename}.${format} 420w`,
|
.map(bp => `assets/images/${bp}/${format}/${filename}.${format} ${bp}w`)
|
||||||
`assets/images/768/${format}/${filename}.${format} 768w`,
|
.join(", ");
|
||||||
`assets/images/1024/${format}/${filename}.${format} 1024w`,
|
|
||||||
`assets/images/1280/${format}/${filename}.${format} 1280w`,
|
|
||||||
`assets/images/1600/${format}/${filename}.${format} 1600w`,
|
|
||||||
`assets/images/1920/${format}/${filename}.${format} 1920w`,
|
|
||||||
`assets/images/2560/${format}/${filename}.${format} 2560w`,
|
|
||||||
`assets/images/3840/${format}/${filename}.${format} 3840w`,
|
|
||||||
].join(", ");
|
|
||||||
source.setAttribute("srcset", newSrcset);
|
source.setAttribute("srcset", newSrcset);
|
||||||
});
|
});
|
||||||
|
|
||||||
// JPEG für <img>-Fallback
|
// === <img> (JPEG-Fallback) responsiv setzen ===
|
||||||
img.src = `assets/images/1920/jpeg/${filename}.jpg`;
|
const jpegSrcset = breakpoints
|
||||||
|
.map(bp => `assets/images/${bp}/jpeg/${filename}.jpg ${bp}w`)
|
||||||
|
.join(", ");
|
||||||
|
|
||||||
|
img.setAttribute("src", `assets/images/1920/jpeg/${filename}.jpg`);
|
||||||
|
img.setAttribute("srcset", jpegSrcset);
|
||||||
|
img.setAttribute("sizes", "100vw");
|
||||||
|
|
||||||
console.log(`[Bratonien] Kalenderbild gesetzt für Tag ${filename}`);
|
console.log(`[Bratonien] Kalenderbild gesetzt für Tag ${filename}`);
|
||||||
setFavicon(`${basePath}${filename}.webp`);
|
setFavicon(`${basePath}${filename}.webp`);
|
||||||
|
|||||||
Reference in New Issue
Block a user