-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwordchanger.js
More file actions
1 lines (1 loc) · 899 Bytes
/
wordchanger.js
File metadata and controls
1 lines (1 loc) · 899 Bytes
1
javascript:(function(){ var originalWord = prompt("Enter the word to replace:"); var newWord = prompt("Enter the new word:"); if (originalWord && newWord) { var bodyElements = document.getElementsByTagName("*"); for (var i = 0; i < bodyElements.length; i++) { var element = bodyElements[i]; for (var j = 0; j < element.childNodes.length; j++) { var node = element.childNodes[j]; if (node.nodeType === Node.TEXT_NODE) { var text = node.nodeValue; var replacedText = text.replace(new RegExp(originalWord, "gi"), newWord); if (replacedText !== text) { element.replaceChild(document.createTextNode(replacedText), node); } } } } alert("All instances of \"" + originalWord + "\" have been replaced with \"" + newWord + "\"."); } else { alert("Please enter both the original and the new word."); }})();