Javascript Greasemonkey/Tampermonkey脚本重定向到双重修改的URL
目标页面的URL为:Javascript Greasemonkey/Tampermonkey脚本重定向到双重修改的URL,javascript,url,greasemonkey,userscripts,tampermonkey,Javascript,Url,Greasemonkey,Userscripts,Tampermonkey,目标页面的URL为:ouo.io/tLnpEc.html 我想把URL改为:ouo.press/tLnpEc 即:.io至。按并删除.html 我已经有了这个,但它不起作用(它重定向到ouo.press,但仍然没有删除.html): 我希望有人能在这个问题上提供帮助。相关:(和其他几个) 要点: 检查页面位置,确保您尚未重定向;避免无限重定向循环 不要在.href上操作。这将导致各种引用、搜索等链接和重定向的副作用和错误触发 使用@run at document start减少延迟和恼人的“闪烁
ouo.io/tLnpEc.html
我想把URL改为:ouo.press/tLnpEc
即:.io
至。按
并删除.html
我已经有了这个,但它不起作用(它重定向到ouo.press,但仍然没有删除.html):
我希望有人能在这个问题上提供帮助。相关:(和其他几个)
要点:
.href
上操作。这将导致各种引用、搜索等链接和重定向的副作用和错误触发@run at document start
减少延迟和恼人的“闪烁”// ==UserScript==
// @name _Redirecy ouo.io/...html files to ouo.press/... {plain path}
// @match *://ouo.io/*
// @run-at document-start
// @grant none
// ==/UserScript==
//-- Only redirect if the *path* ends in .html...
if (/\.html$/.test (location.pathname) ) {
var newHost = location.host.replace (/\.io$/, ".press");
var plainPath = location.pathname.replace (/\.html$/, "");
var newURL = location.protocol + "//" +
newHost +
plainPath +
location.search +
location.hash
;
location.replace (newURL);
}
// ==UserScript==
// @name _Redirecy ouo.io/...html files to ouo.press/... {plain path}
// @match *://ouo.io/*
// @run-at document-start
// @grant none
// ==/UserScript==
//-- Only redirect if the *path* ends in .html...
if (/\.html$/.test (location.pathname) ) {
var newHost = location.host.replace (/\.io$/, ".press");
var plainPath = location.pathname.replace (/\.html$/, "");
var newURL = location.protocol + "//" +
newHost +
plainPath +
location.search +
location.hash
;
location.replace (newURL);
}