Last active
April 16, 2026 19:28
-
-
Save mindfullsilence/74deed11a1195363da0a4e3bbacffb5c to your computer and use it in GitHub Desktop.
replace-text.js
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
| ;(() => { | |
| const find = 'Available Now' // the text you want to find (not case sensitive) | |
| const replace = 'COMING SOON' // the text you want to replace it with | |
| // IGNORE THE REST BELOW | |
| const findReplace = (node, find, replace) => { | |
| const next = () => findReplace(node, find, replace) | |
| if ( ! node ) { | |
| return next | |
| } | |
| if (node.nodeType === Node.TEXT_NODE && node.nodeValue.trim() !== '') { | |
| if ( node.nodeValue.trim().toLowerCase() === find.toLowerCase() ) { | |
| node.nodeValue = replace | |
| } | |
| } | |
| for (let i = 0; i < node.childNodes.length; i++) { | |
| findReplace(node.childNodes[i], find, replace); | |
| } | |
| return next | |
| } | |
| document.addEventListener('DOMContentLoaded', findReplace(document.body, find, replace)) | |
| })() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note this script invokes immediately, as well as once the dom is loaded. To scope it to specific elements, simply call once for each element:
This script is a bit computationally heavy considering its a recursive dom manipulator, but running it on very large pages hasn't seemed to have any meaningful impact thus far.