Skip to content

Instantly share code, notes, and snippets.

@nkhil
Created October 12, 2018 09:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkhil/befbaa8a9722e92db091f47a66fde7ca to your computer and use it in GitHub Desktop.
Save nkhil/befbaa8a9722e92db091f47a66fde7ca to your computer and use it in GitHub Desktop.
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