【发布时间】:2014-09-19 00:15:45
【问题描述】:
我正在尝试使用 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
我只想将 thumb 替换为 full 并删除 x1.example.to, x2 .example.to、x3.example.to、x4.example.to 等完全来自原始 URL,因此新的 URL 将以 example.to/images/full/
我如何做到这一点?
我从this answer 找到了一个 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");
}
有什么帮助吗?
【问题讨论】:
标签: regex greasemonkey