From 8880e00f48173b8a90df62f58c5cc200265dfe47 Mon Sep 17 00:00:00 2001 From: Thomas Miceli <27960254+thomiceli@users.noreply.github.com> Date: Thu, 1 Jun 2023 19:04:12 +0200 Subject: [PATCH] Fix dark mode flickering (#44) --- public/main.ts | 23 ++++------------------- templates/base/base_header.html | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/public/main.ts b/public/main.ts index 7255cd1..d0e9e2b 100644 --- a/public/main.ts +++ b/public/main.ts @@ -6,26 +6,10 @@ import moment from 'moment'; import md from 'markdown-it'; import hljs from 'highlight.js'; + document.addEventListener('DOMContentLoaded', () => { - const themeMenu = document.getElementById('theme-menu')!; - const checkTheme = () => { - if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) { - document.documentElement.classList.add('dark') - } else { - document.documentElement.classList.remove('dark') - } - } - - checkTheme() - - window.matchMedia('(prefers-color-scheme: dark)') - .addEventListener('change',({ matches }) => { - checkTheme() - } - ) - document.getElementById('light-mode')!.onclick = (e) => { e.stopPropagation() localStorage.theme = 'light'; @@ -81,9 +65,10 @@ document.addEventListener('DOMContentLoaded', () => { if (lang && hljs.getLanguage(lang)) { try { return '
' +
- hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
+ hljs.highlight(str, {language: lang, ignoreIllegals: true}).value +
'
';
- } catch (__) {}
+ } catch (__) {
+ }
}
return '' + md().utils.escapeHtml(str) + '
';
diff --git a/templates/base/base_header.html b/templates/base/base_header.html
index b0a67dc..39a62e3 100644
--- a/templates/base/base_header.html
+++ b/templates/base/base_header.html
@@ -3,6 +3,24 @@
+