0

I am trying to find a way to replace certain text on the webpage without the use of chrome extensions.

For example, I want the text 'dogs' to replace with 'doggos' each time the web page detects the word dogs. Is it possible to do this without the use of Chrome Extensions? How can I write such a script and can this run in the backgroun?

Thanks all!

user2768498
  • 155
  • 1
  • 2
  • 9
  • You can't modify pages automatically without an extension or an external MitM tool like Fiddler. – wOxxOm Sep 19 '19 at 07:58

1 Answers1

0

Use Chrome Dev Tools

If you want to use chrome, but not a chrome extension, you want to use the console in the Chrome Dev Tools. Running a script for a website on the Chrome Console is a solution to your question, and is shown below, but it will disappear when you refresh the page.

Replacing String Literals in the Body

To replace all instances of dogs with doggos in the HTML body, you would walk the document tree as documented by this SO question.

Applied to your question, the result is below:

Replacing body text

Further Reading

You may also want to check out javascript with Regular Expressions, which are more powerful than a simple string replace. If you want this running in the background, you should look at Mutation Observers to check whether the DOM has changed.

Ross Jacobs
  • 2,962
  • 1
  • 17
  • 27
  • Thanks for pointing that out. I've fixed the answer to point to the walk the DOM solution. – Ross Jacobs Sep 19 '19 at 08:41
  • The OP didn't say they wanted this to work on more than their own computer, so I think using the console is valid here. It should be possible to copy and paste Javascript into the console that will monitor for changes in the DOM and replace text by walking the tree. OP will *probably* want to have the script run inside of a chrome extension as that would make more sense, but that's not what they asked. – Ross Jacobs Sep 19 '19 at 08:47
  • Well, the question's main point is automatic replacement so this answer isn't really helpful. Like I said above there's no solution with the given constraints. – wOxxOm Sep 19 '19 at 09:33