-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmouse.html
More file actions
389 lines (332 loc) · 11.6 KB
/
mouse.html
File metadata and controls
389 lines (332 loc) · 11.6 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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
<html lang="en">
<head>
<title>Arkose Biometrics Playground</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8">
<link rel="icon" type="image/png" href="https://external-content.duckduckgo.com/ip3/arkoselabs.com.ico"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/picocss/2.0.6/pico.min.css" integrity="sha512-UXfikgakSZBii5lkvmDCRO+IYWQhTtwMOJ+3EmGEA+oA82kvbSskgw3OI16Jx1kINgF8aqOkYE+c9h4m6muONg==" crossorigin="anonymous" referrerpolicy="no-referrer"/>
<style>
code {
white-space: pre-wrap;
overflow-y: scroll;
min-height: 70vh;
max-height: 70vh;
}
.copyBtn {
border-top-left-radius: 0;
border-top-right-radius: 0;
width: 100%;
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>Arkose Biometrics Collector</h1>
</header>
<section>
<ol>
<li>75 events will be collected as part of the bda (4ca87df3d1).</li>
<li>150<sup>*</sup> events will be collected for answer submission as part of mbio.</li>
</ol>
<div role="group">
<button class="secondary" type="button" id="bdaBtn">BDA Preset</button>
<button class="secondary" type="button" id="mbioBtn">mbio Preset</button>
<button type="button" id="resetBtn">Reset</button>
</div>
</section>
<hr>
<details open>
<summary role="button" class="secondary">Mouse</summary>
<label>
Max Events:
<input id="maxMouseEvents" type="number" placeholder="150" value="75" aria-label="max events">
</label>
<label>
<input id="mouseEnabled" type="checkbox" role="switch" checked/>
Collect
</label>
<fieldset class="grid">
<div>
<code style="width: 100%" id="outputMouse"></code>
<button class="copyBtn" data-target="outputMouse" type="button">Copy to Clipboard 📋</button>
</div>
<div>
<code style="width: 100%" id="outputMouseFormatted"></code>
<button class="copyBtn" data-target="outputMouseFormatted" type="button">Copy to Clipboard 📋</button>
</div>
</fieldset>
</details>
<details>
<summary role="button" class="secondary">Keyboard</summary>
<label>
Max Events:
<input id="maxKeyEvents" type="number" placeholder="50" value="75" aria-label="max events">
</label>
<label>
<input id="keyEnabled" type="checkbox" role="switch" checked/>
Collect
</label>
<fieldset class="grid">
<div>
<code style="width: 100%" id="outputKeyboard"></code>
<button class="copyBtn" data-target="outputKeyboard" type="button">Copy to Clipboard 📋</button>
</div>
<div>
<code style="width: 100%" id="outputKeyboardFormatted"></code>
<button class="copyBtn" data-target="outputKeyboardFormatted" type="button">Copy to Clipboard 📋</button>
</div>
</fieldset>
</details>
<details>
<summary role="button" class="secondary">Touch</summary>
<label>
Max Events:
<input id="maxTouchEvents" type="number" placeholder="150" value="75" aria-label="max events">
</label>
<label>
<input id="touchEnabled" type="checkbox" role="switch" checked/>
Collect
</label>
<fieldset class="grid">
<div>
<code style="width: 100%" id="outputTouch"></code>
<button class="copyBtn" data-target="outputTouch" type="button">Copy to Clipboard 📋</button>
</div>
<div>
<code style="width: 100%" id="outputTouchFormatted"></code>
<button class="copyBtn" data-target="outputTouchFormatted" type="button">Copy to Clipboard 📋</button>
</div>
</fieldset>
</details>
</div>
<script>
const outputMouseElement = document.getElementById("outputMouse");
const outputMouseFormattedElement = document.getElementById("outputMouseFormatted");
const mouseEnabledElement = document.getElementById("mouseEnabled");
const maxMouseEventsElement = document.getElementById("maxMouseEvents");
const outputKeyElement = document.getElementById("outputKeyboard");
const outputKeyFormattedElement = document.getElementById("outputKeyboardFormatted");
const keyEnabledElement = document.getElementById("keyEnabled");
const maxKeyEventsElement = document.getElementById("maxKeyEvents");
const outputTouchElement = document.getElementById("outputTouch");
const outputTouchFormattedElement = document.getElementById("outputTouchFormatted");
const touchEnabledElement = document.getElementById("touchEnabled");
const maxTouchEventsElement = document.getElementById("maxTouchEvents");
const MouseEvents = Object.freeze({
Move: 0,
Down: 1,
Up: 2,
});
const KeyEvents = Object.freeze({
Down: 0,
Up: 1,
});
const TouchEvents = Object.freeze({
Start: 0,
End: 1,
Move: 2,
Cancel: 99,
});
const AllowedKeys = Object.freeze({
Tab: 0,
Enter: 1,
Space: 3,
ShiftLeft: 4,
ShiftRight: 5,
ControlLeft: 6,
ControlRight: 7,
MetaLeft: 8,
MetaRight: 9,
AltLeft: 10,
AltRight: 11,
Backspace: 12,
Escape: 13,
Default: 14,
});
let mouseEvents;
let touchEvents;
let keyPressEvents;
let startTimestamp;
let _lastMouseMove;
function reset() {
startTimestamp = Date.now();
mouseEvents = [];
_lastMouseMove = undefined;
outputMouseElement.textContent = "";
outputMouseFormattedElement.textContent = "";
mouseEnabledElement.checked = true;
mouseEnabledElement.disabled = false;
keyPressEvents = [];
outputKeyElement.textContent = "";
outputKeyFormattedElement.textContent = "";
keyEnabledElement.checked = true;
keyEnabledElement.disabled = false;
touchEvents = [];
outputTouchElement.textContent = "";
outputTouchFormattedElement.textContent = "";
touchEnabledElement.checked = true;
touchEnabledElement.disabled = false;
}
reset();
document.getElementById("resetBtn").addEventListener("click", (evt) => {
evt.preventDefault();
reset();
});
const MOUSE_THRESHOLD = 5;
document.addEventListener("mousemove", recordMouseEventFactory(MouseEvents.Move));
document.addEventListener("mousedown", recordMouseEventFactory(MouseEvents.Down));
document.addEventListener("mouseup", recordMouseEventFactory(MouseEvents.Up));
document.addEventListener("keydown", recordKeyPressEventFactory(KeyEvents.Down));
document.addEventListener("keyup", recordKeyPressEventFactory(KeyEvents.Up));
document.addEventListener("touchstart", recordTouchEventFactory(TouchEvents.Start), {
passive: false,
});
document.addEventListener("touchend", recordTouchEventFactory(TouchEvents.End), {
passive: false,
});
document.addEventListener("touchmove", recordTouchEventFactory(TouchEvents.Move), {
passive: false,
});
document.addEventListener("touchcancel", recordTouchEventFactory(TouchEvents.Cancel), {
passive: false,
});
function recordMouseEventFactory(mouseEventType) {
return function(mouseEvent) {
if(!mouseEnabledElement.checked) {
return;
}
const MAX_MOUSE_EVENTS = parseInt(maxMouseEventsElement.value, 10);
if(mouseEvents.length >= MAX_MOUSE_EVENTS) {
mouseEnabledElement.checked = false;
mouseEnabledElement.disabled = true;
return;
}
function insertEvent() {
const eventObject = {
timestamp: Date.now() - startTimestamp,
type: mouseEventType,
x: mouseEvent.pageX,
y: mouseEvent.pageY,
};
mouseEvents.push(eventObject);
_lastMouseMove = eventObject;
updateDisplay(outputMouseElement, outputMouseFormattedElement, mouseEvents, `${eventObject.timestamp},${eventObject.type},${eventObject.x},${eventObject.y};`);
}
if(mouseEvents.length <= MAX_MOUSE_EVENTS) {
if(mouseEventType === MouseEvents.Move) {
if(_lastMouseMove) {
// magnitude = sqrt(x*x + y*y)
// if magnitude > MOUSE_THRESHOLD (5)
const magnitude = Math.sqrt((mouseEvent.pageX - _lastMouseMove.x) * (mouseEvent.pageX - _lastMouseMove.x) + (mouseEvent.pageY - _lastMouseMove.y) * (mouseEvent.pageY - _lastMouseMove.y));
if(magnitude > MOUSE_THRESHOLD) {
insertEvent();
}
return;
}
else {
insertEvent();
return;
}
}
const eventObject = {
timestamp: Date.now() - startTimestamp,
type: mouseEventType,
x: mouseEvent.pageX,
y: mouseEvent.pageY,
};
mouseEvents.push(eventObject);
updateDisplay(outputMouseElement, outputMouseFormattedElement, mouseEvents, `${eventObject.timestamp},${eventObject.type},${eventObject.x},${eventObject.y};`);
}
};
}
function recordKeyPressEventFactory(keyEventType) {
return function(keyEvent) {
if(!keyEnabledElement.checked) {
return;
}
// 75 on bda, 50 on mbio
const MAX_KEY_EVENTS = parseInt(maxKeyEventsElement.value, 10);
if(keyPressEvents.length >= MAX_KEY_EVENTS) {
keyEnabledElement.checked = false;
keyEnabledElement.disabled = true;
return;
}
if(keyPressEvents.length < MAX_KEY_EVENTS) {
const eventObject = {
timestamp: Date.now() - startTimestamp,
type: keyEventType,
code: AllowedKeys[keyEvent.code] ?? AllowedKeys.Default,
};
keyPressEvents.push(eventObject);
updateDisplay(outputKeyElement, outputKeyFormattedElement, keyPressEvents, `${eventObject.timestamp},${eventObject.type},${eventObject.code};`);
}
};
}
function recordTouchEventFactory(touchEventType) {
return function(touchEvent) {
if(!touchEnabledElement.checked) {
return;
}
// 75 on bda, 150 on mbio
const MAX_TOUCH_EVENTS = parseInt(maxTouchEventsElement.value, 10);
if(touchEvents.length >= MAX_TOUCH_EVENTS) {
touchEnabledElement.checked = false;
touchEnabledElement.disabled = true;
return;
}
for(let i = 0; i < touchEvent.touches.length; i++) {
if(touchEvents.length < MAX_TOUCH_EVENTS) {
const eventObject = {
timestamp: Date.now() - startTimestamp,
type: touchEventType,
x: Math.floor(touchEvent.touches[i].pageX),
y: Math.floor(touchEvent.touches[i].pageY),
};
touchEvents.push(eventObject);
updateDisplay(outputTouchElement, outputTouchFormattedElement, touchEvents, `${eventObject.timestamp},${eventObject.type},${eventObject.x},${eventObject.y};`);
}
}
};
}
function updateDisplay(outputElement, outputFormattedElement, allEvents, stringify) {
outputElement.textContent = JSON.stringify(allEvents, null, 4);
outputElement.scrollTop = 900000;
outputFormattedElement.textContent += `${stringify}\n`;
outputFormattedElement.scrollTop = 900000;
}
document.getElementById("bdaBtn").addEventListener("click", (evt) => {
evt.preventDefault();
maxMouseEventsElement.value = "75";
maxKeyEventsElement.value = "75";
maxTouchEventsElement.value = "75";
});
document.getElementById("mbioBtn").addEventListener("click", (evt) => {
evt.preventDefault();
maxMouseEventsElement.value = "150";
maxKeyEventsElement.value = "50";
maxTouchEventsElement.value = "150";
});
const copyButtons = document.getElementsByClassName("copyBtn");
for(const copyButton of copyButtons) {
copyButton.addEventListener("click", (evt) => {
evt.preventDefault();
const targetId = copyButton.getAttribute("data-target");
const text = document.getElementById(targetId).textContent;
copyToClipboard(text);
});
}
function copyToClipboard(text) {
const textArea = document.createElement("textarea");
textArea.value = text;
textArea.style.position = "fixed";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
// noinspection JSDeprecatedSymbols
document.execCommand("copy");
document.body.removeChild(textArea);
}
</script>
</body>
</html>