Created
January 12, 2018 12:09
-
-
Save johnmccole/888bb3cc3ac201b065db76fb4acf9cfe to your computer and use it in GitHub Desktop.
Add clean.js to remove all useless nodes from the document.
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
function clean(node) | |
{ | |
for(var n = 0; n < node.childNodes.length; n ++) | |
{ | |
var child = node.childNodes[n]; | |
if | |
( | |
child.nodeType === 8 || (child.nodeType === 3 && !/\S/.test(child.nodeValue)) | |
) | |
{ | |
node.removeChild(child); | |
n --; | |
} | |
else if(child.nodeType === 1) | |
{ | |
clean(child); | |
} | |
} | |
} | |
clean(document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment