-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.html
62 lines (52 loc) · 1.28 KB
/
ui.html
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
58
59
60
61
62
<div id='container' tabindex='-1'></div>
<script>
const container = document.getElementById('container')
function renderContainer() {
container.innerText = document.activeElement === container
? 'you can use keyboard controls'
: 'focus the plugin to use controls'
}
container.addEventListener('focus', renderContainer)
container.addEventListener('blur', renderContainer)
renderContainer()
const pressedKeys = new Set()
function updatePressedKeys() {
parent.postMessage({ pluginMessage: { kind: 'UPDATE_PRESSED_KEYS', pressedKeys: [ ...pressedKeys ] } }, '*')
}
container.addEventListener('keydown', (event) => {
pressedKeys.add(event.key)
updatePressedKeys()
})
container.addEventListener('keyup', (event) => {
pressedKeys.delete(event.key)
updatePressedKeys()
})
</script>
<style>
html, body {
margin: 0;
height: 100%;
}
#container {
border: 5px solid red;
color: red;
font-family: 'Comic Sans MS', sans-serif;
text-align: center;
height: 100%;
box-sizing: border-box;
outline: none;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
opacity: 0.5;
cursor: default;
user-select: none;
}
#container:focus {
border-color: green;
border-width: 15px;
color: green;
opacity: 1;
}
</style>