mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-20 15:41:30 -07:00
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:
@ -85,14 +85,14 @@ var colours = [];
|
|||||||
|
|
||||||
var Module = {
|
var Module = {
|
||||||
'preRun': function() {
|
'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:
|
// This means you can add something like this to the HTML:
|
||||||
// <script id="environment" type="application/json">
|
// <script id="environment" type="application/json">
|
||||||
// { "LOOPY_DEFAULT": "20x10t11dh" }
|
// { "LOOPY_DEFAULT": "20x10t11dh" }
|
||||||
// </script>
|
// </script>
|
||||||
var envscript = document.getElementById("environment");
|
var envscript, k, v;
|
||||||
var k, v;
|
for (envscript of document.querySelectorAll(
|
||||||
if (envscript !== null)
|
"script#environment, script.environment"))
|
||||||
for ([k, v] of
|
for ([k, v] of
|
||||||
Object.entries(JSON.parse(envscript.textContent)))
|
Object.entries(JSON.parse(envscript.textContent)))
|
||||||
ENV[k] = v;
|
ENV[k] = v;
|
||||||
|
Reference in New Issue
Block a user