A utility function for userscripts that detects and handles AJAXed content.
Forked from the original with major improvements, including:
- does not require jQuery
- avoids the quirks associated with
setInterval()
- optionally takes a function instead of a string for querying elements on page
Add the following to your userscript's metadata block:
// @require https://cdn.jsdelivr.net/gh/CoeJoder/[email protected]/waitForKeyElements.js
If your userscript was already installed, you'll have to reinstall it to pickup the change. See documentation.
waitForKeyElements("div.comments", (element) => {
element.innerHTML = "This text inserted by waitForKeyElements().";
});
waitForKeyElements(() => {
const iframe = document.querySelector('iframe');
if (iframe) {
const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
return iframeDoc.querySelectorAll("div.comments");
}
return null;
}, callbackFunc);