function initSelectTheme () {
  Array.from(document.getElementsByClassName('color-theme-select')).forEach(themeSelect => {
    // Get the current theme
    const currentTheme = document.body.getAttribute('theme')
    // Set the selected Index
    for (let j = 0; j < themeSelect.options.length; j++) {
      const i = themeSelect.options[j]
      if (i.value === currentTheme) {
        themeSelect.selectedIndex = j
        break
      }
    }

    themeSelect.addEventListener('change', () => {
      const theme = themeSelect.value
      window.localStorage && localStorage.setItem('theme', theme)
      if (theme !== 'auto') {
        setColorTheme(theme)
      } else {
        if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
          setColorTheme('dark')
        } else {
          setColorTheme('light')
        }
      }
      for (const event of window.switchThemeEventSet) event()
    })
  })
}
/**
 * Initialize the select theme button.
 */
Initialize the select theme button.
Initialize the select theme button .
function initSelectTheme () {
  Array.from(document.getElementsByClassName('color-theme-select')).forEach(themeSelect => {
    const currentTheme = document.body.getAttribute('theme')
    for (let j = 0; j < themeSelect.options.length; j++) {
      const i = themeSelect.options[j]
      if (i.value === currentTheme) {
        themeSelect.selectedIndex = j
        break
      }
    }
    themeSelect.addEventListener('change', () => {
      const theme = themeSelect.value
      window.localStorage && localStorage.setItem('theme', theme)
      if (theme !== 'auto') {
        setColorTheme(theme)
      } else {
        if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
          setColorTheme('dark')
        } else {
          setColorTheme('light')
        }
      }
      for (const event of window.switchThemeEventSet) event()
    })
  })
}
function initSelectTheme ( ) { Array . from ( document . getElementsByClassName ( 'color-theme-select' ) ) . forEach ( themeSelect => { const currentTheme = document . body . getAttribute ( 'theme' ) for ( let j = 0 ; j < themeSelect . options . length ; j ++ ) { const i = themeSelect . options [ j ] if ( i . value === currentTheme ) { themeSelect . selectedIndex = j break } } themeSelect . addEventListener ( 'change' , ( ) => { const theme = themeSelect . value window . localStorage && localStorage . setItem ( 'theme' , theme ) if ( theme !== 'auto' ) { setColorTheme ( theme ) } else { if ( window . matchMedia && window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches ) { setColorTheme ( 'dark' ) } else { setColorTheme ( 'light' ) } } for ( const event of window . switchThemeEventSet ) event ( ) } ) } ) }
Initialize the select theme button.
Initialize the select theme button .
// Get the current theme // Set the selected Index