webseite/layouts/_partials/scripts.html
Jannik Menzel 2264cd53b5
All checks were successful
publish / publish (push) Successful in 26s
added details and pop-up to event calendar
2025-06-20 17:26:03 +02:00

38 lines
No EOL
1.2 KiB
HTML

<!-- Darkmode JS -->
<script>
(function () {
try {
const stored = localStorage.getItem("theme");
const systemPrefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
const isDark = stored ? stored === "dark" : systemPrefersDark;
if (isDark) {
document.documentElement.classList.add("dark");
}
} catch (e) {
// ignore errors
}
})();
</script>
<!-- Localization Auto Redirect -->
{{ if .IsHome }}
<script>
const cachedLang = localStorage.getItem("language");
const path = window.location.pathname;
if (cachedLang) {
if (cachedLang === "de" && path !== "/") {
window.location.href = "/";
} else if (cachedLang === "en" && path !== "/en/") {
window.location.href = "/en/";
}
} else {
const lang = navigator.language;
if (lang.startsWith("de")) {
localStorage.setItem("language", "de");
} else {
localStorage.setItem("language", "en");
}
}
</script>
{{ end }}