/
totp-autocomplete.js
40 lines (31 loc) · 1.11 KB
/
totp-autocomplete.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
'use strict';
class TOTPAutocomplete extends Autocomplete {}
TOTPAutocomplete.prototype.click = async function(e, input) {
if (!e.isTrusted) {
return;
}
await kpxc.updateTOTPList();
this.showList(input, true);
};
TOTPAutocomplete.prototype.itemClick = async function(e, input, uuid) {
if (!e.isTrusted) {
return;
}
const index = Array.prototype.indexOf.call(e.currentTarget.parentElement.childNodes, e.currentTarget);
await this.fillTotp(index, uuid, input);
this.closeList();
input.focus();
};
TOTPAutocomplete.prototype.itemEnter = async function(index, item) {
const uuid = item?.getAttribute('uuid');
this.fillTotp(index, uuid);
};
TOTPAutocomplete.prototype.fillTotp = async function(index, uuid, currentInput) {
const combination = await kpxcFields.getCombination(this.input, 'totp')
|| await kpxcFields.getCombination(this.input, 'totpInputs');
if (combination) {
combination.loginId = index;
}
kpxcFill.fillTOTPFromUuid(this.input || currentInput, uuid);
};
const kpxcTOTPAutocomplete = new TOTPAutocomplete();