From 022e666c3fccc4e489c880e6d44198c9a4895c1c Mon Sep 17 00:00:00 2001 From: rxxbyy Date: Wed, 25 Feb 2026 15:03:20 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Fix=20Typer=20logo=20light/dark?= =?UTF-8?q?=20theme=20for=20GitHub=20and=20MkDocs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/js/custom.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/docs/en/docs/js/custom.js b/docs/en/docs/js/custom.js index c71e49d29f..1be26ddfdd 100644 --- a/docs/en/docs/js/custom.js +++ b/docs/en/docs/js/custom.js @@ -175,17 +175,28 @@ function handleSponsorImages() { } function setupThemeImages() { - new MutationObserver(() => { + const updateImages = () => { const scheme = document.body.getAttribute("data-md-color-scheme"); const isDark = scheme === "slate"; document.querySelectorAll("picture[data-light-src][data-dark-src]").forEach((picture) => { - const src = isDark ? picture.dataset.darkSrc : picture.dataset.lightSrc; + const src = (isDark ? picture.dataset.darkSrc : picture.dataset.lightSrc); const source = picture.querySelector("source"); const img = picture.querySelector("img"); - if (source) source.srcset = src; - if (img) img.src = src; + if (source) { + source.srcset = src; + } + if (img) { + img.src = src; + } }); - }).observe(document.body, { attributes: true, attributeFilter: ["data-md-color-scheme"] }); + } + + new MutationObserver(updateImages).observe(document.body, { + attributes: true, + attributeFilter: ["data-md-color-scheme"], + }); + + updateImages(); } async function main() {