2017-10-17 05:11:32 +02:00
|
|
|
|
function AutofillService(utilsService, totpService, tokenService, cipherService) {
|
2017-08-28 19:00:46 +02:00
|
|
|
|
this.utilsService = utilsService;
|
|
|
|
|
this.totpService = totpService;
|
|
|
|
|
this.tokenService = tokenService;
|
2017-10-17 05:11:32 +02:00
|
|
|
|
this.cipherService = cipherService;
|
2017-08-28 19:00:46 +02:00
|
|
|
|
|
2016-09-17 06:00:17 +02:00
|
|
|
|
initAutofill();
|
2017-07-14 21:34:05 +02:00
|
|
|
|
}
|
2016-09-17 06:00:17 +02:00
|
|
|
|
|
|
|
|
|
function initAutofill() {
|
2017-09-22 18:10:19 +02:00
|
|
|
|
// Add other languages to this array
|
|
|
|
|
var usernameFieldNames = ['username', 'user name', 'email', 'email address', 'e-mail', 'e-mail address',
|
|
|
|
|
'userid', 'user id'];
|
|
|
|
|
|
|
|
|
|
AutofillService.prototype.generateFillScript = function (pageDetails, fill) {
|
|
|
|
|
if (!pageDetails) {
|
2016-09-17 06:00:17 +02:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var fillScript = {
|
|
|
|
|
documentUUID: pageDetails.documentUUID,
|
|
|
|
|
script: [],
|
|
|
|
|
autosubmit: null,
|
|
|
|
|
properties: {},
|
|
|
|
|
options: {},
|
|
|
|
|
metadata: {}
|
|
|
|
|
};
|
|
|
|
|
|
2016-09-17 15:35:54 +02:00
|
|
|
|
var passwordFields = [],
|
2016-09-30 04:21:12 +02:00
|
|
|
|
passwords = [],
|
|
|
|
|
usernames = [],
|
2017-09-29 21:12:23 +02:00
|
|
|
|
filledFields = {},
|
2016-09-30 04:21:12 +02:00
|
|
|
|
pf = null,
|
2017-09-22 18:10:19 +02:00
|
|
|
|
username = null,
|
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
|
|
if (fill.fields && fill.fields.length) {
|
|
|
|
|
var fieldNames = [];
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < fill.fields.length; i++) {
|
|
|
|
|
if (fill.fields[i].name && fill.fields[i].name !== '') {
|
|
|
|
|
fieldNames.push(fill.fields[i].name.toLowerCase());
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
fieldNames.push(null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < pageDetails.fields.length; i++) {
|
|
|
|
|
var field = pageDetails.fields[i];
|
2017-09-29 21:12:23 +02:00
|
|
|
|
if (filledFields.hasOwnProperty(field.opid) || !field.viewable) {
|
2017-09-22 18:10:19 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var matchingIndex = findMatchingFieldIndex(field, fieldNames);
|
|
|
|
|
if (matchingIndex > -1) {
|
2017-09-29 21:12:23 +02:00
|
|
|
|
filledFields[field.opid] = field;
|
2017-09-22 18:10:19 +02:00
|
|
|
|
fillScript.script.push(['click_on_opid', field.opid]);
|
|
|
|
|
fillScript.script.push(['fill_by_opid', field.opid, fill.fields[matchingIndex].value]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!fill.password || fill.password === '') {
|
|
|
|
|
// No password for this login. Maybe they just wanted to auto-fill some custom fields?
|
2017-09-29 21:12:23 +02:00
|
|
|
|
fillScript = setFillScriptForFocus(filledFields, fillScript);
|
2017-09-22 18:10:19 +02:00
|
|
|
|
return fillScript;
|
|
|
|
|
}
|
2016-09-17 15:35:54 +02:00
|
|
|
|
|
2016-12-30 08:09:54 +01:00
|
|
|
|
passwordFields = loadPasswordFields(pageDetails, false);
|
2016-11-26 18:06:39 +01:00
|
|
|
|
if (!passwordFields.length) {
|
2016-11-26 20:41:08 +01:00
|
|
|
|
// not able to find any viewable password fields. maybe there are some "hidden" ones?
|
2016-12-30 08:09:54 +01:00
|
|
|
|
passwordFields = loadPasswordFields(pageDetails, true);
|
2016-09-17 06:00:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var formKey in pageDetails.forms) {
|
2016-09-30 04:21:12 +02:00
|
|
|
|
var passwordFieldsForForm = [];
|
2017-07-14 21:34:05 +02:00
|
|
|
|
for (i = 0; i < passwordFields.length; i++) {
|
2016-09-30 04:21:12 +02:00
|
|
|
|
if (formKey === passwordFields[i].form) {
|
|
|
|
|
passwordFieldsForForm.push(passwordFields[i]);
|
2016-09-17 06:00:17 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-17 15:35:54 +02:00
|
|
|
|
|
2016-10-04 05:54:03 +02:00
|
|
|
|
for (i = 0; i < passwordFieldsForForm.length; i++) {
|
|
|
|
|
pf = passwordFieldsForForm[i];
|
2016-09-30 04:21:12 +02:00
|
|
|
|
passwords.push(pf);
|
|
|
|
|
|
2017-09-22 18:10:19 +02:00
|
|
|
|
if (fill.username) {
|
2017-01-21 18:38:52 +01:00
|
|
|
|
username = findUsernameField(pageDetails, pf, false, false);
|
2016-11-26 18:06:39 +01:00
|
|
|
|
|
|
|
|
|
if (!username) {
|
2016-11-26 20:41:08 +01:00
|
|
|
|
// not able to find any viewable username fields. maybe there are some "hidden" ones?
|
2017-01-21 18:38:52 +01:00
|
|
|
|
username = findUsernameField(pageDetails, pf, true, false);
|
2016-09-17 15:35:54 +02:00
|
|
|
|
}
|
2016-09-17 06:00:17 +02:00
|
|
|
|
|
2016-09-30 04:21:12 +02:00
|
|
|
|
if (username) {
|
|
|
|
|
usernames.push(username);
|
|
|
|
|
}
|
2016-09-17 15:35:54 +02:00
|
|
|
|
}
|
2016-09-17 06:00:17 +02:00
|
|
|
|
}
|
2016-09-17 15:35:54 +02:00
|
|
|
|
}
|
2016-09-30 04:21:12 +02:00
|
|
|
|
|
2016-10-04 05:54:03 +02:00
|
|
|
|
if (passwordFields.length && !passwords.length) {
|
|
|
|
|
// The page does not have any forms with password fields. Use the first password field on the page and the
|
2016-09-17 19:47:17 +02:00
|
|
|
|
// input field just before it as the username.
|
|
|
|
|
|
2016-09-30 04:21:12 +02:00
|
|
|
|
pf = passwordFields[0];
|
|
|
|
|
passwords.push(pf);
|
|
|
|
|
|
2017-09-22 18:10:19 +02:00
|
|
|
|
if (fill.username && pf.elementNumber > 0) {
|
2017-01-21 18:38:52 +01:00
|
|
|
|
username = findUsernameField(pageDetails, pf, false, true);
|
2016-09-17 19:47:17 +02:00
|
|
|
|
|
2016-11-26 18:06:39 +01:00
|
|
|
|
if (!username) {
|
2016-11-26 20:41:08 +01:00
|
|
|
|
// not able to find any viewable username fields. maybe there are some "hidden" ones?
|
2017-01-21 18:38:52 +01:00
|
|
|
|
username = findUsernameField(pageDetails, pf, true, true);
|
2016-09-17 19:47:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-30 04:21:12 +02:00
|
|
|
|
if (username) {
|
|
|
|
|
usernames.push(username);
|
|
|
|
|
}
|
2016-09-17 06:00:17 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-07 19:10:04 +02:00
|
|
|
|
if (!passwordFields.length && !fill.skipUsernameOnlyFill) {
|
2017-09-22 18:10:19 +02:00
|
|
|
|
// No password fields on this page. Let's try to just fuzzy fill the username.
|
|
|
|
|
for (i = 0; i < pageDetails.fields.length; i++) {
|
|
|
|
|
var f = pageDetails.fields[i];
|
2017-09-29 21:12:23 +02:00
|
|
|
|
if (f.viewable && (f.type === 'text' || f.type === 'email' || f.type === 'tel') &&
|
2017-09-22 21:11:30 +02:00
|
|
|
|
fieldIsFuzzyMatch(f, usernameFieldNames)) {
|
2017-09-22 18:10:19 +02:00
|
|
|
|
usernames.push(f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-30 04:21:12 +02:00
|
|
|
|
for (i = 0; i < usernames.length; i++) {
|
2017-09-29 21:12:23 +02:00
|
|
|
|
if (filledFields.hasOwnProperty(usernames[i].opid)) {
|
2017-09-22 18:10:19 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-29 21:12:23 +02:00
|
|
|
|
filledFields[usernames[i].opid] = usernames[i];
|
2016-09-30 04:21:12 +02:00
|
|
|
|
fillScript.script.push(['click_on_opid', usernames[i].opid]);
|
2017-09-22 18:10:19 +02:00
|
|
|
|
fillScript.script.push(['fill_by_opid', usernames[i].opid, fill.username]);
|
2016-09-30 04:21:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < passwords.length; i++) {
|
2017-09-29 21:12:23 +02:00
|
|
|
|
if (filledFields.hasOwnProperty(passwords[i].opid)) {
|
2017-09-22 18:10:19 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-29 21:12:23 +02:00
|
|
|
|
filledFields[passwords[i].opid] = passwords[i];
|
2016-09-30 04:21:12 +02:00
|
|
|
|
fillScript.script.push(['click_on_opid', passwords[i].opid]);
|
2017-09-22 18:10:19 +02:00
|
|
|
|
fillScript.script.push(['fill_by_opid', passwords[i].opid, fill.password]);
|
2016-09-17 06:00:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-29 21:12:23 +02:00
|
|
|
|
fillScript = setFillScriptForFocus(filledFields, fillScript);
|
2016-09-17 06:00:17 +02:00
|
|
|
|
return fillScript;
|
|
|
|
|
};
|
2016-12-30 08:09:54 +01:00
|
|
|
|
|
|
|
|
|
AutofillService.prototype.getFormsWithPasswordFields = function (pageDetails) {
|
|
|
|
|
var passwordFields = [],
|
|
|
|
|
formData = [];
|
|
|
|
|
|
2017-10-06 04:30:46 +02:00
|
|
|
|
passwordFields = loadPasswordFields(pageDetails, true);
|
2016-12-30 08:09:54 +01:00
|
|
|
|
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) {
|
2017-01-21 18:38:52 +01:00
|
|
|
|
var uf = findUsernameField(pageDetails, pf, false, false);
|
2016-12-30 08:09:54 +01:00
|
|
|
|
if (!uf) {
|
|
|
|
|
// not able to find any viewable username fields. maybe there are some "hidden" ones?
|
2017-01-21 18:38:52 +01:00
|
|
|
|
uf = findUsernameField(pageDetails, pf, true, false);
|
2016-12-30 08:09:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
formData.push({
|
|
|
|
|
form: pageDetails.forms[formKey],
|
|
|
|
|
password: pf,
|
|
|
|
|
username: uf
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return formData;
|
|
|
|
|
};
|
|
|
|
|
|
2017-10-07 19:10:04 +02:00
|
|
|
|
AutofillService.prototype.doAutoFill = function (options) {
|
2017-08-28 19:00:46 +02:00
|
|
|
|
var deferred = Q.defer();
|
2017-09-22 21:11:30 +02:00
|
|
|
|
var self = this,
|
|
|
|
|
totpPromise = null;
|
2017-08-28 19:00:46 +02:00
|
|
|
|
|
|
|
|
|
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
|
|
|
|
|
var tab = null;
|
|
|
|
|
if (tabs.length > 0) {
|
|
|
|
|
tab = tabs[0];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
deferred.reject();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-07 19:10:04 +02:00
|
|
|
|
if (!tab || !options.login || !options.pageDetails || !options.pageDetails.length) {
|
2017-08-28 19:00:46 +02:00
|
|
|
|
deferred.reject();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var didAutofill = false;
|
2017-10-07 19:10:04 +02:00
|
|
|
|
for (var i = 0; i < options.pageDetails.length; i++) {
|
2017-08-28 19:00:46 +02:00
|
|
|
|
// make sure we're still on correct tab
|
2017-10-07 19:10:04 +02:00
|
|
|
|
if (options.pageDetails[i].tab.id !== tab.id || options.pageDetails[i].tab.url !== tab.url) {
|
2017-08-28 19:00:46 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-07 19:10:04 +02:00
|
|
|
|
var fillScript = self.generateFillScript(options.pageDetails[i].details, {
|
|
|
|
|
username: options.login.username,
|
|
|
|
|
password: options.login.password,
|
|
|
|
|
fields: options.login.fields,
|
|
|
|
|
skipUsernameOnlyFill: options.skipUsernameOnlyFill || false
|
2017-09-22 18:10:19 +02:00
|
|
|
|
});
|
2017-09-22 21:11:30 +02:00
|
|
|
|
|
2017-08-28 19:00:46 +02:00
|
|
|
|
if (!fillScript || !fillScript.script || !fillScript.script.length) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
didAutofill = true;
|
2017-10-07 19:10:04 +02:00
|
|
|
|
if (!options.skipLastUsed) {
|
2017-10-17 05:11:32 +02:00
|
|
|
|
self.cipherService.updateLastUsedDate(options.login.id);
|
2017-08-29 18:52:11 +02:00
|
|
|
|
}
|
2017-08-28 19:00:46 +02:00
|
|
|
|
|
|
|
|
|
chrome.tabs.sendMessage(tab.id, {
|
|
|
|
|
command: 'fillForm',
|
|
|
|
|
fillScript: fillScript
|
2017-10-07 19:10:04 +02:00
|
|
|
|
}, { frameId: options.pageDetails[i].frameId });
|
2017-08-28 19:00:46 +02:00
|
|
|
|
|
2017-10-07 19:10:04 +02:00
|
|
|
|
if (totpPromise || (options.fromBackground && self.utilsService.isFirefox()) ||
|
|
|
|
|
options.skipTotp || !options.login.totp || !self.tokenService.getPremium()) {
|
2017-09-22 21:11:30 +02:00
|
|
|
|
continue;
|
2017-08-28 19:00:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-22 21:11:30 +02:00
|
|
|
|
totpPromise = self.totpService.isAutoCopyEnabled().then(function (enabled) {
|
2017-08-28 19:00:46 +02:00
|
|
|
|
if (enabled) {
|
2017-10-06 16:36:45 +02:00
|
|
|
|
/* jshint ignore:start */
|
2017-10-07 19:10:04 +02:00
|
|
|
|
return self.totpService.getCode(options.login.totp);
|
2017-10-06 16:36:45 +02:00
|
|
|
|
/* jshint ignore:end */
|
2017-08-28 19:00:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}).then(function (code) {
|
|
|
|
|
if (code) {
|
2017-10-06 16:36:45 +02:00
|
|
|
|
/* jshint ignore:start */
|
2017-08-28 19:00:46 +02:00
|
|
|
|
self.utilsService.copyToClipboard(code);
|
2017-10-06 16:36:45 +02:00
|
|
|
|
/* jshint ignore:end */
|
2017-08-28 19:00:46 +02:00
|
|
|
|
}
|
2017-09-22 21:31:31 +02:00
|
|
|
|
|
|
|
|
|
return code;
|
2017-08-28 19:00:46 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-22 21:11:30 +02:00
|
|
|
|
if (didAutofill) {
|
|
|
|
|
if (totpPromise) {
|
2017-09-22 21:31:31 +02:00
|
|
|
|
totpPromise.then(function (totpCode) {
|
|
|
|
|
deferred.resolve(totpCode);
|
2017-09-22 21:11:30 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
deferred.resolve();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2017-08-28 19:00:46 +02:00
|
|
|
|
deferred.reject();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
|
};
|
|
|
|
|
|
2017-10-07 19:17:43 +02:00
|
|
|
|
AutofillService.prototype.doAutoFillForLastUsedLogin = function (pageDetails, fromCommand) {
|
2017-08-28 19:00:46 +02:00
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
|
|
|
|
|
var tab = null;
|
|
|
|
|
if (tabs.length > 0) {
|
|
|
|
|
tab = tabs[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!tab || !tab.url) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var tabDomain = self.utilsService.getDomain(tab.url);
|
|
|
|
|
if (!tabDomain) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-17 05:11:32 +02:00
|
|
|
|
self.cipherService.getLastUsedForDomain(tabDomain).then(function (cipher) {
|
|
|
|
|
if (!cipher) {
|
2017-08-28 19:00:46 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-09-22 18:10:19 +02:00
|
|
|
|
|
2017-10-07 19:10:04 +02:00
|
|
|
|
self.doAutoFill({
|
2017-10-17 05:11:32 +02:00
|
|
|
|
login: cipher,
|
2017-10-07 19:10:04 +02:00
|
|
|
|
pageDetails: pageDetails,
|
|
|
|
|
fromBackground: true,
|
2017-10-12 04:52:46 +02:00
|
|
|
|
skipTotp: !fromCommand,
|
2017-10-07 19:10:04 +02:00
|
|
|
|
skipLastUsed: true,
|
2017-10-07 19:17:43 +02:00
|
|
|
|
skipUsernameOnlyFill: !fromCommand
|
2017-10-07 19:10:04 +02:00
|
|
|
|
});
|
2017-08-28 19:00:46 +02:00
|
|
|
|
});
|
|
|
|
|
});
|
2017-08-29 18:52:11 +02:00
|
|
|
|
};
|
2017-08-28 19:00:46 +02:00
|
|
|
|
|
2016-12-30 08:09:54 +01:00
|
|
|
|
function loadPasswordFields(pageDetails, canBeHidden) {
|
|
|
|
|
var arr = [];
|
|
|
|
|
for (var i = 0; i < pageDetails.fields.length; i++) {
|
|
|
|
|
if (pageDetails.fields[i].type === 'password' && (canBeHidden || pageDetails.fields[i].viewable)) {
|
|
|
|
|
arr.push(pageDetails.fields[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return arr;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-21 18:38:52 +01:00
|
|
|
|
function findUsernameField(pageDetails, passwordField, canBeHidden, withoutForm) {
|
2016-12-30 08:09:54 +01:00
|
|
|
|
var usernameField = null;
|
|
|
|
|
for (var i = 0; i < pageDetails.fields.length; i++) {
|
|
|
|
|
var f = pageDetails.fields[i];
|
2017-01-21 18:38:52 +01:00
|
|
|
|
if (f.elementNumber >= passwordField.elementNumber) {
|
2016-12-30 08:09:54 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-21 18:38:52 +01:00
|
|
|
|
if ((withoutForm || f.form === passwordField.form) && (canBeHidden || f.viewable) &&
|
|
|
|
|
(f.type === 'text' || f.type === 'email' || f.type === 'tel')) {
|
2016-12-30 08:09:54 +01:00
|
|
|
|
usernameField = f;
|
2017-09-22 18:10:19 +02:00
|
|
|
|
|
|
|
|
|
if (findMatchingFieldIndex(f, usernameFieldNames) > -1) {
|
|
|
|
|
// We found an exact match. No need to keep looking.
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-12-30 08:09:54 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return usernameField;
|
|
|
|
|
}
|
2017-09-22 18:10:19 +02:00
|
|
|
|
|
|
|
|
|
function findMatchingFieldIndex(field, names) {
|
|
|
|
|
var matchingIndex = -1;
|
|
|
|
|
if (field.htmlID && field.htmlID !== '') {
|
|
|
|
|
matchingIndex = names.indexOf(field.htmlID.toLowerCase());
|
|
|
|
|
}
|
|
|
|
|
if (matchingIndex < 0 && field.htmlName && field.htmlName !== '') {
|
|
|
|
|
matchingIndex = names.indexOf(field.htmlName.toLowerCase());
|
|
|
|
|
}
|
|
|
|
|
if (matchingIndex < 0 && field['label-tag'] && field['label-tag'] !== '') {
|
|
|
|
|
matchingIndex = names.indexOf(field['label-tag'].replace(/(?:\r\n|\r|\n)/g, '').trim().toLowerCase());
|
|
|
|
|
}
|
|
|
|
|
if (matchingIndex < 0 && field.placeholder && field.placeholder !== '') {
|
|
|
|
|
matchingIndex = names.indexOf(field.placeholder.toLowerCase());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return matchingIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fieldIsFuzzyMatch(field, names) {
|
|
|
|
|
if (field.htmlID && field.htmlID !== '' && fuzzyMatch(names, field.htmlID.toLowerCase())) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (field.htmlName && field.htmlName !== '' && fuzzyMatch(names, field.htmlName.toLowerCase())) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (field['label-tag'] && field['label-tag'] !== '' &&
|
|
|
|
|
fuzzyMatch(names, field['label-tag'].replace(/(?:\r\n|\r|\n)/g, '').trim().toLowerCase())) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (field.placeholder && field.placeholder !== '' && fuzzyMatch(names, field.placeholder.toLowerCase())) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fuzzyMatch(options, value) {
|
|
|
|
|
if (!options || !options.length || !value || value === '') {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < options.length; i++) {
|
|
|
|
|
if (value.indexOf(options[i]) > -1) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-09-29 21:12:23 +02:00
|
|
|
|
|
|
|
|
|
function setFillScriptForFocus(filledFields, fillScript) {
|
|
|
|
|
var lastField = null,
|
|
|
|
|
lastPasswordField = null;
|
|
|
|
|
|
|
|
|
|
for (var opid in filledFields) {
|
|
|
|
|
if (filledFields.hasOwnProperty(opid) && filledFields[opid].viewable) {
|
|
|
|
|
lastField = filledFields[opid];
|
|
|
|
|
|
|
|
|
|
if (filledFields[opid].type === 'password') {
|
|
|
|
|
lastPasswordField = filledFields[opid];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Prioritize password field over others.
|
|
|
|
|
if (lastPasswordField) {
|
|
|
|
|
fillScript.script.push(['focus_by_opid', lastPasswordField.opid]);
|
|
|
|
|
}
|
|
|
|
|
else if (lastField) {
|
|
|
|
|
fillScript.script.push(['focus_by_opid', lastField.opid]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fillScript;
|
|
|
|
|
}
|
2017-07-14 21:34:05 +02:00
|
|
|
|
}
|