@@ -10,7 +10,7 @@ kpxcForm.savedCustomInputs = [];
1010kpxcForm . savedForms = [ ] ;
1111kpxcForm . submitTriggered = false ;
1212
13- // Activate the Credential Banner if existing credentials are not found
13+ // Activate the Credential Banner if credentials are found from form submit
1414kpxcForm . activateCredentialBanner = async function ( usernameValue , passwordInputs , passwordField ) {
1515 let passwordValue = '' ;
1616 // Check if the form has three password fields -> a possible password change form
@@ -163,7 +163,7 @@ kpxcForm.initForm = function(form, credentialFields) {
163163 form . addEventListener ( 'submit' , kpxcForm . onSubmit ) ;
164164
165165 const submitButton = kpxcForm . getFormSubmitButton ( form ) ;
166- if ( submitButton !== undefined ) {
166+ if ( submitButton ) {
167167 submitButton . addEventListener ( 'click' , kpxcForm . onSubmit ) ;
168168 }
169169 }
@@ -181,6 +181,15 @@ kpxcForm.initCustomForm = function(combinations) {
181181 }
182182} ;
183183
184+ // Identifies a submit button from the page outside any form
185+ kpxcForm . initSubmitButtonFromPage = function ( ) {
186+ let submitButton = kpxcSites . formSubmitButtonExceptionFound ( ) ;
187+ submitButton ??= $ ( 'button[type=submit], button.login' ) ;
188+ if ( submitButton ) {
189+ submitButton . addEventListener ( 'click' , kpxcForm . onSubmit ) ;
190+ }
191+ } ;
192+
184193// Triggers when a custom form has been identified with a specific form submit button
185194kpxcForm . onCustomFormSubmit = async function ( e ) {
186195 if ( ! e . isTrusted || kpxcForm . savedCustomInputs ?. length === 0 ) {
@@ -227,14 +236,25 @@ kpxcForm.onSubmit = async function(e) {
227236 form = kpxcForm . savedForms [ 0 ] . form ;
228237 }
229238
230- if ( ! form ) {
239+ // Try choosing inputs from the last combination detected.
240+ // Needed if initSubmitButtonFromPage() has been used.
241+ let usernameField ;
242+ let passwordField ;
243+ let passwordInputs = [ ] ;
244+ if ( ! form && kpxc . combinations . length > 0 ) {
245+ usernameField = kpxc . combinations . at ( - 1 ) ?. username ;
246+ passwordField = kpxc . combinations . at ( - 1 ) ?. password ;
247+ passwordInputs = kpxc . combinations . at ( - 1 ) ?. passwordInputs ;
248+ } else {
249+ [ usernameField , passwordField , passwordInputs ] = kpxcForm . getCredentialFieldsFromForm ( form ) ;
250+ }
251+
252+ if ( ! form && ! usernameField && ! passwordField ) {
231253 logDebug ( 'Error: No form found for submit detection.' ) ;
232254 kpxcForm . submitTriggered = false ;
233255 return ;
234256 }
235257
236- const [ usernameField , passwordField , passwordInputs ] = kpxcForm . getCredentialFieldsFromForm ( form ) ;
237-
238258 // Use the first text field in the form if only username input is missing
239259 const usernameValue = await kpxcForm . getUsernameValue ( ! usernameField && passwordField
240260 ? form ?. querySelector ( 'input[type=text]' )
0 commit comments