Skip to content

Instantly share code, notes, and snippets.

@johnmccole
Created January 12, 2018 12:09
Show Gist options
  • Save johnmccole/888bb3cc3ac201b065db76fb4acf9cfe to your computer and use it in GitHub Desktop.
Save johnmccole/888bb3cc3ac201b065db76fb4acf9cfe to your computer and use it in GitHub Desktop.
Add clean.js to remove all useless nodes from the document.
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