♻️ [#676] Further optimise appearance.js to reduce code duplication

This commit is contained in:
Daniel Odrinski 2023-05-02 21:16:16 +01:00
parent c6869834ea
commit a660482b24

View file

@ -26,20 +26,19 @@ window.addEventListener("DOMContentLoaded", (event) => {
const switcher = document.getElementById("appearance-switcher");
const switcherMobile = document.getElementById("appearance-switcher-mobile");
var targetAppearance = document.documentElement.classList.contains("dark") ? "dark" : "light"
updateMeta()
this.updateLogo?.(targetAppearance)
updateMeta();
this.updateLogo?.(getTargetAppearance());
if (switcher) {
switcher.addEventListener("click", () => {
document.documentElement.classList.toggle("dark");
var targetAppearance = document.documentElement.classList.contains("dark") ? "dark" : "light"
var targetAppearance = getTargetAppearance();
localStorage.setItem(
"appearance",
targetAppearance
);
updateMeta()
this.updateLogo?.(targetAppearance)
updateMeta();
this.updateLogo?.(targetAppearance);
});
switcher.addEventListener("contextmenu", (event) => {
event.preventDefault();
@ -49,13 +48,13 @@ window.addEventListener("DOMContentLoaded", (event) => {
if (switcherMobile) {
switcherMobile.addEventListener("click", () => {
document.documentElement.classList.toggle("dark");
var targetAppearance = document.documentElement.classList.contains("dark") ? "dark" : "light"
var targetAppearance = getTargetAppearance();
localStorage.setItem(
"appearance",
targetAppearance
);
updateMeta()
this.updateLogo?.(targetAppearance)
updateMeta();
this.updateLogo?.(targetAppearance);
});
switcherMobile.addEventListener("contextmenu", (event) => {
event.preventDefault();
@ -88,3 +87,7 @@ var updateLogo = (targetAppearance) => {
}
{{ end }}
{{- end }}
var getTargetAppearance = () => {
return document.documentElement.classList.contains("dark") ? "dark" : "light"
}