-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
57 lines (54 loc) · 1.92 KB
/
script.js
File metadata and controls
57 lines (54 loc) · 1.92 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
event.key ==pageUP shown
event.location == 0,1,2
event.which==57 shown
event.code==numpad9
*/
const box = document.querySelector('.box');
const key = document.querySelectorAll('.key');
const icon = document.querySelectorAll('.icon');
const html = document.querySelector('.main');
const container = document.querySelector('.container');
const h1 = document.querySelector('.init');
const keyLocation = ['General keys', 'Left-side modifier keys', 'Right-side modifier keys', 'Numpad'];
let state = 'true' //true for light mode
let counter = 0;
function update(e) {
counter++;
if(counter===1){
h1.style.setProperty('display', 'none');
[...container.children].forEach(child => {if(child.nodeName!='svg'){child.style.setProperty('opacity', '1')}});
//Only for first keypress
}
box.innerHTML = `${e.which}<span>${e.key}</span>`;
if(e.which.toString().length===3){
//Make space for 3 digit keycodes in the box
box.style.setProperty('font-size', 'calc(var(--side) - 15rem)');
}
else {
box.style.setProperty('font-size', 'calc(var(--side) - 10rem)');
}
key[0].textContent = e.key;
key[1].textContent = `${e.location} (${keyLocation[e.location]})`;
key[2].textContent = e.which;
key[3].textContent = e.code;
}
window.addEventListener('keydown', update);
icon.forEach(ic => ic.addEventListener('click', () => {
html.classList.toggle('dark');
container.classList.toggle('darkcont');
box.classList.toggle('darkbox');
icon[1].classList.toggle('transp');
state = !state;
localStorage.setItem('state', JSON.stringify(state));
}));
window.addEventListener('load', ()=>{
state = JSON.parse(localStorage.getItem('state'));
//if state is 'dark' then update these
if(!state) {
html.classList.add('dark');
container.classList.add('darkcont');
box.classList.add('darkbox');
icon[1].classList.add('transp');
}
});