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) {
|
2017-11-09 17:50:30 -07:00
|
|
|
term.clear();
|
|
|
|
|
|
|
|
let cats = [];
|
|
|
|
for (let cat in obj) {
|
|
|
|
cats.push(cat);
|
|
|
|
}
|
|
|
|
cats.sort();
|
2016-04-04 21:45:00 -06:00
|
|
|
|
2017-11-09 17:50:30 -07:00
|
|
|
for (let cat of cats) {
|
|
|
|
let puzzles = obj[cat];
|
|
|
|
|
|
|
|
let pdiv = createElement('div');
|
|
|
|
pdiv.className = 'category';
|
|
|
|
|
|
|
|
let h = createElement('h2');
|
|
|
|
pdiv.appendChild(h);
|
|
|
|
h.textContent = cat;
|
|
|
|
|
|
|
|
let l = createElement('ul');
|
|
|
|
pdiv.appendChild(l);
|
|
|
|
|
|
|
|
for (var puzzle of puzzles) {
|
|
|
|
var points = puzzle[0];
|
|
|
|
var id = puzzle[1];
|
|
|
|
|
|
|
|
var i = createElement('li');
|
|
|
|
l.appendChild(i);
|
|
|
|
|
|
|
|
if (points === 0) {
|
|
|
|
i.textContent = "‡";
|
|
|
|
} else {
|
|
|
|
var a = createElement('a');
|
|
|
|
i.appendChild(a);
|
|
|
|
a.className = "link";
|
|
|
|
a.textContent = points;
|
|
|
|
a.href = cat + "/" + id + "/index.html";
|
|
|
|
// a.addEventListener("click", loadPuzzle.bind(undefined, cat, id, points));
|
2016-09-22 09:34:01 -06:00
|
|
|
}
|
2017-11-09 17:50:30 -07:00
|
|
|
}
|
2016-04-03 21:12:48 -06:00
|
|
|
|
2016-09-22 09:34:01 -06:00
|
|
|
term.appendShallow(pdiv);
|
2017-11-09 17:50:30 -07:00
|
|
|
}
|
2016-09-22 09:34:01 -06:00
|
|
|
}
|
2016-04-03 21:12:48 -06:00
|
|
|
|
|
|
|
function puzzles_start() {
|
2017-11-09 17:50:30 -07:00
|
|
|
var element = document.getElementById("puzzles");
|
|
|
|
var puzzlesTerminal = new Terminal(element);
|
|
|
|
var refreshInterval = 40 * 1000;
|
2016-09-22 09:34:01 -06:00
|
|
|
|
2017-11-09 17:50:30 -07:00
|
|
|
var refreshCallback = puzzlesRefresh.bind(undefined, puzzlesTerminal);
|
2018-05-16 08:21:09 -06:00
|
|
|
var refreshFunction = loadJSON.bind(undefined, puzzlesJsonUrl + '?_=' + new Date().getTime(), refreshCallback);
|
2016-09-22 09:34:01 -06:00
|
|
|
|
2017-11-09 17:50:30 -07:00
|
|
|
puzzlesTerminal.clear();
|
|
|
|
puzzlesTerminal.par("Loading...");
|
|
|
|
refreshFunction();
|
|
|
|
setInterval(refreshFunction, refreshInterval);
|
2016-04-03 21:12:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener("load", puzzles_start);
|