<script id="pjax-script" src="<%= url_for('js/libs/pjax.min.js') %>"></script>
<script>
  (function () {
    const isGoogleTranslate = location.hostname.includes('.translate.goog')

    if (isGoogleTranslate) {
      document.getElementById('pjax-script')?.remove()
      return
    }

    function initPjax () {
      if (window.pjax) return

      window.pjax = new Pjax({
        selectors: [
          'head title',
          '.page-container',
          '.pjax'
        ],
        history: true,
        debug: false,
        cacheBust: false,
        timeout: 0,
        analytics: false,
        currentUrlFullReload: false,
        scrollRestoration: false
      })

      document.addEventListener('pjax:send', onPjaxSend)
      document.addEventListener('pjax:complete', onPjaxComplete)
    }

    function onPjaxSend () {
      KEEP?.utils?.pjaxProgressBarStart()
    }

    function onPjaxComplete () {
      KEEP?.utils?.pjaxProgressBarEnd()

      window?.pjax?.executeScripts(
        document.querySelectorAll('script[data-pjax], .pjax script')
      )

      KEEP?.initExecute()
    }

    // DOM Ready
    if (document.readyState === 'loading') {
      document.addEventListener('DOMContentLoaded', initPjax)
    } else {
      initPjax()
    }
  })()
</script>
