Last active
August 28, 2020 10:30
-
-
Save o0101/acd50bedeb1335065763e50d4783f711 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
"use strict"; | |
{ | |
const forbidden = new Set(["Facebook", "Zuckerberg", "Trump", "alt-left", "Syria", "Trump's", "racist", "liberal", "alt-right"]); | |
const tw = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT); const actions = []; | |
while( tw.nextNode() ) { | |
const text = tw.currentNode; | |
if ( text.parentElement.tagName !== 'SCRIPT' && text.parentElement.tagName !== 'STYLE' ) { | |
actions.push( () => redact( text, forbidden )); | |
} | |
}; actions.forEach( a => a() ); | |
function redact( t, e ) { | |
const p = t.parentElement; | |
if ( ! p ) { | |
return; | |
} | |
const converted = t.textContent.split(/\s/g).map( word => { | |
if ( e.has(word) ) { | |
const s = document.createElement('span'); | |
s.style = "color:black;background:black;"; | |
s.innerText = word + " "; | |
return s; | |
} else return word + " "; | |
}); | |
t.replaceWith( ...converted ); | |
p.normalize(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment