<script>
  try {
    const bodyClass = localStorage.getItem('config_body_class');

    if (bodyClass) {
      document.getElementsByTagName("body")[0].className = bodyClass;

      if (bodyClass.includes('night-theme')) {
        document.getElementById('body-styles').innerHTML = '<style><%= Rails.application.assets["themes/night.css"].to_s.squish.html_safe %></style>';
      } else if (bodyClass.includes('ten-x-hacker-theme')) {
        document.getElementById('body-styles').innerHTML = '<style><%= Rails.application.assets["themes/hacker.css"].to_s.squish.html_safe %></style>'
      } else if (bodyClass.includes('pink-theme')) {
        document.getElementById('body-styles').innerHTML = '<style><%= Rails.application.assets["themes/pink.css"].to_s.squish.html_safe %></style>'
      } else if(bodyClass.includes('minimal-light-theme')) {
        document.getElementById('body-styles').innerHTML = '<style><%= Rails.application.assets["themes/minimal.css"].to_s.squish.html_safe %></style>'
      }

      if (bodyClass.includes('open-dyslexic-article-body')) { // Preloading custom font for anticipated use
        const link = document.createElement('link');
        link.as = 'font'
        link.rel = 'preload'
        crossorigin = 'anonymous'
        link.href = '<%= asset_path "OpenDyslexic-Regular.otf" %>';
        document.getElementsByTagName('head')[0].appendChild(link);
      }
    }
    if (navigator.userAgent === 'DEV-Native-ios') {
      document.getElementsByTagName("body")[0].classList.add("dev-ios-native-body");
    }
    if (localStorage.getItem('config_minimize_newest_listings') === 'yes') {
      document.getElementsByTagName("body")[0].classList.add("config_minimize_newest_listings");
    }
    if (window.frameElement) { // Hide top bar and footer when loaded within iframe
      document.getElementsByTagName("body")[0].classList.add("hidden-shell");
    }
  } catch(e) {
      Honeybadger.notify(e);
  }
</script>
