Skip to content

Instantly share code, notes, and snippets.

@nkhil

nkhil/brexit.js

Created Oct 12, 2018
Embed
What would you like to do?
var elementsInsideBody = [...document.body.getElementsByTagName('*')];
// This makes an array of everything inside the body tag
//a function that loops through every single item
function findAndReplace(){
elementsInsideBody.forEach(element =>{
element.childNodes.forEach(child =>{
if(child.nodeType === 3){
replaceText(child);
}
});
});
}
function replaceText (node) {
let value = node.nodeValue;
value = value.replace(/Brexit/gi, 'Breadsticks');
value = value.replace(/brexit/gi, 'breadsticks');
node.nodeValue = value;
}
window.onload = findAndReplace();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment