替换Greasemonkey中URL的部分内容(Replace parts of a URL in Greasemonkey)

编程入门 行业动态 更新时间:2024-10-27 06:22:20
替换Greasemonkey中URL的部分内容(Replace parts of a URL in Greasemonkey)

我正在尝试使用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.jpg

What 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.jpg

I 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\/(.+)$/i

and then:

.replace(regex, "$1$2full/$3");

You can see the results here.

更多推荐

本文发布于:2023-08-05 22:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1440125.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:部分内容   URL   Greasemonkey   Replace   parts

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!