views:

101

answers:

2

A friend of mine uploaded about 20 or so galleries of nature shots she's done over the past year or so onto webshots.com, however, I just purchased a paid flickr account for her as a birthday gift, and I want to download all of her photos from webshots and have them ready for her to upload to flickr once she gets the email about her account upgrade (she's out of the country - no internet access.)

I don't have access to her webshots account, so I've resorted to Greasemonkey and DownThemAll to start saving her images into folders on my desktop.

I'm somewhat new to javascript, and all the "user scripts" available for Greasemonkey don't exactly do what I need, so I figured I'd ask at stackoverflow!

When a gallery page is loaded:

(http://[category].webshots.com/album/[album-id]),

I need the Greasemonkey script to find all links to images:

(http://[category].webshots.com/photo/[photo-page-id])

and re-write them to reflect this scheme:

(http://community.webshots.com/photo/fullsize/[photo-page-id])

Is this easy to do? It seems like it would be, but I can't seem to get it right...

Here's my current greasemonkey script that doesn't work:

// ==UserScript==
// @name           Webshot Gallery Fixer
// @namespace      WGF
// @description    Fixes webshot galleries
// @include        http://*.webshots.com/*
// ==/UserScript==

var links = document.getElementsByTagName("a"); //array
var regex = /^(http:\/\/)([^\.]+)(\.webshots\.com\/photo\/)(.+)$/i;
for (var i=0,imax=links.length; i<imax; i++) {
   links[i].href = liks[i].href.replace(regex,"$1community$3fullsize/$4");
}
+3  A: 
var links = document.getElementsByTagName("a"); //array
var regex = /^(http:\/\/)([^\.]+)(\.webshots\.com\/photo\/)(.+)$/i;
for (var i=0,imax=links.length; i<imax; i++) {
   links[i].href = links[i].href.replace(regex,"$1community$3fullsize/$4");
}

ought to do the trick

Robusto
This appears to be no different than the OP's code and it doesn't work.
Brock Adams
@Brock Adams Probably because the OP lifted that code from the answer. Check the edits on the question.
George Marian
@George Marian: Yeah, it looks that way when checking edit histories. Sorry about that, Robusto, still have that typo, though. ;-)
Brock Adams
@George Marian: Fixed typo. Thanks for pointing that out. :)
Robusto
@Robusto I did no such thing, @Brock Adams deserves the credit for pointing out the typo. :)
George Marian
@Brock Adams: Sorry for the mix-up.
Robusto
@Robusto: No problémo. Good answer. I'd already +1'd you.
Brock Adams
+1  A: 

Your code was fine but for a typo:

links[i].href = liks[i] .href.replace(regex,"$1community$3fullsize/$4");

Replace liks with links and it works.

Open up the Firebug console, turn most of the warnings on, and reload the page. You can see errors your script might cause (plus a metric ton of errors from the site itself).

Brock Adams
+1 for spotting the typo, though you typo'd yourself. It's liks. ;)
George Marian
@George Marian: D'Oh! That's what I get for trying to recreate the error, by hand, from my fixed copy of the code. Fixed. Thanks.
Brock Adams