UNPKG

@stolbivi/pirojok

Version:

Some minimalistic library used to build chrome extensions, covers some popular Chrome Extension API

42 lines (41 loc) 1.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DynamicUI = void 0; /** * A utility class for observing and reacting to DOM mutations * Provides methods to watch for changes in the DOM tree and execute callbacks */ var DynamicUI = /** @class */ (function () { function DynamicUI() { } /** * Sets up a mutation observer on a target node with specified options * @param target - The DOM node to observe * @param options - Configuration options for the mutation observer * @returns The MutationObserver instance */ DynamicUI.prototype.watch = function (target, options) { var MutationObserver = window.MutationObserver; var observer = new MutationObserver(function (ms) { return ms.forEach(function (m) { // console.log("Mutation:", m); if (m.type === 'childList') { m.addedNodes.forEach(function (node) { if (options.onAdd) { options.onAdd(node); } }); m.removedNodes.forEach(function (node) { if (options.onRemove) { options.onRemove(m.target, node); } }); } }); }); observer.observe(target, options); return observer; }; return DynamicUI; }()); exports.DynamicUI = DynamicUI;