Element Creation Hook

A small wrapper around MutationObserver to hook into creation of elements based on a CSS selector.

Script này sẽ không được không được cài đặt trực tiếp. Nó là một thư viện cho các script khác để bao gồm các chỉ thị meta // @require https://update.greasyfork.org/scripts/565361/1749989/Element%20Creation%20Hook.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Element Creation Hook
// @namespace   https://greasyfork.org/users/1545341
// @version     1.0.0
// @license     MIT
// @author      abcenjoyer
// @description A small wrapper around MutationObserver to hook into creation of elements based on a CSS selector.
// ==/UserScript==

function hookCreation(selector, callback) {
  const observer = new MutationObserver((mutations) => {
    const element = document.querySelector(selector);

    if (element) {
      callback(element);
      observer.disconnect();
    }
  });

  observer.observe(document.documentElement, {
    childList: true,
    subtree: true,
    attributes: true,
    characterData: true
  });
}