mirror of https://github.com/dirtbags/moth.git
Update theme to new Puzzle struct
This commit is contained in:
parent
1fffeb0060
commit
fb22032638
File diff suppressed because one or more lines are too long
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
// prettify adds classes to various types, returning an HTML string.
|
// prettify adds classes to various types, returning an HTML string.
|
||||||
function prettify(key, val) {
|
function prettify(key, val) {
|
||||||
console.log(key, val)
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case "Body":
|
case "Body":
|
||||||
return '[HTML]'
|
return '[HTML]'
|
||||||
|
@ -62,7 +61,7 @@ async function checkAnswer(answer) {
|
||||||
answerHashes.push(await sha256Hash(answer))
|
answerHashes.push(await sha256Hash(answer))
|
||||||
|
|
||||||
for (let hash of answerHashes) {
|
for (let hash of answerHashes) {
|
||||||
for (let correctHash of window.puzzle.Pre.AnswerHashes) {
|
for (let correctHash of window.puzzle.AnswerHashes) {
|
||||||
if (hash == correctHash) {
|
if (hash == correctHash) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -129,7 +128,7 @@ async function loadPuzzle(categoryName, points, puzzleId) {
|
||||||
window.puzzle = await resp.json()
|
window.puzzle = await resp.json()
|
||||||
|
|
||||||
// Populate authors
|
// Populate authors
|
||||||
document.getElementById("authors").textContent = window.puzzle.Pre.Authors.join(", ")
|
document.getElementById("authors").textContent = window.puzzle.Authors.join(", ")
|
||||||
|
|
||||||
// If answers are provided, this is the devel server
|
// If answers are provided, this is the devel server
|
||||||
if (window.puzzle.Answers.length > 0) {
|
if (window.puzzle.Answers.length > 0) {
|
||||||
|
@ -137,14 +136,14 @@ async function loadPuzzle(categoryName, points, puzzleId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load scripts
|
// Load scripts
|
||||||
for (let script of (window.puzzle.Pre.Scripts || [])) {
|
for (let script of (window.puzzle.Scripts || [])) {
|
||||||
let st = document.createElement("script")
|
let st = document.createElement("script")
|
||||||
document.head.appendChild(st)
|
document.head.appendChild(st)
|
||||||
st.src = base + script
|
st.src = base + script
|
||||||
}
|
}
|
||||||
|
|
||||||
// List associated files
|
// List associated files
|
||||||
for (let fn of (window.puzzle.Pre.Attachments || [])) {
|
for (let fn of (window.puzzle.Attachments || [])) {
|
||||||
let li = document.createElement("li")
|
let li = document.createElement("li")
|
||||||
let a = document.createElement("a")
|
let a = document.createElement("a")
|
||||||
a.href = base + fn
|
a.href = base + fn
|
||||||
|
@ -154,14 +153,14 @@ async function loadPuzzle(categoryName, points, puzzleId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prefix `base` to relative URLs in the puzzle body
|
// Prefix `base` to relative URLs in the puzzle body
|
||||||
let doc = new DOMParser().parseFromString(window.puzzle.Pre.Body, "text/html")
|
let doc = new DOMParser().parseFromString(window.puzzle.Body, "text/html")
|
||||||
for (let se of doc.querySelectorAll("[src],[href]")) {
|
for (let se of doc.querySelectorAll("[src],[href]")) {
|
||||||
se.outerHTML = se.outerHTML.replace(/(src|href)="([^/]+)"/i, "$1=\"" + base + "$2\"")
|
se.outerHTML = se.outerHTML.replace(/(src|href)="([^/]+)"/i, "$1=\"" + base + "$2\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a validation pattern was provided, set that
|
// If a validation pattern was provided, set that
|
||||||
if (window.puzzle.Pre.AnswerPattern) {
|
if (window.puzzle.AnswerPattern) {
|
||||||
document.querySelector("#answer").pattern = window.puzzle.Pre.AnswerPattern
|
document.querySelector("#answer").pattern = window.puzzle.AnswerPattern
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace puzzle children with what's in `doc`
|
// Replace puzzle children with what's in `doc`
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<link rel="stylesheet" href="basic.css">
|
<link rel="stylesheet" href="basic.css">
|
||||||
<meta name="viewport" content="width=device-width">
|
<meta name="viewport" content="width=device-width">
|
||||||
<script src="moment.min.js" async></script>
|
<script src="moment.min.js" async></script>
|
||||||
<script src="Chart.min.js" async></script>
|
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js" async></script>
|
||||||
<script src="scoreboard.js" async></script>
|
<script src="scoreboard.js" async></script>
|
||||||
</head>
|
</head>
|
||||||
<body class="wide">
|
<body class="wide">
|
||||||
|
|
Loading…
Reference in New Issue