Allow filling password for non-detected fields and combinations (#1580)

Allow filling password for non-detected fields and combinations
This commit is contained in:
Sami Vänttinen 2022-05-31 15:39:32 +03:00 committed by GitHub
parent 1a7975df93
commit 54b8ac79a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 42 deletions

View file

@ -23,62 +23,58 @@ kpxcFill.fillAttributeToActiveElementWith = async function(attr) {
// Fill requested from the context menu. Active element is used for combination detection
kpxcFill.fillInFromActiveElement = async function(passOnly = false) {
await kpxc.receiveCredentialsIfNecessary();
if (kpxc.credentials.length === 0) {
logDebug('Error: Credential list is empty.');
return;
}
if (kpxc.combinations.length > 0 && kpxc.settings.autoCompleteUsernames) {
const combination = passOnly
? kpxc.combinations.find(c => c.password)
: kpxc.combinations.find(c => c.username);
if (!combination) {
logDebug('Error: No combination found.');
return;
}
const field = passOnly ? combination.password : combination.username;
if (!field) {
logDebug('Error: No input field found.');
return;
}
// Set focus to the input field
field.focus();
if (kpxc.credentials.length > 1) {
// More than one credential -> show autocomplete list
kpxcUserAutocomplete.showList(field);
return;
} else {
// Just one credential -> fill the first combination found
await sendMessage('page_set_login_id', kpxc.credentials[0].uuid);
kpxcFill.fillInCredentials(combination, kpxc.credentials[0].login, kpxc.credentials[0].uuid, passOnly);
if (await kpxcFill.fillFromCombination(passOnly)) {
// Combination found and filled
return;
}
}
// No previous combinations detected. Create a new one from active element
const el = document.activeElement;
let combination;
if (kpxc.combinations.length === 0) {
combination = await kpxc.createCombination(el);
} else {
combination = el.type === 'password'
? await kpxcFields.getCombination(el, 'password')
: await kpxcFields.getCombination(el, 'username');
}
// Do not allow filling password to a non-password field
if (passOnly && combination && !combination.password) {
kpxcUI.createNotification('warning', tr('fieldsNoPasswordField'));
return;
}
const combination = await kpxc.createCombination(el, passOnly);
await sendMessage('page_set_login_id', kpxc.credentials[0].uuid);
kpxcFill.fillInCredentials(combination, kpxc.credentials[0].login, kpxc.credentials[0].uuid, passOnly);
};
// Fill from combination, if found
kpxcFill.fillFromCombination = async function(passOnly) {
const combination = passOnly
? kpxc.combinations.find(c => c.password)
: kpxc.combinations.find(c => c.username);
if (!combination) {
logDebug('Error: No combination found.');
return false;
}
const field = passOnly ? combination.password : combination.username;
if (!field) {
logDebug('Error: No input field found.');
return false;
}
// Set focus to the input field
field.focus();
if (kpxc.credentials.length > 1) {
// More than one credential -> show autocomplete list
kpxcUserAutocomplete.showList(field);
} else {
// Just one credential -> fill the first combination found
await sendMessage('page_set_login_id', kpxc.credentials[0].uuid);
kpxcFill.fillInCredentials(combination, kpxc.credentials[0].login, kpxc.credentials[0].uuid, passOnly);
}
return true;
};
// Fill requested by Auto-Fill
kpxcFill.fillFromAutofill = async function() {
if (kpxc.credentials.length !== 1 || kpxc.combinations.length === 0) {

View file

@ -72,15 +72,21 @@ kpxc.clearAllFromPage = function() {
};
// Creates a new combination manually from active element
kpxc.createCombination = async function(activeElement) {
kpxc.createCombination = async function(activeElement, passOnly) {
const combination = {
username: null,
password: null,
passwordInputs: [],
form: activeElement.form
form: null
};
if (activeElement.getLowerCaseAttribute('type') === 'password') {
if (!activeElement) {
return combination;
}
combination.form = activeElement.form;
if (passOnly || activeElement.getLowerCaseAttribute('type') === 'password') {
combination.password = activeElement;
} else {
combination.username = activeElement;