0

我的博客在 Imgur 存储图像,但加载速度太慢。使用 JavaScript 我想替换表单的所有 URL

https://i.imgur.com/xxxxxx.png

https://example.net/imgur/xxxxxx.png

4

2 回答 2

0

您不需要任何 Javascript 来执行此操作,只需在您的博客站点文件所在的目录中创建一个文件夹,然后下载图像并将它们放在该文件夹中,它应该可以工作。

于 2021-04-18T03:41:50.153 回答
0

您可以使用正则表达式替换:

var url = "https://i.imgur.com/image.png";
var output = url.replace(/https:\/\/i.imgur.com\/(\S+)\.png/g, "https://example.net/imgur/$1.png");
console.log(url);
console.log(output);

于 2021-04-18T03:42:17.003 回答