From a4e48b48fdc010bc22dfa41d00baaab317e7733c Mon Sep 17 00:00:00 2001 From: welpo Date: Wed, 2 Aug 2023 23:52:28 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A1=20chore:=20add=20comments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/js/initializeTheme.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/static/js/initializeTheme.js b/static/js/initializeTheme.js index 45ba7f6..5c8a96c 100644 --- a/static/js/initializeTheme.js +++ b/static/js/initializeTheme.js @@ -1,9 +1,17 @@ (function () { + // Get the current theme from the browser's local storage. + // This allows the user's theme preference to persist across sessions. const currentTheme = localStorage.getItem('theme'); + + // Check if the current theme is stored in local storage. if (currentTheme) { + // If a theme is found in local storage, apply it to the document. document.documentElement.setAttribute('data-theme', currentTheme); } else { + // If no theme is found in local storage, determine if the user's system prefers a dark color scheme. const isSystemDark = window.matchMedia('(prefers-color-scheme: dark)').matches; + + // Set the document's theme attribute to match the system preference. document.documentElement.setAttribute('data-theme', isSystemDark ? 'dark' : 'light'); } })();