Page 1 of 1

Add-on to replace a known string in a URL

Posted: Fri Jul 10, 2009 1:58 am
by hornakapopolis
I've never really been into scripting, so if there's an easier way to do this, feel free to throw a rock at my head and point it out.

Could an add-on be made to replace a known string within a URL with something else?

I've been doing a lot of wallpaper searching lately and started running across a lot of imagevenue (I think) links that were loading to ad pages, but one of my blockers was blocking everything on the page so I couldn't click a link and I wasn't being redirected. Replacing a string in the URL would take me to the image, though, and I was figuring that there is probably some way to do that automatically.

If it matters, in this example, the entire first part of the URL could be substituted since any part of the address that changes is that the end.

Re: Add-on to replace a known string in a URL

Posted: Sat Jul 11, 2009 5:51 am
by sulpherdragon
Hi.

Theres a few different ways to do this. One simple method is by using the following code:

Code: Select all

// loop through all links
for (var i = 0; i < document.links.length; i++)
{
             //replace microsoft with W3Schools
	document.links[i].replace(/microsoft/gi, "W3Schools");
}
I took the code from http://www.w3schools.com/jsref/jsref_replace.asp so you can read and learn how it works

the /gi means it will replace several occurances of the string and it will also be case in-sensitive.
change "microsoft" to the string you want to replace, and change "W3Schools" to the new string you need.
If you want, you can give more specific instructions and one of us could make a plugin.
I didnt get a chance to formally test it, but if it doesnt work it shouldnt be too hard to fix.

Heres hoping it solves your problem!

Re: Add-on to replace a known string in a URL

Posted: Sat Jul 11, 2009 2:17 pm
by hornakapopolis
That's seems to have worked. Thanks!

I remembered it was imagevenue, so changing the code to this:

Code: Select all

// loop through all links
for (var i = 0; i < document.links.length; i++)
{
             //replace microsoft with W3Schools
   document.links[i].replace(/tempfull-aff.php?loc=loc703&/gi, "img.php?");
}
...seems to have removed their ad pages.

Of course, since the ad pages are random, you don't really know until you've gone awhile without.

Thanks again!

Re: Add-on to replace a known string in a URL

Posted: Sat Jul 11, 2009 6:33 pm
by hornakapopolis
Well, nope... doesn't work.

Like I said, I don't really know anything when it comes to scripting, but looking at this code, is it replacing a string found within a link on a page? If that's the case, then it's not working because the link that are clicked to get to these pages don't include the string.

It's one of those cases when you click a thumbnail of an image, but before you are taken to the image, you get an ad page and you must click it before you can continue.

Here's an example:

Link is posted to: http://img31.imagevenue.com/img.php?ima ... _584lo.jpg

Clicking the link first takes you to: http://img31.imagevenue.com/tempfull-af ... _584lo.jpg

Which then immediately redirects to: http://img31.imagevenue.com/uploading-aff.php

I didn't realize it was going to the last link until I just tried it on another computer. My main system's security software stops it at the second link, which is a step you don't even see when no blockers are involved.

I'm going to play around a bit more with my security software, too, but I was hoping this was something that could be done. It's going to have to either be catching the URL or making a change in the Address bar.

edit: Also, I didn't think about it until I was copying and pasting the addresses, but it might be possible that that number changes after the loc

Re: Add-on to replace a known string in a URL

Posted: Mon Jul 13, 2009 10:40 pm
by kudos
Try ImageHost Grabber - a firefox extension that will download all images on a page that are hosted on an image host. Works well with Orca.

Re: Add-on to replace a known string in a URL

Posted: Tue Jul 14, 2009 2:31 am
by hornakapopolis
Unfortunately, I don't work with Orca. ;) ...and it's something I usually do to pass the time while waiting on other things, not something I sit down specifically to do. Also, many of the times I want to see the full image before saving it.