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-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-09-21 14:42:38 -06:00
|
|
|
let base = "content/" + categoryName + "/" + puzzleId + "/";
|
|
|
|
let fn = base + "puzzle.json";
|
2018-09-19 17:56:47 -06:00
|
|
|
|
2018-10-02 09:22:09 -06:00
|
|
|
fetch(fn)
|
|
|
|
.then(function(resp) {
|
|
|
|
return resp.json();
|
|
|
|
}).then(function(obj) {
|
2018-09-21 17:45:28 -06:00
|
|
|
document.getElementById("authors").textContent = obj.authors.join(", ");
|
2018-10-02 19:21:54 -06:00
|
|
|
if (obj.answers) {
|
|
|
|
let oldans = document.querySelector("[name=answer]");
|
|
|
|
let ans = document.createElement("select");
|
|
|
|
oldans.parentNode.replaceChild(ans, oldans);
|
|
|
|
for (let a of obj.answers) {
|
|
|
|
let opt = document.createElement("option");
|
|
|
|
ans.appendChild(opt);
|
|
|
|
opt.innerText = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById("idtxt").innerText = "Summary/Hint:"
|
|
|
|
|
|
|
|
let id = document.querySelector("[name=id]");
|
|
|
|
id.disabled = true;
|
|
|
|
id.value = "❖ " + (obj.summary || obj.hint);
|
|
|
|
id.title = "This will be hidden to participants";
|
|
|
|
|
|
|
|
document.querySelector("[type=Submit]").disabled = true;
|
|
|
|
}
|
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-02 09:22:09 -06:00
|
|
|
document.getElementById("puzzle").innerHTML = obj.body;
|
|
|
|
}).catch(function(err) {
|
|
|
|
console.log("Error", err);
|
|
|
|
});
|
|
|
|
|
|
|
|
document.querySelector("body > h1").innerText = categoryName + " " + points
|
|
|
|
document.querySelector("input[name=cat]").value = categoryName;
|
|
|
|
document.querySelector("input[name=points]").value = points;
|
|
|
|
|
2018-09-21 17:45:28 -06:00
|
|
|
function mutated(mutationsList, observer) {
|
|
|
|
for (let mutation of mutationsList) {
|
|
|
|
if (mutation.type == 'childList') {
|
|
|
|
for (let e of mutation.addedNodes) {
|
2018-10-02 09:22:09 -06:00
|
|
|
//console.log(e);
|
|
|
|
if (! e.querySelectorAll) { continue; }
|
2018-09-21 17:45:28 -06:00
|
|
|
for (let se of e.querySelectorAll("[src],[href]")) {
|
|
|
|
se.outerHTML = se.outerHTML.replace(/(src|href)="([^/]+)"/i, "$1=\"" + base + "$2\"")
|
2018-10-02 09:22:09 -06:00
|
|
|
//console.log(se.outerHTML);
|
2018-09-21 17:45:28 -06:00
|
|
|
}
|
2018-10-02 09:22:09 -06:00
|
|
|
//console.log(e.querySelectorAll("[src]"));
|
2018-09-21 17:45:28 -06:00
|
|
|
}
|
2018-10-02 09:22:09 -06:00
|
|
|
//console.log(mutation.addedNodes);
|
2018-09-21 17:45:28 -06:00
|
|
|
} else {
|
|
|
|
console.log(mutation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-02 09:22:09 -06:00
|
|
|
let puzzle = document.getElementById("puzzle");
|
|
|
|
let observerOptions = {
|
|
|
|
childList: true,
|
|
|
|
attributes: true,
|
|
|
|
subtree: true,
|
|
|
|
};
|
|
|
|
window.observer = new MutationObserver(mutated);
|
|
|
|
observer.observe(puzzle, observerOptions);
|
2018-09-19 17:56:47 -06:00
|
|
|
}
|
|
|
|
document.addEventListener("DOMContentLoaded", init);
|
|
|
|
</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-02 19:21:54 -06:00
|
|
|
<span id="idtxt">Team ID:</span> <input type="text" name="id"> <br>
|
2018-10-02 09:22:09 -06:00
|
|
|
Answer: <input type="text" name="answer"> <br>
|
|
|
|
<input type="submit" value="Submit">
|
|
|
|
</form>
|
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>
|