Javascript 替换函数插入当前 URL

问题描述 投票:0回答:1

我的用户脚本在清理一些链接时遇到一个奇怪的问题。它成功删除了字符串中不需要的部分,但随后由于未知原因也将当前 URL 添加到字符串中。

示例:

我在这个网站上:https;//store.steampowered.com/app/1091500/Cyberpunk_2077/

有一个“访问网站”链接: https;//steamcommunity.com/linkfilter/?u=https://www.cyberpunk.net

脚本应将其更改为: https;//www.cyberpunk.net

脚本确实将其更改为: https;//store.steampowered.com/app/1091500/Cyberpunk_2077/https;//www.cyberpunk.net

jQuery(document).on("mouseenter", "a", function(event) {
  jQuery(this).prop("href", jQuery(this).prop("href").replace(/https:\/\/steamcommunity\.com\/linkfilter\/\?u=/, ""));
});
javascript replace userscripts
1个回答
0
投票

您可以使用以下代码分割链接

jQuery(document).on("mouseenter", "a", function(event) {
   jQuery(this).prop("href", jQuery(this).prop("href").split("=")[1]);
});
© www.soinside.com 2019 - 2024. All rights reserved.