Javascript Greasemonkey是否将站点URL从.html重定向到-print.html?

Javascript Greasemonkey是否将站点URL从.html重定向到-print.html?,javascript,redirect,greasemonkey,Javascript,Redirect,Greasemonkey,需要帮助为Greasemonkey制作脚本,帮助我更高效地阅读论坛 重定向以.html结尾的所有页面: http://www.site.com/thread-category/4525-url.html 此可打印版本的URL: http://www.site.com/thread-category/4525-url-print.html (在结束.html之前添加-print,以考虑可能的URL参数和哈希标记: /==UserScript== //@name\u将site.com重定向到p

需要帮助为Greasemonkey制作脚本,帮助我更高效地阅读论坛

重定向以
.html
结尾的所有页面:

http://www.site.com/thread-category/4525-url.html
此可打印版本的URL:

http://www.site.com/thread-category/4525-url-print.html


(在结束
.html

之前添加
-print
,以考虑可能的URL参数和哈希标记:

/==UserScript==
//@name\u将site.com重定向到print.html URL
//@include/site\.com\/thread.+?\.html\b/
//@grant none
//@在文档开始时运行
//==/UserScript==
if(!/print\.html$/i.test(location.pathname)){
var printPath=location.pathname.replace(/(\.html)$/,“-print$1”);
var newURL=location.protocol+“/”
+location.host
+打印路径
+location.search
+location.hash
;
location.replace(newURL);
}

请注意,我们使用的是regex版本的
@include

我建议
location.host
而不是
location.hostname
,因为
location.host
包含端口(如果存在)。
hostname
从不包含端口号。