moth/theme/puzzle-list.html

81 lines
1.8 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">
<script>
function render(obj) {
puzzlesElement = document.createElement('div');
let cats = [];
for (let cat in obj) {
cats.push(cat);
console.log(cat);
}
cats.sort();
for (let cat of cats) {
let puzzles = obj[cat];
let pdiv = document.createElement('div');
pdiv.className = 'category';
let h = document.createElement('h2');
pdiv.appendChild(h);
h.textContent = cat;
let l = document.createElement('ul');
pdiv.appendChild(l);
for (var puzzle of puzzles) {
var points = puzzle[0];
var id = puzzle[1];
var i = document.createElement('li');
i.textContent = " ";
2018-09-18 18:22:03 -06:00
l.appendChild(i);
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-09-18 18:22:03 -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>