Fixed theme switcher
This commit is contained in:
@ -11,6 +11,7 @@
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
|
||||
|
||||
<script src="/js/handleColorMode.js"></script>
|
||||
<script src="/js/normalizeToast.js"></script>
|
||||
<script src="/static/jquery/dist/jquery.min.js"></script>
|
||||
<script src="/js/toastHandler.js"></script>
|
||||
@ -20,29 +21,7 @@
|
||||
<script src="/static/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="/static/@popperjs/core/dist/umd/popper.min.js"></script>
|
||||
<script src="/static/tsparticles-confetti/tsparticles.confetti.bundle.min.js"></script>
|
||||
<script>
|
||||
// Listen for changes in the prefers-color-scheme media query and update the "data-bs-theme" attribute on the <html> element.
|
||||
(function () {
|
||||
const currentTheme = localStorage.getItem('bs.theme') ?? 'auto';
|
||||
const isDark = currentTheme === 'dark';
|
||||
const isLight = currentTheme === 'light';
|
||||
|
||||
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
const prefersLight = window.matchMedia('(prefers-color-scheme: light)').matches;
|
||||
|
||||
if (currentTheme === 'auto') {
|
||||
if (prefersDark) {
|
||||
document.documentElement.setAttribute('data-bs-theme', 'dark');
|
||||
} else if (prefersLight) {
|
||||
document.documentElement.setAttribute('data-bs-theme', 'light');
|
||||
}
|
||||
} else if (isDark) {
|
||||
document.documentElement.setAttribute('data-bs-theme', 'dark');
|
||||
} else if (isLight) {
|
||||
document.documentElement.setAttribute('data-bs-theme', 'light');
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<!-- The body and html tag need to be left open! -->
|
||||
|
Reference in New Issue
Block a user