使用 Greasemonkey 和 FireFox 重写部分链接
我的一个朋友在 webshots.com 上上传了她在过去一年左右拍摄的大约 20 张左右的自然照片,但是,我刚刚为她购买了一个付费 Flickr 帐户作为生日礼物,我想下载她的所有照片 措施
我无法访问她的 webshots 帐户,所以我已经采取了 Greasemonkey 和 DownThemAll 开始将她的图像保存到我桌面上的文件夹中。
我对 javascript 有点陌生,所有可用于 Greasemonkey 的“用户脚本”都不能完全满足我的需要。
加载图库页面时:
(http://[category].webshots.com/album/[album-id]),
我需要 Greasemonkey 脚本来查找所有图像链接:
(http://[category].webshots.com/photo/[photo-page-id])
并重写它们以反映此方案:
(http://community.webshots.com/photo/fullsize/[photo-page-id])
这容易做到吗?看起来好像是这样,但我似乎无法做到正确。
这是我当前不起作用的 Greasemonkey 脚本:
// ==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");
}
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");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
应该能解决问题
ought to do the trick
您的代码很好,但有一个拼写错误:
links[i].href =
liks[i].href.replace(regex,"$1community$3fullsize/ $4");
将 liks 替换为 links 即可。
打开 Firebug 控制台,打开大部分警告,然后重新加载页面。您可以看到脚本可能导致的错误(加上站点本身的大量错误)。
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).
答案很晚了,但无论如何我都会发布,以防万一它会有所帮助。
我自己对这个东西有点陌生,但我认为给 links[i].href 赋值没有帮助,因为它只是一个变量。这样做不会改变页面上的任何内容。我认为你应该用这个替换这个
:
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:
with this: