Answer the question
In order to leave comments, you need to log in
Replacing specific text on a page with JS?
Greetings! I recently started learning JavaScript, but I still don't understand anything about it. There was an idea to create an extension for the FireFox browser. He is required to replace specific text on the page with another. I have tried many options, in particular from here . The problem is this: when you install the extension in the browser through the debug menu, all the necessary text is replaced. When the page is refreshed, the replacement in some buttons and other elements disappears. I don't understand what it is, any help would be greatly appreciated.
Answer the question
In order to leave comments, you need to log in
It is strictly forbidden to use innerHTML for text autoreplacement, since when using it, handlers on elements will fly off, you will break the site so easily.
To auto-replace text, simply iterate through all the text nodes on the page and specifically change and correct them (text nodes) as you need.
This will help you:
How to loop through all text nodes on a page?
Because AJAX and the internal logic of the website?
The web has been dynamic for a long time, and this must be taken into account.
There is such a thing as an observer ( MutationObserver ), you hang it after applying your changes and inside it you execute it again, for a specific element if it contains the desired text that needs to be replaced.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question