1
0
mirror of https://github.com/bitwarden/browser synced 2024-12-27 10:23:48 +01:00
bitwarden-estensione-browser/src/theme.js

23 lines
854 B
JavaScript
Raw Normal View History

// Set theme on page load
// This is done outside the Angular app to avoid a flash of unthemed content before it loads
// The defaultTheme is also set in the html itself to make sure that some theming is always applied
(function () {
const defaultTheme = 'light'
const htmlEl = document.documentElement;
let theme = defaultTheme;
const savedTheme = window.localStorage.getItem('theme');
if (savedTheme != null) {
if (savedTheme.indexOf('system') > -1) {
theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
} else if (savedTheme.indexOf('dark') > -1) {
theme = 'dark';
}
}
if (!htmlEl.classList.contains('theme_' + theme)) {
htmlEl.classList.remove('theme_' + defaultTheme);
htmlEl.classList.add('theme_' + theme);
}
})();