javascript - GreaseMonkey脚本重写图片链接

标签 javascript firefox replace greasemonkey hyperlink

<分区>

Possible Duplicate:
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

谁能给我一个线索?

最佳答案

您必须遍历所有 <img>标签,只需替换 thumbnaillarge在他们的 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() ,所以如果您想尝试正则表达式,我认为它也应该可以。

关于javascript - GreaseMonkey脚本重写图片链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6434558/

相关文章:

javascript - 为什么在我尝试替换 @mention 时正则表达式不起作用?

c# 使用 linq 替换类的属性中的字符串不起作用

javascript - 递增类,需要停止并从头开始

javascript - 在 Microsoft Surface 设备上与 Firefox 交互和触摸?

html - 如何让我的菜单在 Firefox 中工作?

html - Firefox 伪元素定位在一行中的第一个单词

MySQL 搜索并替换不属于其一部分的整个字段

JavaScript 按钮。 - 添加/删除类/id 样式 onClick。 - 显示 : none/block

javascript - 如何使用JSZip解压

javascript - jQuery - ("a.class")加载和window.open?