2018-09-19 17:56:47 -06:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Puzzle</title>
|
|
|
|
<link rel="stylesheet" href="basic.css">
|
|
|
|
<meta name="viewport" content="width=device-width">
|
2018-10-02 19:21:54 -06:00
|
|
|
<meta charset="utf-8">
|
2018-10-09 18:05:58 -06:00
|
|
|
<script src="devel.js"></script>
|
2018-09-19 17:56:47 -06:00
|
|
|
<script>
|
|
|
|
function init() {
|
|
|
|
let params = new URLSearchParams(window.location.search);
|
|
|
|
let categoryName = params.get("cat");
|
|
|
|
let points = params.get("points");
|
|
|
|
let puzzleId = params.get("pid");
|
|
|
|
|
2018-10-10 16:56:15 -06:00
|
|
|
let puzzle = document.getElementById("puzzle");
|
2018-09-21 14:42:38 -06:00
|
|
|
let base = "content/" + categoryName + "/" + puzzleId + "/";
|
2018-09-19 17:56:47 -06:00
|
|
|
|
2018-10-10 16:56:15 -06:00
|
|
|
fetch(base + "puzzle.json")
|
|
|
|
.then(resp => {
|
2018-10-02 09:22:09 -06:00
|
|
|
return resp.json();
|
2018-10-10 16:56:15 -06:00
|
|
|
})
|
|
|
|
.then(obj => {
|
|
|
|
// Populate authors
|
2018-09-21 17:45:28 -06:00
|
|
|
document.getElementById("authors").textContent = obj.authors.join(", ");
|
2018-10-10 16:56:15 -06:00
|
|
|
|
|
|
|
// If answers are provided, this is the devel server
|
2018-10-02 19:21:54 -06:00
|
|
|
if (obj.answers) {
|
2018-10-09 18:05:58 -06:00
|
|
|
devel_addin(obj, document.getElementById("devel"));
|
|
|
|
}
|
2018-10-10 16:56:15 -06:00
|
|
|
|
|
|
|
// Load scripts
|
2018-10-09 18:05:58 -06:00
|
|
|
for (let script of obj.scripts) {
|
|
|
|
let st = document.createElement("script");
|
|
|
|
document.head.appendChild(st);
|
|
|
|
st.src = base + script;
|
2018-10-02 19:21:54 -06:00
|
|
|
|
|
|
|
}
|
2018-10-10 16:56:15 -06:00
|
|
|
|
|
|
|
// List associated files
|
2018-09-21 17:45:28 -06:00
|
|
|
for (let fn of obj.files) {
|
|
|
|
let li = document.createElement("li");
|
|
|
|
let a = document.createElement("a");
|
|
|
|
a.href = base + fn;
|
|
|
|
a.innerText = fn;
|
|
|
|
li.appendChild(a);
|
|
|
|
document.getElementById("files").appendChild(li);
|
|
|
|
}
|
2018-10-10 14:23:36 -06:00
|
|
|
|
|
|
|
// Prefix `base` to relative URLs in the puzzle body
|
|
|
|
let doc = new DOMParser().parseFromString(obj.body, "text/html");
|
2018-10-10 14:59:55 -06:00
|
|
|
for (let se of doc.querySelectorAll("[src],[href]")) {
|
2018-10-10 14:23:36 -06:00
|
|
|
se.outerHTML = se.outerHTML.replace(/(src|href)="([^/]+)"/i, "$1=\"" + base + "$2\"");
|
|
|
|
}
|
|
|
|
|
2018-10-10 16:56:15 -06:00
|
|
|
// Replace puzzle children with what's in `doc`
|
|
|
|
Array.from(puzzle.childNodes).map(e => e.remove());
|
|
|
|
Array.from(doc.body.childNodes).map(e => puzzle.appendChild(e));
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
// Show error to the user
|
|
|
|
Array.from(puzzle.childNodes).map(e => e.remove());
|
|
|
|
let p = document.createElement("p");
|
|
|
|
puzzle.appendChild(p);
|
|
|
|
p.classList.add("Error");
|
|
|
|
p.textContent = err;
|
2018-10-02 09:22:09 -06:00
|
|
|
});
|
|
|
|
|
2018-10-10 16:56:15 -06:00
|
|
|
document.title = categoryName + " " + points;
|
|
|
|
document.querySelector("body > h1").innerText = document.title;
|
2018-10-02 09:22:09 -06:00
|
|
|
document.querySelector("input[name=cat]").value = categoryName;
|
|
|
|
document.querySelector("input[name=points]").value = points;
|
2018-09-19 17:56:47 -06:00
|
|
|
}
|
2018-10-10 16:56:15 -06:00
|
|
|
if (document.readyState === "loading") {
|
|
|
|
document.addEventListener("DOMContentLoaded", init);
|
|
|
|
} else {
|
|
|
|
init();
|
|
|
|
}
|
2018-09-19 17:56:47 -06:00
|
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h1>Puzzle</h1>
|
|
|
|
<section>
|
2018-09-21 17:45:28 -06:00
|
|
|
<div id="puzzle">Loading...</div>
|
|
|
|
<ul id="files"></ul>
|
|
|
|
<p>Puzzle by <span id="authors"></span></p>
|
2018-09-19 17:56:47 -06:00
|
|
|
</section>
|
2018-10-02 09:22:09 -06:00
|
|
|
<form action="answer" method="post">
|
|
|
|
<input type="hidden" name="cat">
|
|
|
|
<input type="hidden" name="points">
|
2018-10-09 18:05:58 -06:00
|
|
|
Team ID: <input type="text" name="id"> <br>
|
|
|
|
Answer: <input type="text" name="answer" id="answer"> <br>
|
2018-10-02 09:22:09 -06:00
|
|
|
<input type="submit" value="Submit">
|
|
|
|
</form>
|
2018-10-09 18:05:58 -06:00
|
|
|
<div id="devel"></div>
|
2018-09-19 17:56:47 -06:00
|
|
|
<nav>
|
|
|
|
<ul>
|
|
|
|
<li><a href="puzzle-list.html">Puzzles</a></li>
|
|
|
|
<li><a href="scoreboard.html">Scoreboard</a></li>
|
|
|
|
</ul>
|
|
|
|
</nav>
|
|
|
|
</body>
|
|
|
|
</html>
|