js: allow for multiple environment blocks in HTML

Not that I actually need it, but it's just as easy to load multiple
environment <script>s from the DOM as it is to load one, so we may as
well do that.  Since only one element can have id="environment", we do
this by matching class="environment" as well.
This commit is contained in:
Ben Harris
2023-08-21 22:48:59 +01:00
parent b5367ed18a
commit f97d11df67

View File

@ -85,14 +85,14 @@ var colours = [];
var Module = {
'preRun': function() {
// Merge environment variables from HTML script element.
// Merge environment variables from HTML script elements.
// This means you can add something like this to the HTML:
// <script id="environment" type="application/json">
// { "LOOPY_DEFAULT": "20x10t11dh" }
// </script>
var envscript = document.getElementById("environment");
var k, v;
if (envscript !== null)
var envscript, k, v;
for (envscript of document.querySelectorAll(
"script#environment, script.environment"))
for ([k, v] of
Object.entries(JSON.parse(envscript.textContent)))
ENV[k] = v;