2022-08-01 02:29:55 +08:00
|
|
|
<script>
|
|
|
|
// synchronously set clone button states and urls here to avoid flickering
|
|
|
|
// on page load. initRepoCloneLink calls this when proto changes.
|
2022-09-09 14:38:51 +08:00
|
|
|
// this applies the protocol-dependant clone url to all elements with the
|
|
|
|
// `js-clone-url` and `js-clone-url-vsc` classes.
|
2022-08-01 02:29:55 +08:00
|
|
|
// 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;
|
|
|
|
|
2023-02-09 17:29:13 +08:00
|
|
|
let link = btn.getAttribute('data-link');
|
|
|
|
if (link.startsWith('http://') || link.startsWith('https://')) {
|
|
|
|
// use current protocol/host as the clone link
|
|
|
|
const url = new URL(link);
|
|
|
|
url.protocol = window.location.protocol;
|
|
|
|
url.host = window.location.host;
|
|
|
|
link = url.toString();
|
|
|
|
}
|
2022-08-01 02:29:55 +08:00
|
|
|
for (const el of document.getElementsByClassName('js-clone-url')) {
|
|
|
|
el[el.nodeName === 'INPUT' ? 'value' : 'textContent'] = link;
|
|
|
|
}
|
2022-09-09 14:38:51 +08:00
|
|
|
for (const el of document.getElementsByClassName('js-clone-url-vsc')) {
|
|
|
|
el['href'] = 'vscode://vscode.git/clone?url=' + encodeURIComponent(link);
|
|
|
|
}
|
2022-08-01 02:29:55 +08:00
|
|
|
})();
|
|
|
|
</script>
|