1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-27 12:36:14 +01:00

support for label left/top and more intel. selects

This commit is contained in:
Kyle Spearrin 2017-12-06 09:11:37 -05:00
parent e1158828ec
commit 41d615a8fe

View File

@ -10,10 +10,10 @@ import TotpService from './totp.service';
import UtilsService from './utils.service'; import UtilsService from './utils.service';
const CardAttributes: string[] = ['autoCompleteType', 'data-stripe', 'htmlName', 'htmlID', 'label-tag', const CardAttributes: string[] = ['autoCompleteType', 'data-stripe', 'htmlName', 'htmlID', 'label-tag',
'placeholder']; 'placeholder', 'label-left', 'label-top'];
const IdentityAttributes: string[] = ['autoCompleteType', 'data-stripe', 'htmlName', 'htmlID', 'label-tag', const IdentityAttributes: string[] = ['autoCompleteType', 'data-stripe', 'htmlName', 'htmlID', 'label-tag',
'placeholder']; 'placeholder', 'label-left', 'label-top'];
const UsernameFieldNames: string[] = ['username', 'user name', 'email', 'email address', 'e-mail', 'e-mail address', const UsernameFieldNames: string[] = ['username', 'user name', 'email', 'email address', 'e-mail', 'e-mail address',
'userid', 'user id']; 'userid', 'user id'];
@ -483,11 +483,9 @@ export default class AutofillService {
if (year.length === 2) { if (year.length === 2) {
year = '20' + year; year = '20' + year;
} }
const exp = year + '-' + ('0' + card.expMonth).slice(-2);
filledFields[fillFields.exp.opid] = fillFields.exp; const exp = year + '-' + ('0' + card.expMonth).slice(-2);
fillScript.script.push(['click_on_opid', fillFields.exp.opid]); this.makeScriptActionWithValue(fillScript, exp, fillFields.exp, filledFields);
fillScript.script.push(['fill_by_opid', fillFields.exp.opid, exp]);
} }
return fillScript; return fillScript;
@ -588,9 +586,7 @@ export default class AutofillService {
const isoState = IsoStates[stateLower] || IsoProvinces[stateLower]; const isoState = IsoStates[stateLower] || IsoProvinces[stateLower];
if (isoState) { if (isoState) {
filledState = true; filledState = true;
filledFields[fillFields.state.opid] = fillFields.state; this.makeScriptActionWithValue(fillScript, isoState, fillFields.state, filledFields);
fillScript.script.push(['click_on_opid', fillFields.state.opid]);
fillScript.script.push(['fill_by_opid', fillFields.state.opid, isoState]);
} }
} }
@ -604,9 +600,7 @@ export default class AutofillService {
const isoCountry = IsoCountries[countryLower]; const isoCountry = IsoCountries[countryLower];
if (isoCountry) { if (isoCountry) {
filledCountry = true; filledCountry = true;
filledFields[fillFields.country.opid] = fillFields.country; this.makeScriptActionWithValue(fillScript, isoCountry, fillFields.country, filledFields);
fillScript.script.push(['click_on_opid', fillFields.country.opid]);
fillScript.script.push(['fill_by_opid', fillFields.country.opid, isoCountry]);
} }
} }
@ -632,9 +626,7 @@ export default class AutofillService {
fullName += identity.lastName; fullName += identity.lastName;
} }
filledFields[fillFields.name.opid] = fillFields.name; this.makeScriptActionWithValue(fillScript, fullName, fillFields.name, filledFields);
fillScript.script.push(['click_on_opid', fillFields.name.opid]);
fillScript.script.push(['fill_by_opid', fillFields.name.opid, fullName]);
} }
if (fillFields.address && identity.address1 && identity.address1 !== '') { if (fillFields.address && identity.address1 && identity.address1 !== '') {
@ -655,9 +647,7 @@ export default class AutofillService {
address += identity.address3; address += identity.address3;
} }
filledFields[fillFields.address.opid] = fillFields.address; this.makeScriptActionWithValue(fillScript, address, fillFields.address, filledFields);
fillScript.script.push(['click_on_opid', fillFields.address.opid]);
fillScript.script.push(['fill_by_opid', fillFields.address.opid, address]);
} }
return fillScript; return fillScript;
@ -680,10 +670,40 @@ export default class AutofillService {
private makeScriptAction(fillScript: AutofillScript, cipherData: any, fillFields: any, private makeScriptAction(fillScript: AutofillScript, cipherData: any, fillFields: any,
filledFields: { [id: string]: AutofillField; }, dataProp: string, fieldProp?: string) { filledFields: { [id: string]: AutofillField; }, dataProp: string, fieldProp?: string) {
fieldProp = fieldProp || dataProp; fieldProp = fieldProp || dataProp;
if (cipherData[dataProp] && cipherData[dataProp] !== '' && fillFields[fieldProp]) { this.makeScriptActionWithValue(fillScript, cipherData[dataProp], fillFields[fieldProp], filledFields);
filledFields[fillFields[fieldProp].opid] = fillFields[fieldProp]; }
fillScript.script.push(['click_on_opid', fillFields[fieldProp].opid]);
fillScript.script.push(['fill_by_opid', fillFields[fieldProp].opid, cipherData[dataProp]]); private makeScriptActionWithValue(fillScript: AutofillScript, dataValue: any, field: any,
filledFields: { [id: string]: AutofillField; }) {
let doFill = false;
if (dataValue && dataValue !== '' && field) {
if (field.type === 'select-one' && field.selectInfo && field.selectInfo.options) {
for (let i = 0; i < field.selectInfo.options.length; i++) {
const option = field.selectInfo.options[i];
for (let j = 0; j < option.length; j++) {
if (option[j].toLowerCase() === dataValue.toLowerCase()) {
doFill = true;
if (option.length > 1) {
dataValue = option[1];
}
break;
}
}
if (doFill) {
break;
}
}
} else {
doFill = true;
}
}
if (doFill) {
filledFields[field.opid] = field;
fillScript.script.push(['click_on_opid', field.opid]);
fillScript.script.push(['fill_by_opid', field.opid, dataValue]);
} }
} }