可能重复:
如何在Greasemonkey 中用img src url替换图像链接
我是javascript的新手,想写一个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
有人能给我线索吗?
您必须遍历所有<img>
标记,并在其src
属性中用large
替换thumbnail
:
// 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()
,所以如果你想尝试regex,我认为它也应该有效。