Skip to content

Instantly share code, notes, and snippets.

@fallenleavesguy
Created November 2, 2023 06:45
Show Gist options
  • Save fallenleavesguy/8f6b6ed06c2d12d7dec83058f814407d to your computer and use it in GitHub Desktop.
Save fallenleavesguy/8f6b6ed06c2d12d7dec83058f814407d to your computer and use it in GitHub Desktop.
observe undefined dom text
(function () {
function observeUndefinedValue(selector, cb) {
const targetNode = document.querySelector(selector);
if (!targetNode) {
return;
}
cb(targetNode);
const config = { attributes: false, childList: true, subtree: false };
const callback = (mutationList) => {
mutationList.forEach((mutation) => {
if (mutation.type === 'childList') {
cb(targetNode);
}
});
};
const observer = new MutationObserver(callback);
observer.observe(targetNode, config);
}
observeUndefinedValue('#zfu .red', (target) => {
if (target.innerText.startsWith('undefined')) {
target.style.display = 'none';
} else {
target.style.display = 'inline';
}
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment