-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