gpt4 book ai didi

javascript - 使用 GreaseMonkey 更改 URL

转载 作者:行者123 更新时间:2023-12-05 06:42:06 27 4
gpt4 key购买 nike

我想用 Greasemonkey 脚本更改页面的当前 URL。

我的意思是,我在位置:“http://www.mywebsite.com/video/old/*.mkv”,我想移动到“http://www.mywebsite.com/video/new/*.mkv”。所以基本上,我只想更改 URL 中"new"中的“旧”。

我找到了这段代码:

var oldUrlPath  = window.location.pathname;

/*--- Test that ".compact" is at end of URL, excepting any "hashes"
or searches.
*/
var newURL = window.location.protocol + "//"
+ window.location.host
+ oldURLPath
+ window.location.search
+ window.location.hash
;
/*-- replace() puts the good page in the history instead of the
bad page.
*/
window.location.replace (newURL);

但我不知道如何用我想要的 newURLPath 替换 oldURLPath。我想我必须使用 replace() 但我不确定(而且我尝试的所有代码都不起作用,我一定没有正确使用它,因为我不熟悉 ReGex)。

感谢您的回答

最佳答案

我认为正则表达式没有任何必要。看起来您可以将 replace() old 替换为 new

var oldURL = "http://www.mywebsite.com/video/old/*.mkv";
location.href = oldURL.replace('old','new');

关于javascript - 使用 GreaseMonkey 更改 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38543998/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com