//
// FILE: 07_javascript.js
// Description: the javascript code that will be added to the website
document.addEventListener('DOMContentLoaded', function() {
var commitInfoModal = document.getElementById('commitInfoModal');
if (commitInfoModal) {
commitInfoModal.addEventListener('show.bs.modal', function (event) {
var button = event.relatedTarget;
var hash = button.getAttribute('data-commit-hash');
var modalBody = document.getElementById('commitModalBody');
modalBody.innerHTML = `
`;
fetch('get_commit_info.php?hash=' + encodeURIComponent(hash))
.then(resp => resp.text())
.then(html => { modalBody.innerHTML = html; })
.catch(() => {
modalBody.innerHTML = 'Failed to load commit info.
';
});
});
}
});
document.addEventListener('DOMContentLoaded', function () {
const usernameInput = document.querySelector('input[name="username"]');
const repoInput = document.querySelector('input[name="repo"]');
const hashInput = document.querySelector('input[name="hash"]');
const urlPreview = document.getElementById('github_url_zip');
function updateUrl() {
const username = usernameInput.value.trim() || 'USERNAME';
const repo = repoInput.value.trim() || 'REPO';
const hash = hashInput.value.trim() || 'HASH';
const url = `https://github.com/${username}/${repo}/archive/${hash}.zip`;
urlPreview.innerHTML = `${url}`;
}
[usernameInput, repoInput, hashInput].forEach(input => {
input.addEventListener('input', updateUrl);
});
updateUrl(); // Run once on load
});