web-apps/apps/common/mobile/utils/htmlutils.js
2022-01-28 11:32:57 +03:00

10 lines
435 B
JavaScript

let obj = !localStorage ? {id: 'theme-light', type: 'light'} : JSON.parse(localStorage.getItem("ui-theme"));
if ( !obj ) {
obj = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ?
{id: 'theme-dark', type: 'dark'} : {id: 'theme-light', type: 'light'};
localStorage && localStorage.setItem("ui-theme", JSON.stringify(obj));
}
document.body.classList.add(`theme-type-${obj.type}`);