flex/pelican/themes/Flex/static/dark-theme/dark-theme.min.js

1 line
No EOL
965 B
JavaScript

function ThemeManager(e){var t=e.defaultTheme,r="true"===e.enableAutoDetectTheme.toLowerCase(),a=window.matchMedia("light"===t?"(prefers-color-scheme: dark)":"(prefers-color-scheme: dark), (prefers-color-scheme: no-preference)");function d(e,t){e=document.getElementById(e);e.disabled=!t,e.media=""}function m(){var e=localStorage.getItem("themeOverride");d("dark-theme-style","dark"===(e="light"!==e&&"dark"!==e?"browser"===e||r?a.matches?"dark":"light":t:e)),d("pygments-dark-theme","dark"===e),d("pygments-light-theme","light"===e),"dark"===e?(document.body.classList.add("dark-theme"),document.body.classList.remove("light-theme")):(document.body.classList.add("light-theme"),document.body.classList.remove("dark-theme"))}this.switch=function(e){localStorage.setItem("themeOverride",e),m()};e=localStorage.getItem("themeOverride");"light"!==e&&"dark"!==e||m(),a.addListener(m)}window.theme=new ThemeManager(document.getElementById("dark-theme-script").dataset);