From 84b32b28e9f1da6576e4864a0f374b341a2c9920 Mon Sep 17 00:00:00 2001 From: marudor Date: Thu, 16 May 2019 16:10:53 +0200 Subject: Further color improvements --- templates/layouts/default.html.ep | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'templates/layouts') diff --git a/templates/layouts/default.html.ep b/templates/layouts/default.html.ep index 54f9e1f..a512314 100644 --- a/templates/layouts/default.html.ep +++ b/templates/layouts/default.html.ep @@ -32,8 +32,22 @@ document.head.appendChild(st); } } + var otherTheme = { + 'dark.min': 'light.min', + 'light.min': 'dark.min', +}; +var currentTheme = localStorage.getItem('theme'); +if (!otherTheme.hasOwnProperty(currentTheme)) { + currentTheme = window.matchMedia('(prefers-color-scheme: dark').matches ? 'dark.min' : 'light.min'; +} +addStyleSheet(currentTheme, 'theme'); + +function toggleTheme() { + currentTheme = otherTheme[currentTheme] || 'light.min'; + localStorage.setItem('theme', currentTheme); + addStyleSheet(currentTheme, 'theme'); +} - %= javascript "/static/${av}/js/theme.min.js" -- cgit v1.2.3