mirror of
https://github.com/netz39/www.netz39.de.git
synced 2025-01-31 09:33:18 +01:00
Merge pull request #59 from netz39/auto-darkmode
Make auto darkmode working by using "prefers-color-scheme" tag
This commit is contained in:
commit
0df7b9dd96
1 changed files with 12 additions and 3 deletions
|
@ -6,12 +6,21 @@
|
|||
{% if site.color_theme == 'auto' %}
|
||||
<script>
|
||||
const isAutoTheme = true;
|
||||
document.documentElement.setAttribute('data-theme', sessionStorage.getItem('theme'))
|
||||
const prefersDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
const storedTheme = localStorage.getItem('theme');
|
||||
|
||||
if (storedTheme) {
|
||||
document.documentElement.setAttribute('data-theme', storedTheme);
|
||||
} else if (prefersDarkMode) {
|
||||
document.documentElement.setAttribute('data-theme', 'dark');
|
||||
} else {
|
||||
document.documentElement.setAttribute('data-theme', 'light');
|
||||
}
|
||||
</script>
|
||||
{% else %}
|
||||
<script>
|
||||
const isAutoTheme = false;
|
||||
document.documentElement.setAttribute('data-theme', "{{ site.color_theme | default: 'light' }}")
|
||||
document.documentElement.setAttribute('data-theme', "{{ site.color_theme | default: 'light' }}");
|
||||
</script>
|
||||
{% endif %}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue