Skip to content

Latest commit

 

History

History
33 lines (30 loc) · 1.28 KB

README.md

File metadata and controls

33 lines (30 loc) · 1.28 KB

waitForKeyElements()

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

Installation

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.

Usage

With selector string

waitForKeyElements("div.comments", (element) => {
  element.innerHTML = "This text inserted by waitForKeyElements().";
});

With selector function

waitForKeyElements(() => {
  const iframe = document.querySelector('iframe');
  if (iframe) {
    const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
    return iframeDoc.querySelectorAll("div.comments");
  }
  return null;
}, callbackFunc);