Skip to content

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

Notifications You must be signed in to change notification settings

pekul/waitForKeyElements.js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 

Repository files navigation

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);

About

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

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%