Rewrite parts of links using Greasemonkey and FireFox

一笑奈何 提交于 2019-11-29 16:12:54
var links = document.getElementsByTagName("a"); //array
var regex = /^(http:\/\/)([^\.]+)(\.webshots\.com\/photo\/)(.+)$/i;
for (var i=0,imax=links.length; i<imax; i++) {
   links[i].href = links[i].href.replace(regex,"$1community$3fullsize/$4");
}

ought to do the trick

Your code was fine but for a typo:

links[i].href = liks[i] .href.replace(regex,"$1community$3fullsize/$4");

Replace liks with links and it works.

Open up the Firebug console, turn most of the warnings on, and reload the page. You can see errors your script might cause (plus a metric ton of errors from the site itself).

Anonymous

Quite late answer, but I'll post anyway in case it'll do some good.

I'm kind of newb to this stuff myself, but I don't think it will help to assign a value to links[i].href since it's just a variable. You won't change anything on the page by doing so. I think you should replace this:

links[i].href = links[i].href.replace(regex,"$1community$3fullsize/$4");

with this:

document.getElementsByTagName("a")[i].href = links[i].href.replace(regex,"$1community$3fullsize/$4");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!