{{ define "repo/fragments/permalinkShortcut" }}
  <script>
    (() => {
      {{ if .LastCommitInfo }}
      const abortController = new AbortController();
      const scriptEl = document.currentScript;
      document.addEventListener('keydown', (e) => {
        if(e.key === 'y' && !e.ctrlKey && !e.metaKey && !e.altKey) {
          if(e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') return;
          const permalinkUrl = '/{{ .RepoInfo.RepoIdentifier }}/tree/{{ .LastCommitInfo.Hash }}/{{ .Path }}' + window.location.hash;
          window.location.href = permalinkUrl;
        }
      }, {signal: abortController.signal});

      document.body.addEventListener('htmx:beforeCleanupElement', (e) => {
        if(e.target === scriptEl) {
          abortController.abort();
        }
      }, {signal: abortController.signal});
      {{ end }}
    })();
  </script>
{{ end }}
