38 lines
No EOL
1.2 KiB
HTML
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 }} |