mirror of
https://github.com/welpo/tabi.git
synced 2025-10-10 23:38:53 +02:00
💡 chore: add comments
This commit is contained in:
parent
92e6af1d58
commit
a4e48b48fd
1 changed files with 8 additions and 0 deletions
|
@ -1,9 +1,17 @@
|
||||||
(function () {
|
(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');
|
const currentTheme = localStorage.getItem('theme');
|
||||||
|
|
||||||
|
// Check if the current theme is stored in local storage.
|
||||||
if (currentTheme) {
|
if (currentTheme) {
|
||||||
|
// If a theme is found in local storage, apply it to the document.
|
||||||
document.documentElement.setAttribute('data-theme', currentTheme);
|
document.documentElement.setAttribute('data-theme', currentTheme);
|
||||||
} else {
|
} 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;
|
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');
|
document.documentElement.setAttribute('data-theme', isSystemDark ? 'dark' : 'light');
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue