-1
我想用Greasemonkey脚本更改页面的当前URL。使用GreaseMonkey更改URL
我的意思是,我在的位置:“http://www.mywebsite.com/video/old/*.mkv”,我想移动到“http://www.mywebsite.com/video/new/*.mkv”。所以基本上,我只是想改变URL中“新”的“旧”。
我发现这个代码:
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,所以我不得不正确使用它)。
感谢您的回答
在此情况下,但是,一般地,如果'old'子串前需要一个使用它可能会失败,所以最好以包括不能文件名称的一部分的符号,例如:'替换('/ old /','/ new /')'。 – wOxxOm
@ w0x好吧,一般来说,如果有多个'/ old /',这可能会失败。 – nicael