moth/theme/puzzle-list.html

82 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">
<link rel="icon" href="res/icon.svg" type="image/svg+xml">
<link rel="icon" href="res/icon.png" type="image/png">
<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');
l.appendChild(i);
if (points === 0) {
2018-09-19 17:56:26 -06:00
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);
}
}
function init() {
fetch("puzzles.json")
.then(function(resp) {
return resp.json();
}).then(function(obj) {
render(obj);
}).catch(function(err) {
console.log("Error", err);
});
}
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>