@@ -51,6 +51,8 @@ function writeValueWithEvents(input, value) {
5151// Fill MFA TOTP code
5252function fillTOTP ( code ) {
5353
54+ if ( ! code ) { return ; }
55+
5456 if ( document . baseURI . includes ( "zoom.us" ) ) {
5557 var zoomInput = document . querySelector ( "[class=form-masked-pin]" ) ;
5658
@@ -111,10 +113,11 @@ function copyToClipboard(txt) {
111113
112114function fillForm ( creds ) {
113115
114- // Try filling TOTP code.
115- if ( creds [ "otpauth" ] ) {
116- fillTOTP ( creds [ "otpauth" ] ) ;
117- }
116+ const password = creds [ "pass__password" ] ;
117+ const username = creds [ "pass__user" ] ;
118+ const totp = creds [ "otpauth" ] ;
119+
120+ fillTOTP ( totp ) ;
118121
119122 // AWS signin forms has two text inputs for username and account. Here we
120123 // specifically fill username.
@@ -132,43 +135,39 @@ function fillForm(creds) {
132135 writeValueWithEvents ( input , creds [ "account" ] ) ;
133136 } else {
134137 // If placeholder is not empty, the form expects a root user email.
135- writeValueWithEvents ( input , creds [ "pass__user" ] ) ;
138+ writeValueWithEvents ( input , username ) ;
136139 }
137140 }
138141
139142 var userInput = document . querySelector ( "input[id=username]" ) ;
140143
141144 if ( userInput ) {
142- writeValueWithEvents ( userInput , creds [ "pass__user" ] ) ;
145+ writeValueWithEvents ( userInput , username ) ;
143146 }
144147
145148 var passInput = document . querySelector ( "input[type=password]" ) ;
146149
147150 if ( passInput ) {
148- writeValueWithEvents ( passInput , creds [ "pass__password" ] ) ;
149- }
150-
151- } else if ( document . baseURI . includes ( "idmsa.apple.com" ) ) {
152-
153- var userInput = document . querySelector ( "#account_name_text_field" ) ;
154-
155- if ( userInput ) {
156- writeValueWithEvents ( userInput , creds [ "pass__user" ] ) ;
151+ writeValueWithEvents ( passInput , password ) ;
157152 }
153+ } else {
154+ fillDefaultForm ( username , password ) ;
155+ }
158156
159- var passwordInput = document . querySelector ( "input[type=password]" ) ;
157+ for ( const [ id , content ] of Object . entries ( creds ) ) {
160158
161- if ( passwordInput ) {
162- writeValueWithEvents ( passwordInput , creds [ "pass__password" ] ) ;
163- focus ( passwordInput ) ;
159+ // Skip special keys.
160+ if ( [ "pass__password" , "pass__user" , "otpauth" ] . includes ( id ) ) {
161+ continue ;
164162 }
165- } else {
166- fillDefaultForm ( creds [ "pass__user" ] , creds [ "pass__password" ] )
167- }
168163
164+ var input = document . querySelector ( "input[id=" + id + "]" ) ;
165+ var value = content ;
169166
170- for ( const [ key , value ] of Object . entries ( creds ) ) {
171- var input = document . querySelector ( "input[name=" + key + "]" ) ;
167+ // Replace special values.
168+ if ( content == "pass__user" ) { value = username ; }
169+ if ( content == "pass__password" ) { value = password ; }
170+ if ( content == "otpauth" ) { value = totp ; }
172171
173172 if ( input != null ) {
174173 writeValueWithEvents ( input , value ) ;
0 commit comments