简体   繁体   English

Javascript图片网址替换

[英]Javascript image url replacement

I want to write a greasemonkey script/chrome user script that takes any images with a certain syntax and replace a section of the url and puts it back in the dom. 我想编写一个用单一语法获取任何图像并替换一部分URL并将其放回dom的油腻的monkey脚本/ chrome用户脚本。

Namely I have a page full of thumbnails, eg www.example.com/small/randomstuff and I want to replace the imades with the equivilant www.example.com/large/randomstuff 即我有一个充满缩略图的页面,例如www.example.com/small/randomstuff,我想用等价的www.example.com/large/randomstuff替换imades

How would I do this? 我该怎么做?

After page was loaded. 页面加载后。

var imgs = document.getElementsByTagName('img');
var len =imgs.length;
for(var i=0;i<len;i++){
  imgs[i].src=imgs[i].src.replace("small","large");
}

To replace a image source url, you can do something like this: 要替换图片来源网址,您可以执行以下操作:

var imgs = document.getElementsByTagName('img')
imgs[0].src = "http://www.example.com/large/randomstuff"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM