mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2026-01-28 21:31:00 +03:00
22 lines
766 B
Plaintext
22 lines
766 B
Plaintext
---
|
|
---
|
|
|
|
<script is:inline>
|
|
const getThemePreference = () => {
|
|
if (typeof localStorage !== 'undefined' && localStorage.getItem('theme')) {
|
|
return localStorage.getItem('theme');
|
|
}
|
|
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
};
|
|
const isDark = getThemePreference() === 'dark';
|
|
document.documentElement.classList[isDark ? 'add' : 'remove']('dark');
|
|
|
|
if (typeof localStorage !== 'undefined') {
|
|
const observer = new MutationObserver(() => {
|
|
const isDark = document.documentElement.classList.contains('dark');
|
|
localStorage.setItem('theme', isDark ? 'dark' : 'light');
|
|
});
|
|
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
|
|
}
|
|
</script>
|