-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (40 loc) · 1.08 KB
/
index.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
33
34
35
36
37
38
39
40
41
42
43
const GUESTSAVE= "guest";
const FONTSIZE= "size";
let guestnames = document.getElementById("guestnames")
// Load
if(sessionStorage[GUESTSAVE]){
guestnames.querySelector("li").remove();
sessionStorage.getItem(GUESTSAVE).split("\n").forEach(n => {
let li = document.createElement("li");
li.innerHTML = n;
guestnames.appendChild(li);
});
}
if(sessionStorage[FONTSIZE]){
guestnames.style.fontSize = sessionStorage.getItem(FONTSIZE);
}
// Save
guestnames.addEventListener("input",function(){
var guest = [];
Array.from(guestnames.querySelectorAll("li")).forEach(i => {
guest.push(i.innerHTML);
});
sessionStorage.setItem(GUESTSAVE, guest.join("\n"))
});
// keyboard
document.body.addEventListener("keydown", e => {
if(e.ctrlKey && e.key.startsWith("Arrow")){
let f = guestnames.style.fontSize;
if(!f){ f = 250} else { f = parseInt(f)}
switch (e.key) {
case "ArrowUp":
f -= 10;
break;
case "ArrowDown":
f += 10;
break;
}
guestnames.style.fontSize = `${f}%`;
sessionStorage.setItem(FONTSIZE, `${f}%`);
}
});