-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.ts
98 lines (75 loc) · 2.31 KB
/
main.ts
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
(async () => {
// Kagekiri allows us to easily query elements located inside the Shadow DOM.
// ING's newest websites heavily uses web components.
const { querySelector, querySelectorAll } = await import('kagekiri');
console.log(
'%cING autofill is active',
'background-color: #ED6C2D; color: white; font-size: 16px',
);
const loginCatcher = document.createElement('input');
loginCatcher.autocomplete = 'username';
loginCatcher.style.position = 'absolute';
loginCatcher.style.left = '-10000px';
const passwordCatcher = document.createElement('input');
passwordCatcher.type = 'password';
passwordCatcher.autocomplete = 'current-password';
passwordCatcher.style.position = 'absolute';
passwordCatcher.style.left = '-10000px';
document.body.prepend(loginCatcher, passwordCatcher);
loginCatcher.addEventListener(
'change',
(event) => {
const value = (event.target as HTMLInputElement).value;
const loginInput = querySelector(
'input[name="login"]',
) as HTMLInputElement;
const submitButton = querySelector(
'button[type="submit"]',
) as HTMLButtonElement;
loginInput.value = value;
loginInput.dispatchEvent(new Event('input', { bubbles: true }));
submitButton.click();
// Clean-up
loginCatcher.remove();
},
{ once: true },
);
let value: string;
passwordCatcher.addEventListener(
'change',
(event) => {
value = (event.target as HTMLInputElement).value;
// Clean-up
passwordCatcher.remove();
},
{ once: true },
);
const observer = new MutationObserver(() => {
const loginInput = querySelector('input[name="login"]') as HTMLInputElement;
if (loginInput) {
loginInput.placeholder = 'ING autofill is active';
}
if (querySelector('[name="password"]')) {
// Clean-up
observer.disconnect();
const fields = querySelectorAll(
'input[name^=pin-]:enabled',
) as HTMLInputElement[];
const submitButton = querySelector(
'button[type="submit"]',
) as HTMLButtonElement;
for (const field of fields) {
const characterNumber =
Number.parseInt(field.name.split('-')[1], 10) - 1;
field.disabled = true;
field.value = value[characterNumber];
field.dispatchEvent(new Event('input', { bubbles: true }));
}
submitButton.click();
}
});
observer.observe(document, {
childList: true,
subtree: true,
});
})();