Something went wrong. Try again.
JavaScript generic ASN.1 parser (mirror)
Something went wrong. Try again.
asn1js theme.js
1.3 kB · 37 lines
JavaScript
at github-101
1234567891011121314151617181920212223242526272829303132333435363738// set dark theme depending on OS settingsfunction setTheme(theme) { if (theme == 'os') { let prefersDarkScheme = window.matchMedia('(prefers-color-scheme: dark)'); if (prefersDarkScheme.matches) { theme = 'dark'; } else { theme = 'light'; } } document.documentElement.style['color-scheme'] = theme; document.querySelector('html').setAttribute('data-theme', theme); // set the theme-color for iOS devices let bgColor = getComputedStyle(document.documentElement).getPropertyValue('--main-bg-color'); let metaThemeColor = document.querySelector('meta[name=theme-color]'); metaThemeColor.setAttribute('content', bgColor);}// activate selected themelet theme = 'os';const localStorageTheme = localStorage.getItem('theme');if (localStorageTheme) { theme = localStorageTheme;}setTheme(theme);// add handler to theme selection elementconst selectTheme = document.getElementById('theme-select');if (selectTheme) { selectTheme.addEventListener ('change', function () { localStorage.setItem('theme', selectTheme.value); setTheme(selectTheme.value); }); if (theme == 'light') { selectTheme.selectedIndex = 2; } else if (theme == 'dark') { selectTheme.selectedIndex = 1; }}