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 join_loadend(request, game_id) {
15 if (request.status === 404) {
16 add_message("danger", game_id + " is not a valid game ID. Try again.");
21 function lmno_join(form) {
22 const game_id = form.id.value;
24 var request = new XMLHttpRequest();
25 request.addEventListener("loadend", () => join_loadend(request, game_id));
27 request.open("GET", "/" + game_id);
28 request.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
34 function new_loadend() {
35 if (this.status == 200) {
36 /* Response contains the game ID which we simply point the browser to. */
37 const game_id = JSON.parse(this.response);
38 window.location.href = ('/' + game_id);
42 add_message("danger", `An error occured creating a new game (${this.status}).`);
45 function lmno_new(engine) {
46 console.log("In lmno_new");
47 const request = new XMLHttpRequest();
48 request.addEventListener("loadend", new_loadend);
50 request.open("POST", "/new/" + engine);
51 request.setRequestHeader("Content-Type", "application/json; charset=UTF-8");