diff --git a/index.html b/index.html index 5f05197..3948294 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,6 @@ - ASN.1 JavaScript decoder @@ -109,6 +108,7 @@

Links

+ diff --git a/index.js b/index.js index 4456a9a..ed36cdc 100644 --- a/index.js +++ b/index.js @@ -15,7 +15,6 @@ const area = id('area'), file = id('file'), examples = id('examples'), - selectTheme = id('theme-select'), selectDefs = id('definitions'), selectTag = id('tags'); @@ -158,42 +157,6 @@ for (const [name, onClick] of Object.entries(butClickHandlers)) { if (elem) elem.onclick = onClick; } -// set dark theme depending on OS settings -function setTheme(theme) { - if (!selectTheme) { - console.log('Themes are currently not working with single file version.'); - return; - } - 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) -} -// activate selected theme -let theme = 'os'; -const localStorageTheme = localStorage.getItem('theme'); -if (localStorageTheme) { - theme = localStorageTheme; -} -if (theme == 'light') { - selectTheme.selectedIndex = 2; -} else if (theme == 'dark') { - selectTheme.selectedIndex = 1; -} -setTheme(theme); -// add handler to theme selction element -if (selectTheme) { - selectTheme.addEventListener ('change', function () { - localStorage.setItem('theme', selectTheme.value); - setTheme(selectTheme.value); - }); -} // this is only used if window.FileReader function read(f) { area.value = ''; // clear text area, will get b64 content diff --git a/theme.js b/theme.js new file mode 100644 index 0000000..8e84711 --- /dev/null +++ b/theme.js @@ -0,0 +1,37 @@ +const selectTheme = document.getElementById('theme-select') +// set dark theme depending on OS settings +function setTheme(theme) { +if (!selectTheme) { + console.log('Themes are currently not working with single file version.'); + return; +} +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) +} +// activate selected theme +let theme = 'os'; +const localStorageTheme = localStorage.getItem('theme'); +if (localStorageTheme) { +theme = localStorageTheme; +} +if (theme == 'light') { +selectTheme.selectedIndex = 2; +} else if (theme == 'dark') { +selectTheme.selectedIndex = 1; +} +setTheme(theme); +// add handler to theme selction element +if (selectTheme) { +selectTheme.addEventListener ('change', function () { + localStorage.setItem('theme', selectTheme.value); + setTheme(selectTheme.value); +}); +} \ No newline at end of file