替换 Greasemonkey 中 URL 的一部分

Joh*_*ohn 2 regex 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
Run Code Online (Sandbox Code Playgroud)

我想要实现的是:

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
Run Code Online (Sandbox Code Playgroud)

我只想用full替换拇指并切出x1 .example.to、x2 .example.to、x3 .example.to、x4 .example.to 等。完全从原始 URL 中删除,因此新的 URL 将开始喜欢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");
}
Run Code Online (Sandbox Code Playgroud)

有什么帮助吗?