使用 Greasemonkey 和 FireFox 重写部分链接

发布于 2024-09-09 00:56:37 字数 1164 浏览 2 评论 0原文

我的一个朋友在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情绪少女 2024-09-16 00:56:37
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");
}

应该能解决问题

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

楠木可依 2024-09-16 00:56:37

您的代码很好,但有一个拼写错误:

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

爱要勇敢去追 2024-09-16 00:56:37

答案很晚了,但无论如何我都会发布,以防万一它会有所帮助。

我自己对这个东西有点陌生,但我认为给 links[i].href 赋值没有帮助,因为它只是一个变量。这样做不会改变页面上的任何内容。我认为你应该用这个替换这个

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

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

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");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文