1 function undisplay(element) {
2 element.style.display="none";
5 function add_message(severity, message) {
6 message = `<div class="message ${severity}" onclick="undisplay(this)">
7 <span class="hide-button" onclick="undisplay(this.parentElement)">×</span>
10 const message_area = document.getElementById('message-area');
11 message_area.insertAdjacentHTML('beforeend', message);
14 function lmno_join_loadend(request, game_id) {
15 if (request.status === 404) {
16 add_message("danger", game_id + " is not a valid game ID. Try again.");
20 /* Now that its validated, send the browser to the URL for the game_id. */
21 window.location.href = "/" + game_id;
24 function lmno_join(form) {
25 const game_id = form.id.value;
27 var request = new XMLHttpRequest();
28 request.addEventListener("loadend", () => lmno_join_loadend(request, game_id));
30 request.open("GET", "/" + game_id);
31 request.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
37 function lmno_new_loadend() {
38 if (this.status == 200) {
39 /* Response contains the game ID which we simply point the browser to. */
40 const game_id = JSON.parse(this.response);
41 window.location.href = ('/' + game_id);
45 add_message("danger", `An error occured creating a new game (${this.status}).`);
48 function lmno_new(engine) {
49 const request = new XMLHttpRequest();
50 request.addEventListener("loadend", lmno_new_loadend);
52 request.open("POST", "/new/" + engine);
53 request.setRequestHeader("Content-Type", "application/json; charset=UTF-8");