HTML Find/Replace before display

Subscribe to HTML Find/Replace before display 6 posts, 5 voices

 
Dennis M. User

I would like a script that would do a find/replace on HTML before displaying it. There are keywords that I would like to change the color on. I would like to be able to search for "- OPEN -" and change it to "<font>- OPEN -</font>" for example.

 
vOidSenses Scriptwright

you can change the "- OPEN -" to "<font>- OPEN -</font>" but you can't do that before the original page is displayed, thats because greasemonkey script only get executed after the page is fully loaded, and when this happens the page is already displayed

 
Joel H Scriptwright

While voidsenses is technically right, a small script like this should be quick enough that you wouldn't notice the page before it changed, and after it did, you would only see it with different colors.

-Joel

 
vOidSenses Scriptwright

true, actually i normally only notice the scripts working when the pages are somehow heavy, like full of images to load

 
Brad Stewart Scriptwright

If you're wanting to do this just for a specific site, you could do something like this:

1. When a page on the site loads, change every link to add a "click" event listener
2. When the event listener catches a click, prevent Firefox from opening the link
3. Instead, fetch the HTML of the page using an XMLHttpRequest
4. Filter the HTML to make the changes you want
5. display your now-changed HTML

It's a fairly complicated solution -- a simple, quick search and replace might work just a well -- but something like this would do if you absolutely needed to make the changes before the page is displayed.

 
alien_scum Scriptwright

Brad: that is quite cunning.
On the other hand if there is a tag you can get using CSS selectors you could use stylish (which loads before the site) to do the reformatting.