mirror of
https://github.com/MarioSpore/Grinch-AP.git
synced 2025-10-21 04:01:32 -06:00
WebHost: use JS to refresh waitSeed if scripting is enabled (#4843)
This commit is contained in:
@@ -4,7 +4,9 @@
|
||||
|
||||
{% block head %}
|
||||
<title>Generation in Progress</title>
|
||||
<meta http-equiv="refresh" content="1">
|
||||
<noscript>
|
||||
<meta http-equiv="refresh" content="1">
|
||||
</noscript>
|
||||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename="styles/waitSeed.css") }}"/>
|
||||
{% endblock %}
|
||||
|
||||
@@ -16,4 +18,34 @@
|
||||
Waiting for game to generate, this page auto-refreshes to check.
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
const waitSeedDiv = document.getElementById("wait-seed");
|
||||
async function checkStatus() {
|
||||
try {
|
||||
const response = await fetch("{{ url_for('api.wait_seed_api', seed=seed_id) }}");
|
||||
if (response.status !== 202) {
|
||||
// Seed is ready; reload page to load seed page.
|
||||
location.reload();
|
||||
return;
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
waitSeedDiv.innerHTML = `
|
||||
<h1>Generation in Progress</h1>
|
||||
<p>${data.text}</p>
|
||||
`;
|
||||
|
||||
setTimeout(checkStatus, 1000); // Continue polling.
|
||||
} catch (error) {
|
||||
waitSeedDiv.innerHTML = `
|
||||
<h1>Progress Unknown</h1>
|
||||
<p>${error.message}<br />(Last checked: ${new Date().toLocaleTimeString()})</p>
|
||||
`;
|
||||
|
||||
setTimeout(checkStatus, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(checkStatus, 1000);
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
Reference in New Issue
Block a user