asciidoctor / asciidoctor-browser-extension

:white_circle: An extension for web browsers that converts AsciiDoc files to HTML using Asciidoctor.js.
https://chrome.google.com/webstore/detail/asciidoctorjs-live-previe/iaalpfgpbocpdfblpnhhgllgbdbchmia
MIT License
220 stars 50 forks source link

Add a button to remove custom style sheet #531

Closed marieflorescontact closed 3 years ago

ggrossetie commented 3 years ago

Our linter (https://standardjs.com/) is unhappy. Could you please run npm run lint -- --fix? It should fix all the lint issues. You can then run npm run lint to make sure that every issue has been fixed. Thanks!

ggrossetie commented 3 years ago

Nice, the build is now green 👍🏻 The last step is to add an event listener on the removeCustomStyleSheet element to actually remove the custom theme:

untested code

removeCustomStyleSheet.onclick = () => {
  if (selectTheme.selectedOptions) {
    // make sure that a custom theme is selected (i.e., the theme is _not_ in the "Default" option group)
    if (selectTheme.selectedOptions[0].parentNode.label !== 'Default') {
      const themeName = selectTheme.value
      // remove the theme from the custom theme names list (saved in the local storage as an array)
      const customThemeNames = JSON.parse(localStorage.CUSTOM_THEME_NAMES || '[]')
      const customThemeFoundIndex = customThemeNames.indexOf(themeName)
      if (customThemeFoundIndex > -1) {
        customThemeNames.splice(customThemeFoundIndex, 1)
        localStorage.CUSTOM_THEME_NAMES = JSON.stringify(customThemeNames)
      }
      // remove stylesheet content
      localStorage.removeItem('CUSTOM_THEME_' + themeName)
      // remove the selected option
      selectTheme.selectedOptions[0].remove()
    }
  }
}
ggrossetie commented 3 years ago

Merci 🙇🏻