GreaseMonkey脚本重写图像链接

时间:2011-06-22 03:23:40

标签: javascript firefox replace greasemonkey hyperlink

  

可能重复:
  How to replace image links with img src url in Greasemonkey

我是javacript的新手,想要编写一个GreaseMonkey脚本来重写网站上的某些图像链接,以显示原始大小的图像而不是缩略图。

图片链接位于以下表格中:

<div class="feed_img"><a onclick="App.scaleImg(this,'7e87e5d5tw1difluxvqlzj');" href="javascript:;"><img src="http://ww3.sinaimg.cn/thumbnail/7e87e5d5tw1difluxvqlzj.jpg" class="imgicon" vimg="1"></a></div>

我想要做的是替换

http://*/thumbnail/*.jpg 

http://*/large/*.jpg

有人能给我带头吗?

1 个答案:

答案 0 :(得分:2)

您必须遍历所有<img>代码,只需将thumbnail替换为large属性中的src

// This fetches all of the <img> tags and stores them in "tags".
var tags = document.getElementsByTagName('img');

// This loops over all of the <img> tags.
for (var i = 0; i < tags.length; i++) {

  // This replaces the src attribute of the tag with the modified one
  tags[i].src = tags[i].src.replace('thumbnail', 'large');
}

希望这段代码有效。我使用的是基本的replace(),所以如果您想尝试使用正则表达式,我认为它也应该有效。

相关问题