From 19ec4a60b89ab41da68a83a3f6a4d043c693297c Mon Sep 17 00:00:00 2001 From: varjolintu Date: Sun, 14 Mar 2021 11:20:21 +0200 Subject: [PATCH] Add support for segmented TOTP fields without a form --- .../content/keepassxc-browser.js | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/keepassxc-browser/content/keepassxc-browser.js b/keepassxc-browser/content/keepassxc-browser.js index 240aa67..960c0d3 100755 --- a/keepassxc-browser/content/keepassxc-browser.js +++ b/keepassxc-browser/content/keepassxc-browser.js @@ -387,14 +387,8 @@ kpxcFields.getAllCombinations = async function(inputs) { // Adds segmented TOTP fields to the combination if found kpxcFields.getSegmentedTOTPFields = function(inputs, combinations) { - const form = inputs.length > 0 ? inputs[0].form : undefined; - if (!form) { - return combinations; - } - - if (acceptedOTPFields.some(f => form.className.includes(f) || form.id.includes(f) || form.name.includes(f)) - || form.length === 6) { - const totpInputs = Array.from(form.elements).filter(e => e.nodeName === 'INPUT' && e.type !== 'password'); + const addTotpFieldsToCombination = function(inputFields) { + const totpInputs = Array.from(inputFields).filter(e => e.nodeName === 'INPUT' && e.type !== 'password'); if (totpInputs.length === 6) { const combination = { form: form, @@ -411,6 +405,16 @@ kpxcFields.getSegmentedTOTPFields = function(inputs, combinations) { segmented: true }); } + }; + + const form = inputs.length > 0 ? inputs[0].form : undefined; + if (form && (acceptedOTPFields.some(f => form.className.includes(f) || form.id.includes(f) || form.name.includes(f)) + || form.length === 6)) { + // Use the form's elements + addTotpFieldsToCombination(form.elements); + } else if (inputs.length === 6 && inputs.every(i => i.inputMode === 'numeric' && i.pattern.includes('0-9'))) { + // No form is found, but input fields are possibly segmented TOTP fields + addTotpFieldsToCombination(inputs); } return combinations;