-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkeycodes-symphony.js
32 lines (30 loc) · 968 Bytes
/
keycodes-symphony.js
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
document.addEventListener("keydown", function (event) {
compose(event);
});
function compose(e) {
if (e === undefined) {
return;
}
if (
[...Array(26).keys()].map((i) => i + 97).includes(e.key.charCodeAt(0))
) {
let div = document.createElement("div");
div.classList.add("note");
div.style.backgroundColor = `rgb(${
(255 / 26) * (e.key.charCodeAt(0) - 97)
}, ${(255 / 26) * (e.key.charCodeAt(0) - 97)}, ${
(255 / 26) * (e.key.charCodeAt(0) - 97)
})`;
div.innerHTML = e.key;
document.body.appendChild(div);
} else if (e.key === "Backspace") {
let notes = document.getElementsByClassName("note");
notes[notes.length - 1].remove();
} else if (e.key === "Escape") {
let notes = document.getElementsByClassName("note");
while (notes.length > 0) {
notes[0].remove();
}
}
}
export { compose };