Allows you to easily modify HTML elements on websites.
A small utility library to simplify working with the MutationObserver
browser API.
You register a CSS selector and a callback function. When started, the callback function will be called when any element matching the selector appears in the DOM. Suitable for static websites as well as dynamic web apps.
- Import or copy-paste the script to your code
- Register your selector and callback using
ModifyElement.registerSelector
- Start the observer using
ModifyElement.start
The library exports a single global variable called ModifyElement
which provides the public API.
Register a new selector and a callback function. The callback will be called whenever a new element matching the selector appears in the DOM.
selector
Selector matching the target elementcallback
Callback function to call with the element
Remove the registered callback.
selector
Selector assigned with the callbackcallback
Callback function to remove
Start observing the root element. This applies all registered selectors and starts the MutationObserver.
rootElement
Root element to observe, usually this can bedocument.documentElement
Stop observing the root element.
Clone the repository locally first. This project uses npm
so call npm install
to install
the dependencies. Then there are these important scripts:
npm build
- Build a development versionnpm build:min
- Build a production version (minified)npm build:watch
- Watch source files and rebuild
See #1.