mirror of
https://github.com/keepassxreboot/keepassxc-browser.git
synced 2026-03-11 08:54:43 +00:00
Improved dynamic input field detection
This commit is contained in:
parent
a01109e345
commit
02f766fc52
1 changed files with 28 additions and 15 deletions
|
|
@ -1140,7 +1140,34 @@ cipFields.useDefinedCredentialFields = function() {
|
|||
return false;
|
||||
};
|
||||
|
||||
MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
|
||||
|
||||
// Detects DOM changes in the document
|
||||
let observer = new MutationObserver(function(mutations, observer) {
|
||||
if (document.visibilityState === 'hidden') {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const mut of mutations) {
|
||||
if (mut.type === 'childList') {
|
||||
const fields = cipFields.getAllFields();
|
||||
|
||||
// If only password field is shown it's enough to have one field visible for initCredentialFields
|
||||
if (fields.length > (_detectedFields == 1 ? 0 : 1)) {
|
||||
cip.initCredentialFields(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// define what element should be observed by the observer
|
||||
// and what types of mutations trigger the callback
|
||||
observer.observe(document, {
|
||||
subtree: true,
|
||||
attributes: true,
|
||||
childList: true,
|
||||
characterData: true
|
||||
});
|
||||
|
||||
var cip = {};
|
||||
cip.settings = {};
|
||||
|
|
@ -1152,7 +1179,7 @@ cip.credentials = [];
|
|||
|
||||
jQuery(function() {
|
||||
cip.init();
|
||||
cip.detectNewActiveFields();
|
||||
cip.detectDatabaseChange();
|
||||
});
|
||||
|
||||
cip.init = function() {
|
||||
|
|
@ -1164,20 +1191,6 @@ cip.init = function() {
|
|||
});
|
||||
};
|
||||
|
||||
cip.detectNewActiveFields = function() {
|
||||
const divDetect = setInterval(function() {
|
||||
if (document.visibilityState !== 'hidden') {
|
||||
const fields = cipFields.getAllFields();
|
||||
|
||||
// If only password field is shown it's enough to have one field visible for initCredentialFields
|
||||
if (fields.length > (_detectedFields == 1 ? 0 : 1)) {
|
||||
cip.initCredentialFields(true);
|
||||
clearInterval(divDetect);
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
// Switch credentials if database is changed or closed
|
||||
cip.detectDatabaseChange = function(response) {
|
||||
if (document.visibilityState !== 'hidden') {
|
||||
|
|
|
|||
Loading…
Reference in a new issue