Created
November 2, 2023 06:45
-
-
Save fallenleavesguy/8f6b6ed06c2d12d7dec83058f814407d to your computer and use it in GitHub Desktop.
observe undefined dom text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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