gammatools/web/index.html

156 lines
6.2 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="assets/css/styles.css">
<title>Gamma World Gaming Tools</title>
<script src="/assets/js/config.js"></script>
</head>
<body>
<div style="text-align: center">
<h1>Gamma World Gaming Tools</h1>
</div>
<div id="probability-panel" style="text-align: center; margin: 3px">
<button id="dieroller">Dice</button>
<button id="coinflip">Flip Coin</button>
<button id="chance">Roll Chance</button>
</div>
<div id="gameplay-panel" style="text-align: center; margin: 3px">
<button id="encounter">Encounters</button>
<button id="abcheck">Ability Check</button>
<button id="physicalattack">Physical Attack!</button>
<button id="mentalattack">Mental Attack!</button>
</div>
<div id="gameref-panel" style="text-align: center; margin: 3px">
<button id="chargen">Characters</button>
<button id="tables">Tables</button>
<button id="bestiary">Bestiary</button>
</div>
<hr/>
<div id="toolPanel"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
loadContent("pages/intro.html");
document.getElementById("bestiary").addEventListener("click", function () {
loadContent("pages/bestiary.html?t=" + new Date().getTime());
});
document.getElementById("abcheck").addEventListener("click", function () {
loadContent("pages/ability_check.html?t=" + new Date().getTime());
});
document.getElementById("tables").addEventListener("click", function () {
loadContent("pages/display_tables.html?t=" + new Date().getTime());
});
document.getElementById("dieroller").addEventListener("click", function () {
loadContent("pages/rolldice.html?t=" + new Date().getTime());
});
document.getElementById("encounter").addEventListener("click", function () {
loadContent("pages/encounter.html?t=" + new Date().getTime());
});
document.getElementById("mentalattack").addEventListener("click", function () {
loadContent("pages/mentalattack.html?t=" + new Date().getTime());
});
document.getElementById("physicalattack").addEventListener("click", function () {
loadContent("pages/physicalattack.html?t=" + new Date().getTime());
});
document.getElementById("chargen").addEventListener("click", function () {
loadContent("pages/chargen.html?t=" + new Date().getTime());
});
document.getElementById("coinflip").addEventListener("click", function () {
let commonImgSize = '250px'
// Display a placeholder image or loading indicator
let imgElement = document.createElement('img');
imgElement.src = `${window.IMG}/loading.gif`;
imgElement.style.width = commonImgSize;
imgElement.style.height = commonImgSize;
// Center the image
imgElement.style.display = 'block';
imgElement.style.marginLeft = 'auto';
imgElement.style.marginRight = 'auto';
document.getElementById('toolPanel').innerHTML = '';
document.getElementById('toolPanel').appendChild(imgElement);
fetch(`${window.BASE_URL}/coinflip`)
.then(response => response.text())
.then(data => {
let imgSrc = `${window.IMG}/` + data.replace(/\"/g, '') + '.jpg';
setTimeout(() => {
imgElement.src = imgSrc;
}, 1500);
})
.catch((error) => {
console.error('Error:', error);
});
});
document.getElementById('chance').addEventListener('click', function(event) {
event.preventDefault();
// Insert the odds.gif before making the fetch request
let resultSection = document.getElementById('toolPanel');
resultSection.innerHTML = '';
let imgElement = document.createElement('img');
imgElement.src = `${window.IMG}/odds.gif`;
imgElement.style.width = '250px';
imgElement.style.height = '250px';
imgElement.style.display = 'block';
imgElement.style.marginLeft = 'auto';
imgElement.style.marginRight = 'auto';
resultSection.appendChild(imgElement);
fetch(`${window.BASE_URL}/dice/probability`)
.then((response) => {
if (!response.ok) {
throw response;
}
return response.json();
})
.then((json) => {
// Add a delay of 1 second (1000 milliseconds) before changing the image.
setTimeout(() => {
// Remove loading gif from HTML
imgElement.style.display = 'none';
// Show the result with %+ in large bold centered text
let resultText = document.createElement('p');
resultText.style.fontSize = '32px'; // Large text
resultText.style.fontWeight = 'bold'; // Bold text
resultText.style.textAlign = 'center'; // Centered text
resultText.textContent = json.result + '%'; // Append % to the result value
resultSection.appendChild(resultText);
}, 1000);
})
.catch((err) => {
console.log('Request failed', err);
});
});
});
function loadContent(pageUrl) {
var iframe = document.createElement('iframe');
iframe.src = pageUrl;
iframe.style.width = '100%'; // make the iframe take full width of the container
iframe.style.border = 'none'; // hide the border
iframe.style.overflow = 'hidden'; // hide scrollbars, can be 'auto' if you prefer automatic scrollbars
iframe.style.height = '1800px'; // set a height so that the iframe is visible, adjust as per your needs
document.getElementById("toolPanel").innerHTML = '';
document.getElementById("toolPanel").appendChild(iframe);
}
</script>
</body>
</html>