Merge pull request #117 from keepassxreboot/improved_input_detection

Improved dynamic input field detection
This commit is contained in:
Janek Bevendorff 2018-05-10 12:32:01 +02:00 committed by GitHub
commit 6cc811f495
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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') {