1.0.1 • Published 10 years ago

replace-all-text-nodes v1.0.1

Weekly downloads
5
License
GPL-3.0
Repository
github
Last release
10 years ago

replace-all-text-nodes

Does what the name says. Replace all text nodes on the page (i.e. all text on the page), with an option to use a MutationObserver or repeat full-page replacement periodically to continue replacing text for new elements added via javascript.

Created for use in imposters and concentraitor.

API

function replaceAllFromNode(node, replaceFn, opts) {
  • node: the node to begin the tree search at. This works recursively downwards.
  • replaceFn: a function which replaces text. This can be done in any way desired.
  • opts: an object with any of the following keys:
    • inputsToo: if truthy, also modifies any input boxes. Note that this may cause performance issues or unexpected UI behavior as the user will have their text replaced while typing.
    • notNow: doesn't immediately call replaceAll
    • timeouts: array of milliseconds, at which replaceAll will run over the document again. These milliseconds are all relative to the point when this function was called, not to each other.
    • repeat: milliseconds to repeat running replaceAllFromNode (this is not encouraged; a MutationObserver used by futureNodesToo is preferable for performance reasons unless supporting older browsers which do not support MutationObserver)
    • futureNodesToo: adds a MutationObserver to the page, mutating all elements added to the page. If this is specified, the function returns the MutationObserver used so that it can be started and stopped as desired.
function replaceAllInPage(replaceFn, opts) {

Convenience method which calls replaceAllFromNode with node set to document.

function watchFutureNodes(replaceFn, opts) {

Implementation of futureNodesToo in replaceAllInPage. Creates and returns a MutationObserver which applies replaceFn to any added or modified text nodes when started.

To Use

Installation:

npm install --save replace-all-text-nodes
browserify -r replace-all-text-nodes your-script.js -o output.js

In your-script.js:

var ReplaceNodes = require('replace-all-text-nodes');
ReplaceNodes.replaceAllInPage(...);
1.0.1

10 years ago

1.0.0

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago

0.0.0

10 years ago