簡體   English   中英

使用GreaseMonkey更改URL

[英]Change the URL using GreaseMonkey

我想使用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不熟悉,我不能正確使用它)。

感謝您的回答

我看不到正則表達式中有任何需要。 看起來您可以replace() new replace() old replace()

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM