开发者

Javascript image url replacement

开发者 https://www.devze.com 2022-12-14 07:20 出处:网络
I want to write a greasemonkey script/chr开发者_StackOverflow社区ome user script that takes any images with a certain syntax and replace a section of the url and puts it back in the dom.

I want to write a greasemonkey script/chr开发者_StackOverflow社区ome user script that takes any images with a certain syntax and replace a section of the url and puts it back in the dom.

Namely I have a page full of thumbnails, e.g. www.example.com/small/randomstuff and I want to replace the imades with the equivilant www.example.com/large/randomstuff

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"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号