Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rewrite parts of links using Greasemonkey and FireFox

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.

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");
}
like image 550
z0mn Avatar asked Jan 25 '26 21:01

z0mn


1 Answers

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

like image 122
Robusto Avatar answered Jan 27 '26 10:01

Robusto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!