Repository navigation
Expand file tree
/
Copy pathrecorder.js
More file actions
224 lines (193 loc) · 7.21 KB
/
Copy pathrecorder.js
File metadata and controls
224 lines (193 loc) · 7.21 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
// Hi TWI and all the other Technical Goober Dash players
(() => {
if (document.getElementById('kbd-ui-wrap')) return;
const d = document;
const wrapper = d.createElement('div');
wrapper.id = 'kbd-ui-wrap';
wrapper.style.position = 'fixed';
wrapper.style.left = '10%';
wrapper.style.top = '80%';
wrapper.style.width = '180px';
wrapper.style.height = '80px';
wrapper.style.resize = 'both';
wrapper.style.overflow = 'hidden';
wrapper.style.zIndex = '99999';
wrapper.style.userSelect = 'none';
wrapper.style.background = 'transparent';
let percentX = 0.1;
let percentY = 0.8;
const scaleBox = d.createElement('div');
scaleBox.id = 'kbd-ui';
scaleBox.style.width = '180px';
scaleBox.style.height = '80px';
scaleBox.style.transformOrigin = 'top left';
scaleBox.style.position = 'absolute';
scaleBox.style.left = '0';
scaleBox.style.top = '0';
const panel = d.createElement('div');
panel.style.width = '100%';
panel.style.height = '100%';
panel.style.background = 'rgba(0, 0, 0, 0.6)';
panel.style.borderRadius = '8px';
panel.style.display = 'flex';
panel.style.flexDirection = 'row';
panel.style.alignItems = 'flex-end';
panel.style.gap = '10px';
panel.style.padding = '16px 10px 10px 10px';
panel.style.boxSizing = 'border-box';
panel.style.fontFamily = 'sans-serif';
panel.style.fontSize = '16px';
panel.style.color = '#fff';
panel.style.position = 'relative';
const closeBtn = document.createElement('div');
closeBtn.textContent = '×';
closeBtn.title = 'Close';
closeBtn.style.position = 'absolute';
closeBtn.style.top = '4px';
closeBtn.style.left = '6px';
closeBtn.style.fontSize = '14px';
closeBtn.style.color = '#fff';
closeBtn.style.opacity = '0.2';
closeBtn.style.cursor = 'pointer';
closeBtn.style.transition = 'opacity 0.2s';
closeBtn.addEventListener('mouseenter', () => closeBtn.style.opacity = '1');
closeBtn.addEventListener('mouseleave', () => closeBtn.style.opacity = '0.2');
closeBtn.addEventListener('click', () => {
d.removeEventListener('keydown', keydownHandler);
d.removeEventListener('keyup', keyupHandler);
d.removeEventListener('mousemove', dragMove);
d.removeEventListener('mouseup', dragEnd);
window.removeEventListener('resize', resizeHandler);
observer.disconnect();
wrapper.remove();
});
panel.appendChild(closeBtn);
const buttons = {};
function createKey(label, keyName) {
const btn = document.createElement('button');
btn.textContent = label;
btn.dataset.key = keyName;
btn.style.background = '#222';
btn.style.border = 'none';
btn.style.color = 'white';
btn.style.padding = '6px 10px';
btn.style.borderRadius = '4px';
btn.style.opacity = '0.8';
btn.style.cursor = 'default';
btn.style.transition = 'all 0.1s';
btn.style.userSelect = 'none';
btn.style.minWidth = '32px';
btn.style.textAlign = 'center';
btn.style.fontSize = '1em';
buttons[keyName.toUpperCase()] = btn;
return btn;
}
const xBtn = createKey('X', 'X');
const arrowKeys = {
ArrowUp: '↑',
ArrowDown: '↓',
ArrowLeft: '←',
ArrowRight: '→'
};
for (const key in arrowKeys) {
createKey(arrowKeys[key], key);
}
const arrowContainer = document.createElement('div');
arrowContainer.style.display = 'flex';
arrowContainer.style.flexDirection = 'column';
arrowContainer.style.alignItems = 'center';
arrowContainer.style.gap = '4px';
const rowUp = document.createElement('div');
rowUp.appendChild(buttons['ARROWUP']);
const rowBottom = document.createElement('div');
rowBottom.style.display = 'flex';
rowBottom.style.gap = '4px';
rowBottom.appendChild(buttons['ARROWLEFT']);
rowBottom.appendChild(buttons['ARROWDOWN']);
rowBottom.appendChild(buttons['ARROWRIGHT']);
arrowContainer.appendChild(rowUp);
arrowContainer.appendChild(rowBottom);
panel.appendChild(xBtn);
panel.appendChild(arrowContainer);
scaleBox.appendChild(panel);
wrapper.appendChild(scaleBox);
d.body.appendChild(wrapper);
function highlight(key, on) {
const btn = buttons[key.toUpperCase()];
if (btn) btn.style.background = on ? '#555' : '#222';
}
function keydownHandler(e) {
const k = e.key.toUpperCase();
if (buttons[k]) highlight(k, true);
else if ((k === ' ' || k === 'X') && buttons['X']) highlight('X', true);
}
function keyupHandler(e) {
const k = e.key.toUpperCase();
if (buttons[k]) highlight(k, false);
else if ((k === ' ' || k === 'X') && buttons['X']) highlight('X', false);
}
d.addEventListener('keydown', keydownHandler);
d.addEventListener('keyup', keyupHandler);
let isDragging = false;
let offsetX = 0;
let offsetY = 0;
function isInResizeCorner(e) {
const rect = wrapper.getBoundingClientRect();
return e.clientX > rect.right - 20 && e.clientY > rect.bottom - 20;
}
wrapper.addEventListener('mousedown', (e) => {
if (e.target.tagName === 'BUTTON' || isInResizeCorner(e)) return;
isDragging = true;
offsetX = e.clientX - wrapper.getBoundingClientRect().left;
offsetY = e.clientY - wrapper.getBoundingClientRect().top;
wrapper.style.cursor = 'grabbing';
e.preventDefault();
});
function dragMove(e) {
if (!isDragging) return;
const newLeft = e.clientX - offsetX;
const newTop = e.clientY - offsetY;
const rect = wrapper.getBoundingClientRect();
const maxLeft = window.innerWidth - rect.width;
const maxTop = window.innerHeight - rect.height;
const clampedLeft = Math.max(0, Math.min(newLeft, maxLeft));
const clampedTop = Math.max(0, Math.min(newTop, maxTop));
wrapper.style.left = clampedLeft + 'px';
wrapper.style.top = clampedTop + 'px';
percentX = clampedLeft / window.innerWidth;
percentY = clampedTop / window.innerHeight;
}
function dragEnd() {
isDragging = false;
wrapper.style.cursor = 'grab';
}
d.addEventListener('mousemove', dragMove);
d.addEventListener('mouseup', dragEnd);
function resizeHandler() {
const rect = wrapper.getBoundingClientRect();
let width = rect.width;
let height = rect.height;
const targetRatio = 2.25;
const correctedHeight = width / targetRatio;
if (Math.abs(height - correctedHeight) > 1) {
height = correctedHeight;
wrapper.style.height = height + 'px';
}
const maxWidth = window.innerWidth * 0.9;
const maxHeight = window.innerHeight * 0.9;
width = Math.min(width, maxWidth);
height = Math.min(height, maxHeight);
const scaleX = width / 180;
const scaleY = height / 80;
const scale = Math.min(scaleX, scaleY);
scaleBox.style.transform = `scale(${scale})`;
const newLeft = window.innerWidth * percentX;
const newTop = window.innerHeight * percentY;
wrapper.style.left = Math.max(0, Math.min(newLeft, window.innerWidth - width)) + 'px';
wrapper.style.top = Math.max(0, Math.min(newTop, window.innerHeight - height)) + 'px';
}
resizeHandler();
window.addEventListener('resize', resizeHandler);
const observer = new ResizeObserver(resizeHandler);
observer.observe(wrapper);
})();