Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions downloads.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,47 @@ function option(string $value, string $desc, $attributes = []): string
<?php endif; ?>

<script>
let currentController = null;

window.onload = function () {
let form = document.getElementById("instructions-form")
const form = document.getElementById("instructions-form")
const instructions = document.getElementById("instructions")

form.addEventListener('change', function () {
form.submit();
if (currentController) {
currentController.abort();
}

currentController = new AbortController();

const params = new URLSearchParams(new FormData(form)).toString()

fetch(form.action + '?' + params, {signal: currentController.signal})
.then(response => response.text())
.then(html => {
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');

const newForm = doc.querySelector('#instructions-form');
const newInstructions = doc.querySelector('#instructions');

if (newForm) form.innerHTML = newForm.innerHTML;
if (newInstructions) instructions.innerHTML = newInstructions.innerHTML;

if (window.Prism && typeof Prism.highlightAll === 'function') {
Prism.highlightAll();
}

const newUrl = form.action.split('?')[0] + '?' + params;
history.pushState(null, '', newUrl);
Comment thread
shivammathur marked this conversation as resolved.
Outdated
})
.catch(err => {
if (err.name === 'AbortError') {
return
}

console.error('Request failed:', err);
})
});
}
</script>
Expand Down