handle autofill for pages with no forms, but still has fields

This commit is contained in:
Kyle Spearrin 2016-09-17 09:35:54 -04:00
parent 3bd24a15fc
commit 790d705d40
1 changed files with 68 additions and 60 deletions

View File

@ -17,14 +17,15 @@ function initAutofill() {
metadata: {}
};
var passwordFields = [];
var passwordFields = [],
passwordForms = [];
for (var i = 0; i < pageDetails.fields.length; i++) {
if (pageDetails.fields[i].type === 'password') {
passwordFields.push(pageDetails.fields[i]);
}
}
var passwordForms = [];
for (var formKey in pageDetails.forms) {
for (var j = 0; j < passwordFields.length; j++) {
if (formKey === passwordFields[j].form) {
@ -34,11 +35,11 @@ function initAutofill() {
}
}
if (!passwordForms.length) {
return null;
}
var password = null,
username = null,
loginForm = null;
var loginForm = null;
if (passwordForms.length) {
if (passwordForms.length > 1) {
// More than one form with a password field is on the page.
// This usually occurs when a website has a login and signup form on the same page.
@ -82,7 +83,6 @@ function initAutofill() {
loginForm = passwordForms[0];
}
var password = null;
for (i = 0; i < pageDetails.fields.length; i++) {
var f = pageDetails.fields[i];
if (f.form === loginForm.opid && f.type === 'password') {
@ -91,7 +91,6 @@ function initAutofill() {
}
}
var username = null;
for (i = 0; i < pageDetails.fields.length; i++) {
f = pageDetails.fields[i];
if (f.form === loginForm.opid && (f.type === 'text' || f.type === 'email')
@ -100,16 +99,25 @@ function initAutofill() {
}
}
if (loginForm.htmlAction) {
fillScript.autosubmit = { focusOpid: password.opid };
}
}
else if (passwordFields.length == 1) {
password = passwordFields[0];
if (password.elementNumber > 0) {
username = pageDetails.fields[password.elementNumber - 1];
}
}
if (username) {
fillScript.script.push(['click_on_opid', username.opid]);
fillScript.script.push(['fill_by_opid', username.opid, fillUsername]);
}
if (password) {
fillScript.script.push(['click_on_opid', password.opid]);
fillScript.script.push(['fill_by_opid', password.opid, fillPassword]);
if (loginForm.htmlAction) {
fillScript.autosubmit = { focusOpid: password.opid };
}
return fillScript;