Last active
October 13, 2018 20:15
-
-
Save spacekitcat/d46dbb01facd9a4481b367e52b3fe8ac to your computer and use it in GitHub Desktop.
Walks the DOM and performs text replacements. Designed for use with https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doReplace = function(doc) { | |
var treeWalker = document.createTreeWalker(doc, NodeFilter.SHOW_TEXT, null, null) | |
do { | |
var tmpnode = treeWalker.currentNode; | |
if (tmpnode.nodeValue) { | |
tmpnode.nodeValue = tmpnode.nodeValue.replace(/gamergate/ig, 'misogynist'); | |
tmpnode.nodeValue = tmpnode.nodeValue.replace(/trump/ig, 'misogynist'); | |
tmpnode.nodeValue = tmpnode.nodeValue.replace(/donald trump/ig, 'misogynist'); | |
treeWalker.currentNode = tmpnode; | |
} | |
} while (treeWalker.nextNode()); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment