Skip to content

Commit

Permalink
page: support OTP forms with one <input> per digit
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Vogt committed Dec 1, 2023
1 parent 8652291 commit aae6469
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
26 changes: 21 additions & 5 deletions src/modules/page.js
Expand Up @@ -198,12 +198,28 @@ PassFF.Page = (function () {
function writeValueWithEvents(input, value) {
// don't fill if element is invisible
if (isInvisible(input)) return;
input.value = value;
for (let action of ['focus', 'keydown', 'keyup', 'keypress',
'input', 'change', 'blur']) {
input.dispatchEvent(createFakeEvent(action));
input.value = value;
let inputs = [input];
let values = [value];
if (input.maxLength == 1) {
inputs = Array.from(
document.getElementsByTagName('input')
).filter(el => el.maxLength == 1);
if (inputs.length == value.length) {
values = value.split("");
} else {
inputs = [input];
}
}
values.forEach((value, i) => {
input = inputs[i];
input.value = value;
for (let action of ['focus', 'keydown', 'keyup', 'keypress',
'input', 'change', 'blur']) {
input.dispatchEvent(createFakeEvent(action));
input.value = value;
}
});

}

function annotateInputs(inputs) {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/preferences.js
Expand Up @@ -64,7 +64,7 @@ PassFF.Preferences = (function () {
var prefParams = {
passwordInputNames : 'passwd,password,pass',
loginInputNames : 'login,user,mail,email,tel,username,opt_login,log,usr_name',
otpInputNames : 'otp,code,otc,user[otp_attempt]',
otpInputNames : 'otp,code,otc,user[otp_attempt],one-time-password',
buttonInputQueries : 'button:not([type=reset])\ninput[type=submit]\ninput[type=button]\n[role=button]',
loginFieldNames : 'login,user,username,id',
passwordFieldNames : 'passwd,password,pass',
Expand Down

0 comments on commit aae6469

Please sign in to comment.