Skip to content

Commit e211dfa

Browse files
authored
WebHost: use JS to refresh waitSeed if scripting is enabled (#4843)
1 parent 0f7deb1 commit e211dfa

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

WebHostLib/templates/waitSeed.html

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
{% block head %}
66
<title>Generation in Progress</title>
7-
<meta http-equiv="refresh" content="1">
7+
<noscript>
8+
<meta http-equiv="refresh" content="1">
9+
</noscript>
810
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename="styles/waitSeed.css") }}"/>
911
{% endblock %}
1012

@@ -16,4 +18,34 @@ <h1>Generation in Progress</h1>
1618
Waiting for game to generate, this page auto-refreshes to check.
1719
</div>
1820
</div>
21+
<script>
22+
const waitSeedDiv = document.getElementById("wait-seed");
23+
async function checkStatus() {
24+
try {
25+
const response = await fetch("{{ url_for('api.wait_seed_api', seed=seed_id) }}");
26+
if (response.status !== 202) {
27+
// Seed is ready; reload page to load seed page.
28+
location.reload();
29+
return;
30+
}
31+
32+
const data = await response.json();
33+
waitSeedDiv.innerHTML = `
34+
<h1>Generation in Progress</h1>
35+
<p>${data.text}</p>
36+
`;
37+
38+
setTimeout(checkStatus, 1000); // Continue polling.
39+
} catch (error) {
40+
waitSeedDiv.innerHTML = `
41+
<h1>Progress Unknown</h1>
42+
<p>${error.message}<br />(Last checked: ${new Date().toLocaleTimeString()})</p>
43+
`;
44+
45+
setTimeout(checkStatus, 1000);
46+
}
47+
}
48+
49+
setTimeout(checkStatus, 1000);
50+
</script>
1951
{% endblock %}

0 commit comments

Comments
 (0)