moth/theme/puzzle-list.html

94 lines
2.1 KiB
HTML
Raw Normal View History

2018-09-18 18:22:03 -06:00
<!DOCTYPE html>
<html>
<head>
<title>Open Puzzles</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-18 18:22:03 -06:00
<script>
function render(obj) {
puzzlesElement = document.createElement('div');
let cats = [];
for (let cat in obj) {
cats.push(cat);
}
cats.sort();
for (let cat of cats) {
2018-10-02 19:21:54 -06:00
if (cat.startsWith("__")) {
// Metadata or something
continue;
}
2018-09-18 18:22:03 -06:00
let puzzles = obj[cat];
let pdiv = document.createElement('div');
pdiv.className = 'category';
let h = document.createElement('h2');
pdiv.appendChild(h);
h.textContent = cat;
2018-10-02 19:21:54 -06:00
if (obj.__devel__) {
var a = document.createElement('a');
h.insertBefore(a, h.firstChild);
a.textContent = "⬇️";
a.href = "mothballer/" + cat;
a.classList.add("mothball");
a.title = "Download a compiled puzzle for this category";
}
2018-09-18 18:22:03 -06:00
let l = document.createElement('ul');
pdiv.appendChild(l);
2018-10-02 19:21:54 -06:00
2018-09-18 18:22:03 -06:00
for (var puzzle of puzzles) {
var points = puzzle[0];
var id = puzzle[1];
var i = document.createElement('li');
l.appendChild(i);
2018-10-02 19:21:54 -06:00
i.textContent = " ";
2018-09-18 18:22:03 -06:00
if (points === 0) {
i.textContent = "✿";
2018-09-18 18:22:03 -06:00
} else {
var a = document.createElement('a');
i.appendChild(a);
a.textContent = points;
2018-09-19 17:56:26 -06:00
a.href = "puzzle.html?cat=" + cat + "&points=" + points + "&pid=" + id;
}
}
2018-10-02 19:21:54 -06:00
puzzlesElement.appendChild(pdiv);
document.getElementById("puzzles").appendChild(puzzlesElement);
2018-09-18 18:22:03 -06:00
}
}
function init() {
fetch("puzzles.json")
.then(function(resp) {
return resp.json();
}).then(function(obj) {
render(obj);
}).catch(function(err) {
console.log("Error", err);
});
2018-09-18 18:22:03 -06:00
}
document.addEventListener("DOMContentLoaded", init);
</script>
</head>
<body>
<h1 class="Success">Open Puzzles</h1>
<section>
<div id="puzzles"></div>
</section>
<nav>
<ul>
2018-09-19 17:56:26 -06:00
<li><a href="puzzle-list.html">Puzzles</a></li>
2018-09-18 18:22:03 -06:00
<li><a href="scoreboard.html">Scoreboard</a></li>
</ul>
</nav>
</body>
</html>