2024-06-28 18:10:35 +00:00
|
|
|
window.onload = function () {
|
|
|
|
document.getElementById('diceForm').addEventListener('submit', function (event) {
|
2024-07-01 13:24:27 +00:00
|
|
|
event.preventDefault(); // Prevent the form from submitting via the default form action
|
2024-06-28 18:10:35 +00:00
|
|
|
|
|
|
|
const quantity = parseInt(document.getElementById('quantity').value, 10);
|
|
|
|
const geometry = parseInt(document.getElementById('geometry').value, 10);
|
|
|
|
const discard = document.getElementById('discard').checked;
|
|
|
|
|
2024-07-01 13:24:27 +00:00
|
|
|
const queryParams = new URLSearchParams({
|
|
|
|
quantity: quantity,
|
|
|
|
geometry: geometry,
|
|
|
|
discard_lowest: discard
|
|
|
|
});
|
|
|
|
|
2024-07-01 15:03:40 +00:00
|
|
|
fetch(`${window.BASE_URL}/dice?${queryParams}`)
|
2024-06-28 18:10:35 +00:00
|
|
|
.then(response => response.json())
|
|
|
|
.then(data => {
|
|
|
|
const resultsDiv = document.getElementById('results');
|
|
|
|
let html = '';
|
|
|
|
if (data['dice-set']) {
|
|
|
|
let diceSet = data['dice-set'];
|
|
|
|
html += '<p><h3>Dice Set:</h3></p>';
|
|
|
|
html += `<ul>
|
2024-07-01 13:24:27 +00:00
|
|
|
<li>Mnemonic: ${diceSet['mnemonic']}</li>
|
|
|
|
<li>Min Roll: ${diceSet['min-roll']}</li>
|
|
|
|
<li>Max Roll: ${diceSet['max-roll']}</li>
|
|
|
|
</ul>`;
|
2024-06-28 18:10:35 +00:00
|
|
|
}
|
|
|
|
if (data['rolls'] && quantity > 1) {
|
|
|
|
html += `<p><h3>Rolls: </h3>${data['rolls'].join(', ')}</p>`;
|
|
|
|
}
|
|
|
|
if (data['discarded']) {
|
|
|
|
html += `<p><h3>Discarded:</h3>${data['discarded']}</p>`;
|
|
|
|
}
|
|
|
|
if (data['result']) {
|
|
|
|
html += `<p><h3>Result: </h3><h2>${data['result']}</h2></p>`;
|
|
|
|
}
|
|
|
|
resultsDiv.innerHTML = html;
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.error('Error:', error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|