From 1c3143867b75bb88f106b6cd26978e9b11cc450d Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 25 Oct 2017 21:55:52 -0400 Subject: [PATCH] cleanup autofill service a bit --- src/services/autofillService.js | 50 +++++++++++++++------------------ 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/src/services/autofillService.js b/src/services/autofillService.js index 22a76d03e8..ac48a4e619 100644 --- a/src/services/autofillService.js +++ b/src/services/autofillService.js @@ -78,16 +78,8 @@ function initAutofill() { }; var isoProvinces = { - alberta: 'AB', - 'british columbia': 'BC', - manitoba: 'MB', - 'new brunswick': 'NB', - 'newfoundland and labrador': 'NL', - 'nova scotia': 'NS', - ontario: 'ON', - 'prince edward island': 'PE', - quebec: 'QC', - saskatchewan: 'SK' + alberta: 'AB', 'british columbia': 'BC', manitoba: 'MB', 'new brunswick': 'NB', 'newfoundland and labrador': 'NL', + 'nova scotia': 'NS', ontario: 'ON', 'prince edward island': 'PE', quebec: 'QC', saskatchewan: 'SK' }; AutofillService.prototype.getFormsWithPasswordFields = function (pageDetails) { @@ -95,25 +87,29 @@ function initAutofill() { formData = []; passwordFields = loadPasswordFields(pageDetails, true); - if (passwordFields.length) { - for (var formKey in pageDetails.forms) { - for (var i = 0; i < passwordFields.length; i++) { - var pf = passwordFields[i]; - if (formKey === pf.form) { - var uf = findUsernameField(pageDetails, pf, false, false); - if (!uf) { - // not able to find any viewable username fields. maybe there are some "hidden" ones? - uf = findUsernameField(pageDetails, pf, true, false); - } + if (!passwordFields.length) { + return formData; + } - formData.push({ - form: pageDetails.forms[formKey], - password: pf, - username: uf - }); - break; - } + for (var formKey in pageDetails.forms) { + for (var i = 0; i < passwordFields.length; i++) { + var pf = passwordFields[i]; + if (formKey !== pf.form) { + continue; } + + var uf = findUsernameField(pageDetails, pf, false, false); + if (!uf) { + // not able to find any viewable username fields. maybe there are some "hidden" ones? + uf = findUsernameField(pageDetails, pf, true, false); + } + + formData.push({ + form: pageDetails.forms[formKey], + password: pf, + username: uf + }); + break; } }