mirror of https://github.com/dirtbags/moth.git
82 lines
1.8 KiB
HTML
82 lines
1.8 KiB
HTML
<!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) {
|
|
i.textContent = "✿";
|
|
} else {
|
|
var a = document.createElement('a');
|
|
i.appendChild(a);
|
|
a.textContent = points;
|
|
a.href = "puzzle.html?cat=" + cat + "&points=" + points + "&pid=" + id;
|
|
}
|
|
}
|
|
|
|
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>
|
|
<li><a href="puzzle-list.html">Puzzles</a></li>
|
|
<li><a href="scoreboard.html">Scoreboard</a></li>
|
|
</ul>
|
|
</nav>
|
|
</body>
|
|
</html>
|