Created
September 6, 2011 04:23
-
-
Save ELLIOTTCABLE/1196576 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <script type='text/javascript'>var onAllText, replaceText, slice = Array.prototype.slice; | |
| onAllText = function(_){ return function(parentNode){ | |
| slice.apply(parentNode.childNodes).forEach(function(childNode){ | |
| switch(childNode.nodeType) { case Node.ELEMENT_NODE: onAllText(_)(childNode); break; | |
| case Node.TEXT_NODE: _ (childNode); break; | |
| default: console.log(new(Error)("What the fuck is this shit?"), | |
| childNode)} }) }} | |
| replaceText = function(textNode, query, replacement){ var index; var before, after; | |
| replacement = replacement.cloneNode(true); | |
| if ( (index = textNode.nodeValue.indexOf(query)) !== -1 ) { | |
| before = document.createTextNode( textNode.nodeValue.substr(0, index) ) | |
| after = document.createTextNode( textNode.nodeValue.substr(index + query.length) ) | |
| textNode.parentNode.insertBefore(replacement, textNode) | |
| textNode.parentNode.insertBefore(before, replacement) | |
| textNode.parentNode.replaceChild(after, textNode) }} | |
| window.onBodyLoad = function(){ var pawsNode; | |
| // All of this, just to avoid innerHTML. >,> | |
| pawsNode = document.createElement('span'); pawsNode.classList.add('vanity') | |
| pawsNode.appendChild(document.createTextNode('Paws')) | |
| slice.apply(document.getElementsByTagName('p')).forEach( onAllText(function(textNode){ | |
| replaceText(textNode, 'Paws', pawsNode) })) | |
| } | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment