User JS (17)

1 Name: #!/usr/bin/anonymous : 2007-11-06 04:39 ID:Tmn0NOn4

Is there any way to make a user Javascript file that will replace every instance of a certain string with another?

2 Name: c:\4-ch\anonymous.exe : 2007-11-06 11:00 ID:Heaven

Yes.

3 Name: #!/usr/bin/anonymous : 2007-11-06 12:48 ID:Heaven

I'd go so far as to say there's probably several.

4 Name: #!/usr/bin/anonymous : 2007-11-08 12:03 ID:Heaven

I want to know if it can be done in a bookmarklet. That would be hilarious for pranking.

5 Name: #!/usr/bin/anonymous : 2007-11-09 09:29 ID:R45cliAx

Okay, cool. Like, can someone post one?

6 Name: #!/usr/bin/anonymous : 2007-11-09 10:13 ID:NTj3Twi4

>>5 Google is your best friend

7 Name: #!/usr/bin/anonymous : 2007-11-09 23:31 ID:Heaven

javascript:(function(){document.body.innerHTML=document.body.innerHTML.replace(new RegExp(prompt('regex?'),'g'),prompt('replacement string?'))})()

8 Name: #!/usr/bin/anonymous : 2007-11-10 06:02 ID:r5BC5HBj

someString.replace()

Look into it.

9 Name: #!/usr/bin/anonymous : 2007-11-10 10:13 ID:Heaven

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.

10 Name: #!/usr/bin/anonymous : 2007-11-10 10:18 ID:Heaven

javascript:document.body.innerHTML=document.body.innerHTML.replace(new RegExp(prompt('regex?'),'g'),prompt('replacement%20string?'))
^-- This works though.

11 Name: #!/usr/bin/anonymous : 2007-11-10 14:25 ID:Heaven

>>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.

12 Name: #!/usr/bin/anonymous : 2007-11-10 23:19 ID:Heaven

>>11
that does the replace on the actual html of the page.

13 Name: #!/usr/bin/anonymous : 2007-11-11 09:31 ID:Heaven

Yeah the problem is if it matches a bit of script, a link, or something else, amusing things can happen.

14 Name: #!/usr/bin/anonymous : 2007-11-12 21:42 ID:Heaven

>>13
if you write your regex carefully that won't be a problem.

15 Name: #!/usr/bin/anonymous : 2007-11-14 13:49 ID:Heaven

>>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.

16 Name: #!/usr/bin/anonymous : 2007-11-14 20:38 ID:Heaven

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.

17 Name: #!/usr/bin/anonymous : 2007-11-20 00:58 ID:R45cliAx

>>9
Thanks. :)

But for some reason it only replaces the first instance for me, and not every instance on the page.

This thread has been closed. You cannot post in this thread any longer.