Fix observation of mutated elements

Needs to be installed after DOM loaded.
This commit is contained in:
Adrian Vollmer 2024-04-22 20:28:06 +02:00
parent a479b350e9
commit 2399acaabd
2 changed files with 22 additions and 18 deletions

View File

@ -57,24 +57,6 @@ var onScrollToAnchor = function(argument) {
} }
const observer = new MutationObserver((mutationList) => {
// console.log("Fix mutated elements...", mutationList);
mutationList.forEach((mutation) => {
if (mutation.type == 'childList') {
Array.from(mutation.target.querySelectorAll("a")).forEach( a => {
fixLink(a);
});
Array.from(mutation.target.querySelectorAll("img")).forEach( img => {
embedImg(img);
});
Array.from(mutation.target.querySelectorAll("form")).forEach( form => {
fixForm(form);
});
}
});
});
var monkeyPatch = function() { var monkeyPatch = function() {
if (typeof jQuery === 'undefined') {return;} // Only for jQuery at the moment if (typeof jQuery === 'undefined') {return;} // Only for jQuery at the moment
/** /**

View File

@ -108,3 +108,25 @@ window.fetch = async (...args) => {
} }
return response; return response;
}; };
const observer = new MutationObserver((mutationList) => {
console.log("Fix mutated elements...", mutationList);
mutationList.forEach((mutation) => {
if (mutation.type == 'childList') {
Array.from(mutation.target.querySelectorAll("a")).forEach( a => {
fixLink(a);
});
Array.from(mutation.target.querySelectorAll("img")).forEach( img => {
embedImg(img);
});
Array.from(mutation.target.querySelectorAll("form")).forEach( form => {
fixForm(form);
});
}
});
});
document.addEventListener('DOMContentLoaded', function (event) {
observer.observe(window.document.body, {subtree: true, childList: true});
});