我正在尝试使用Greasemonkey脚本替换部分URL,但是很难实现我想要做的事情。
原始网址如下:
http://x1.example.to/images/thumb/50/157/1571552600.jpg http://x2.example.to/images/thumb/50/120/1201859695.jpg http://x3.example.to/images/thumb/50/210/2109983330.jpg我想要实现的是:
http://example.to/images/full/50/157/1571552600.jpg http://example.to/images/full/50/120/1201859695.jpg http://example.to/images/full/50/210/2109983330.jpg我只想用完全替换拇指并完全从原始URL中删除x1 .example.to, x2 .example.to, x3 .example.to, x4 .example.to等部分,以便新的网址将开始像example.to/images/full/
我该如何实现这一目标?
我从这个答案中找到了一个Greasemonkey脚本并尝试解决但失败了。
这是我到目前为止所做的。
// ==UserScript== // @name Example Images Fixer // @namespace Example // @description Fixes image galleries // @include http://*.example.to/* // ==/UserScript== var links = document.getElementsByTagName("a"); //array var regex = /^(http:\/\/)([^\.]+)(\.example\.to\/images\/thumb/\)(.+)$/i; for (var i=0,imax=links.length; i<imax; i++) { links[i].href = links[i].href.replace(regex,"$4full/$5"); }对此有何帮助?
I'm trying to replace a part of url using a Greasemonkey script, but having hard time to achieve what I'm trying to do.
Original Urls are like:
http://x1.example.to/images/thumb/50/157/1571552600.jpg http://x2.example.to/images/thumb/50/120/1201859695.jpg http://x3.example.to/images/thumb/50/210/2109983330.jpgWhat I want to achieve is this:
http://example.to/images/full/50/157/1571552600.jpg http://example.to/images/full/50/120/1201859695.jpg http://example.to/images/full/50/210/2109983330.jpgI just want to replace thumb with full and cut out the x1.example.to, x2.example.to, x3.example.to, x4.example.to etc.. part completely from the original URL so new urls will be starting like example.to/images/full/
How do I achieve this?
I have found a Greasemonkey script from this answer and did try to work out but failed.
Here's what i did so far.
// ==UserScript== // @name Example Images Fixer // @namespace Example // @description Fixes image galleries // @include http://*.example.to/* // ==/UserScript== var links = document.getElementsByTagName("a"); //array var regex = /^(http:\/\/)([^\.]+)(\.example\.to\/images\/thumb/\)(.+)$/i; for (var i=0,imax=links.length; i<imax; i++) { links[i].href = links[i].href.replace(regex,"$4full/$5"); }Any help on that?
最满意答案
您忘记将http://部分放入替换网址中:
/^(https?:\/\/)[^.]+\.(example\.to\/images\/)thumb\/(.+)$/i接着:
.replace(regex, "$1$2full/$3");你可以在这里看到结果。
You're forgetting to put the http:// part in your replacement URL:
/^(https?:\/\/)[^.]+\.(example\.to\/images\/)thumb\/(.+)$/iand then:
.replace(regex, "$1$2full/$3");You can see the results here.
更多推荐
发布评论