-
Notifications
You must be signed in to change notification settings - Fork 99
/
hcaptcha_fast.js
53 lines (49 loc) · 1.63 KB
/
hcaptcha_fast.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
44
45
46
47
48
49
50
51
52
53
/**
* Enables drag select for hCaptcha.
*/
(async () => {
let $start = null;
let is_mousedown = false;
let is_selecting = false;
function toggle_img($e, enabled, include_start=false) {
if (!$e) {
return;
}
if (!include_start && $start === $e) {
return;
}
if (enabled === true && $e.getAttribute('aria-pressed') === 'false') {
$e.click();
}
else if (enabled === false && $e.getAttribute('aria-pressed') === 'true') {
$e.click();
}
}
document.addEventListener('mousedown', e => {
if (e?.target?.parentNode?.getAttribute('aria-pressed') === 'false') {
is_mousedown = true;
is_selecting = true;
}
else if (e?.target?.parentNode?.getAttribute('aria-pressed') === 'true') {
is_mousedown = true;
is_selecting = false;
}
$start = e?.target?.parentNode;
});
document.addEventListener('mouseup', e => {
is_mousedown = false;
$start = null;
});
document.addEventListener('mousemove', e => {
if (is_mousedown) {
if ($start !== e?.target?.parentNode && $start !== null) {
toggle_img($start, is_selecting, true);
}
toggle_img(e?.target?.parentNode, is_selecting);
}
});
window.addEventListener('load', () => {
const sheet = document.body.appendChild(document.createElement('style')).sheet;
sheet.insertRule('[aria-pressed="true"] > .border-focus {background-color: #0f0 !important; opacity: 0.3 !important}', 0);
});
})();