summaryrefslogtreecommitdiff
path: root/public/main.js
blob: 3f7031b7d3216da41656547d08332734fac145c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
document.addEventListener("DOMContentLoaded", async () => { "use strict";

const $ = (s,c) => (c||document).querySelector(s);
function $$(x,y,z,a){a=(z||document).querySelectorAll(x);if(typeof y=="function")[].forEach.call(a,y);return a}
function m(a,b,c){c=document;b=c.createElement(b||"p");b.innerHTML=a.trim();for(a=c.createDocumentFragment();c=b.firstChild;)a.appendChild(c);return a.firstChild}

const boardEl = document.createElement("table");
$("#board").appendChild(boardEl);

for (let i=0;i<6;i++) {
  let o = "<tr>";
  for (let j=0;j<6;j++) {
    o += `<td>&nbsp;</td>`
  }
  o = m(o, "table");
  boardEl.appendChild(o);
}

function processKey(key) {
  if (!/^([a-z]|enter|bspc)$/.test(key)) return;
  console.log(key);
}

document.addEventListener("keydown", e =>
  e.ctrlKey || e.altKey || e.metaKey ||
    processKey(e.key.toLowerCase()
      .replace("backspace", "bspc")));

//if ("serviceWorker" in navigator) {
//  navigator.serviceWorker.register("sw.js")
//    .then(() => console.log("Service worker registered"));
//}

});