Is there any way to make a user Javascript file that will replace every instance of a certain string with another?
Yes.
I'd go so far as to say there's probably several.
I want to know if it can be done in a bookmarklet. That would be hilarious for pranking.
Okay, cool. Like, can someone post one?
javascript:(function(){document.body.innerHTML=document.body.innerHTML.replace(new RegExp(prompt('regex?'),'g'),prompt('replacement string?'))})()
someString.replace()
Look into it.
javascript:(function(){document.body.innerHTML=document.body.innerHTML.replace(new RegExp(prompt('regex?'),'g'),prompt('replacement string?'))})()
^-- This doesn't work for me.
javascript:(function(){document.body.innerHTML=document.body.innerHTML.replace(prompt('find?'),prompt('replacement string?'))})()
^-- This doesn't work either.
I tested them by bookmarking them and running them on this page. No resulting changes, but on the other hand no errors either.
javascript:document.body.innerHTML=document.body.innerHTML.replace(new RegExp(prompt('regex?'),'g'),prompt('replacement%20string?'))
^-- This works though.
>>10
Holy crap. I just tried that on this page. It worked, but a second later the stylesheet disappeared. Also, the "Reply" button wouldn't work. I had to press Back.
>>11
that does the replace on the actual html of the page.
Yeah the problem is if it matches a bit of script, a link, or something else, amusing things can happen.
>>13
if you write your regex carefully that won't be a problem.
>>14
Leave *ML parsing to the professionals unless you want to work on it for the rest of life and produce something like http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html in the end.
It's a shame we can't get the same replace function for node lists. Then we could select the nodes we do want to affect, and run it only over those, without having to make our own loop.
BTW, RFC822 (email) addresses are fucking complex. Seriously. I think most people have the impression they're like "Personal Name" <user@example.com>. But that's the simplest case, regrettably.