ArnoldDeRuiter / waitForKeyElements.js

A utility function for userscripts that detects and handles AJAXed content.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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/waitForKeyElements.js@v1.2/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);

Additional Resources

This function is part of the Greasemonkey Wrench library.

About

A utility function for userscripts that detects and handles AJAXed content.


Languages

Language:JavaScript 100.0%