开发者

Rewrite parts of links using Greasemonkey and FireFox

开发者 https://www.devze.com 2023-01-07 13:22 出处:网络
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, a

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 th开发者_开发知识库e 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");
}


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


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


Quite late answer, but I'll post anyway in case it'll do some good.

I'm kind of newb to this stuff myself, but I don't think it will help to assign a value to links[i].href since it's just a variable. You won't change anything on the page by doing so. I think you should replace this:

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

with this:

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

精彩评论

暂无评论...
验证码 换一张
取 消