Move dark mode script to site.js
This commit is contained in:
parent
ea43893d4a
commit
c3bf9b61dd
2 changed files with 17 additions and 14 deletions
|
@ -39,18 +39,5 @@
|
|||
|
||||
{{ block "scripts" . }}{{ end }}
|
||||
|
||||
<script>
|
||||
const bodyClasses = document.body.classList;
|
||||
const systemDarkModeMatch = window.matchMedia('(prefers-color-scheme: dark)');
|
||||
const localStorageDarkMode = localStorage.getItem('dark');
|
||||
|
||||
const setDark = isDark => {
|
||||
bodyClasses[isDark ? 'add' : 'remove']('dark');
|
||||
localStorage.setItem('dark', isDark ? 'yes' : 'no');
|
||||
};
|
||||
|
||||
setDark(localStorageDarkMode ? localStorageDarkMode === 'yes' : systemDarkModeMatch.matches);
|
||||
requestAnimationFrame(() => bodyClasses.remove('not-ready'));
|
||||
systemDarkModeMatch.addEventListener('change', (event) => setDark(event.matches));
|
||||
</script>
|
||||
<script src="{{ `scripts/site.js` | absURL }}"></script>
|
||||
</html>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue