npm.io
1.0.11 • Published 6 years ago

element-mutator-lib

Licence
MIT
Version
1.0.11
Deps
0
Size
6 kB
Vulns
0
Weekly
0

Not for a production!

It is for my "home" project and it has not unit tests and it is my playground. I strongly recommend to don't use it in production.

Installation

npm install element-mutator-lib

How to use

Example 1. Run after page is loaded and track all DOM changes.

import ElementMutator from 'element-mutator-lib';

const elementMutator = new ElementMutator({attributeFilter: []}, (cfg, node, attributeName) => {
    // do something
    elementMutator.stop(); // stop
});

Example 2. Track a specific DOM node and all his descendants (<body> body tag in that case).

import ElementMutator from 'element-mutator-lib';

const elementMutator = new ElementMutator({attributeFilter: [], node: document.body}, (cfg, node, attributeName) => {
    // do something
    elementMutator.stop(); // stop
});

Example 3. Track a specific DOM node attributes (href attribute in that case). If attributeName is undefined then mutation is a non attribute mutation.

import ElementMutator from 'element-mutator-lib';

const elementMutator = new ElementMutator({attributeFilter: [href]}, (cfg, node, attributeName) => {
    // do something
    elementMutator.stop(); // stop
});