travelynx/public/static/js/theme.js
2019-05-16 15:22:47 +02:00

12 lines
476 B
JavaScript

var validThemes = ['dark.min', 'light.min'];
var currentTheme = localStorage.getItem('theme');
if (!validThemes.includes(currentTheme)) {
currentTheme = window.matchMedia('(prefers-color-scheme: dark').matches ? 'dark.min' : 'light.min';
}
addStyleSheet(currentTheme, 'theme');
function toggleTheme() {
currentTheme = currentTheme === 'dark.min' ? 'light.min' : 'dark.min';
localStorage.setItem('theme', currentTheme);
addStyleSheet(currentTheme, 'theme');
}