2016-09-22 09:34:01 -06:00
|
|
|
var puzzlesTerminal;
|
|
|
|
var puzzlesJsonUrl = "puzzles.json";
|
2016-04-04 21:45:00 -06:00
|
|
|
|
2016-09-22 09:34:01 -06:00
|
|
|
function loadPuzzle(cat, id, points) {
|
|
|
|
console.log("Requested " + cat + "/" + id + "(" + points + ")");
|
|
|
|
}
|
2016-04-03 21:12:48 -06:00
|
|
|
|
2016-09-22 09:34:01 -06:00
|
|
|
function puzzlesRefresh(term, obj) {
|
|
|
|
term.clear();
|
2016-04-04 21:45:00 -06:00
|
|
|
|
2016-09-22 09:34:01 -06:00
|
|
|
for (var cat in obj) {
|
|
|
|
var puzzles = obj[cat];
|
2016-04-04 21:45:00 -06:00
|
|
|
|
2016-09-22 09:34:01 -06:00
|
|
|
var pdiv = createElement('div');
|
|
|
|
pdiv.className = 'category';
|
2016-04-03 21:12:48 -06:00
|
|
|
|
2016-09-22 09:34:01 -06:00
|
|
|
var h = createElement('h2');
|
|
|
|
pdiv.appendChild(h);
|
|
|
|
h.textContent = cat;
|
2016-04-04 21:45:00 -06:00
|
|
|
|
2016-09-22 09:34:01 -06:00
|
|
|
var l = createElement('ul');
|
|
|
|
pdiv.appendChild(l);
|
2016-04-04 21:45:00 -06:00
|
|
|
|
2016-09-22 09:34:01 -06:00
|
|
|
for (var puzzle of puzzles) {
|
|
|
|
var points = puzzle[0];
|
|
|
|
var id = puzzle[1];
|
2016-04-04 21:45:00 -06:00
|
|
|
|
2016-09-22 09:34:01 -06:00
|
|
|
var i = createElement('li');
|
|
|
|
l.appendChild(i);
|
2016-04-04 22:16:22 -06:00
|
|
|
|
2016-09-22 09:34:01 -06:00
|
|
|
if (points == 0) {
|
|
|
|
i.textContent = "‡";
|
|
|
|
} else {
|
2017-02-05 16:42:41 -07:00
|
|
|
var a = createElement('a');
|
2016-09-22 09:34:01 -06:00
|
|
|
i.appendChild(a);
|
|
|
|
a.className = "link";
|
|
|
|
a.textContent = points;
|
2017-02-05 16:42:41 -07:00
|
|
|
a.href = cat + "/" + id + "/index.html";
|
|
|
|
// a.addEventListener("click", loadPuzzle.bind(undefined, cat, id, points));
|
2016-09-22 09:34:01 -06:00
|
|
|
}
|
|
|
|
}
|
2016-04-03 21:12:48 -06:00
|
|
|
|
2016-09-22 09:34:01 -06:00
|
|
|
term.appendShallow(pdiv);
|
|
|
|
}
|
|
|
|
}
|
2016-04-03 21:12:48 -06:00
|
|
|
|
|
|
|
function puzzles_start() {
|
2016-09-22 09:34:01 -06:00
|
|
|
var element = document.getElementById("puzzles");
|
|
|
|
var puzzlesTerminal = new Terminal(element);
|
|
|
|
var refreshInterval = 40 * 1000;
|
|
|
|
|
|
|
|
var refreshCallback = puzzlesRefresh.bind(undefined, puzzlesTerminal);
|
|
|
|
var refreshFunction = loadJSON.bind(undefined, puzzlesJsonUrl, refreshCallback);
|
|
|
|
|
|
|
|
puzzlesTerminal.clear();
|
|
|
|
puzzlesTerminal.par("Loading...");
|
|
|
|
refreshFunction();
|
|
|
|
setInterval(refreshFunction, refreshInterval);
|
2016-04-03 21:12:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener("load", puzzles_start);
|