我的用户脚本在清理一些链接时遇到一个奇怪的问题。它成功删除了字符串中不需要的部分,但随后由于未知原因也将当前 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=/, ""));
});
您可以使用以下代码分割链接
jQuery(document).on("mouseenter", "a", function(event) {
jQuery(this).prop("href", jQuery(this).prop("href").split("=")[1]);
});