Created
September 4, 2020 13:19
-
-
Save unel/dd6d8cb4c7cb460182da7dfef8c99284 to your computer and use it in GitHub Desktop.
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
function cleanup(node) { | |
const removeMe = | |
node instanceof Image | |
|| node instanceof Text | |
|| node instanceof Comment | |
|| node.tagName === 'svg' | |
|| node.tagName === 'iframe'; | |
const ignoreChilds = | |
node.tagName === 'svg' | |
|| node.tagName === 'iframe'; | |
if (node.textContent && !node.childNodes?.length) { | |
node.textContent = ''; | |
} | |
else if (node.childNodes?.length && !ignoreChilds) { | |
for (const child of node.childNodes) { | |
cleanup(child); | |
} | |
} | |
else if (removeMe) { | |
action = 'remove'; | |
node.remove(); | |
} | |
} | |
cleanup(document.body); | |
console.log('done'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment