gitea

Development moved to Codeberg

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
<script>
	// synchronously set clone button states and urls here to avoid flickering
	// on page load. initRepoCloneLink calls this when proto changes.
	// this applies the protocol-dependant clone url to all elements with the
	// `js-clone-url` and `js-clone-url-vsc` classes.
	// TODO: This localStorage setting should be moved to backend user config
	// so it's available during rendering, then this inline script can be removed.
	(window.updateCloneStates = function() {
		const httpsBtn = document.getElementById('repo-clone-https');
		const sshBtn = document.getElementById('repo-clone-ssh');
		const value = localStorage.getItem('repo-clone-protocol') || 'https';
		const isSSH = value === 'ssh' && sshBtn || value !== 'ssh' && !httpsBtn;

		if (httpsBtn) httpsBtn.classList[!isSSH ? 'add' : 'remove']('primary');
		if (sshBtn) sshBtn.classList[isSSH ? 'add' : 'remove']('primary');

		const btn = isSSH ? sshBtn : httpsBtn;
		if (!btn) return;

		const link = btn.getAttribute('data-link');
		for (const el of document.getElementsByClassName('js-clone-url')) {
			el[el.nodeName === 'INPUT' ? 'value' : 'textContent'] = link;
		}
		for (const el of document.getElementsByClassName('js-clone-url-vsc')) {
			el['href'] = 'vscode://vscode.git/clone?url=' + encodeURIComponent(link);
		}
	})();
</script>