使用GreaseMonkey更改URL

J3ff3z

我想使用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() oldnew

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章