1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-25 16:59:17 +01:00

notification bar detection improvements

This commit is contained in:
Kyle Spearrin 2017-01-21 16:55:15 -05:00
parent c2c65baadb
commit e288ade266

View File

@ -50,39 +50,63 @@
} }
if (form) { if (form) {
forms[i].formElement = form; var formDataObj = {
formData.push(forms[i]); data: forms[i],
formEl: form,
usernameEl: null,
passwordEl: null
};
locateFields(formDataObj);
formData.push(formDataObj);
form.addEventListener('submit', formSubmitted, false); form.addEventListener('submit', formSubmitted, false);
} }
} }
} }
function locateFields(formDataObj) {
var passwordId = formDataObj.data.password ? formDataObj.data.password.htmlID : null,
usernameId = formDataObj.data.username ? formDataObj.data.username.htmlID : null,
passwordName = formDataObj.data.password ? formDataObj.data.password.htmlName : null,
usernameName = formDataObj.data.username ? formDataObj.data.username.htmlName : null,
inputs = document.getElementsByTagName('input');
if (passwordId && passwordId !== '') {
formDataObj.passwordEl = formDataObj.formEl.querySelector('#' + passwordId);
}
if (!formDataObj.passwordEl && passwordName !== '') {
formDataObj.passwordEl = formDataObj.formEl.querySelector('input[name="' + passwordName + '"]');
}
if (!formDataObj.passwordEl && formDataObj.passwordEl) {
formDataObj.passwordEl = inputs[formDataObj.data.password.elementNumber];
if (formDataObj.passwordEl && formDataObj.passwordEl.type !== 'password') {
formDataObj.passwordEl = null;
}
}
if (!formDataObj.passwordEl) {
formDataObj.passwordEl = formDataObj.formEl.querySelector('input[type="password"]');
}
if (usernameId && usernameId !== '') {
formDataObj.usernameEl = formDataObj.formEl.querySelector('#' + usernameId);
}
if (!formDataObj.usernameEl && usernameName !== '') {
formDataObj.usernameEl = formDataObj.formEl.querySelector('input[name="' + usernameName + '"]');
}
if (!formDataObj.usernameEl && formDataObj.data.username) {
formDataObj.usernameEl = inputs[formDataObj.data.username.elementNumber];
}
}
function formSubmitted(e) { function formSubmitted(e) {
for (var i = 0; i < formData.length; i++) { for (var i = 0; i < formData.length; i++) {
if (formData[i].formElement === e.target) { if (formData[i].formEl === e.target) {
var password = null, if (!formData[i].usernameEl || !formData[i].passwordEl) {
username = null, break;
passwordId = formData[i].password ? formData[i].password.htmlID : null,
usernameId = formData[i].username ? formData[i].username.htmlID : null,
inputs = document.getElementsByTagName('input');
if (passwordId && passwordId !== '') {
password = document.getElementById(passwordId);
}
else if (formData[i].password) {
password = inputs[formData[i].password.elementNumber];
}
if (usernameId && usernameId !== '') {
username = document.getElementById(usernameId);
}
else if (formData[i].username) {
username = inputs[formData[i].username.elementNumber];
} }
var login = { var login = {
username: username.value, username: formData[i].usernameEl.value,
password: password.value, password: formData[i].passwordEl.value,
url: document.URL url: document.URL
}; };