travelynx/public/static/js/theme.js

13 lines
476 B
JavaScript
Raw Normal View History

2019-05-16 13:22:47 +00:00
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');
}