Greasemonkey将站点URL从.html重定向到-print.html? [英] Greasemonkey to redirect site URLs from .html to -print.html?

查看:94
本文介绍了Greasemonkey将站点URL从.html重定向到-print.html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要帮助制作Greasemonkey的脚本,这将有助于我更有效地阅读论坛。

Need help making a script for Greasemonkey that will help me read forums more efficiently.

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

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

至此可打印版本网址:

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



(Add -print ,就在结束 .html 之前。

推荐答案

要对可能的URL参数和哈希标记进行计算:

To do this accounting for possible URL parameters and hash tags:

// ==UserScript==
// @name     _Redirect site.com to print.html URL's
// @include  /site\.com\/thread.+?\.html\b/
// @grant    none   
// @run-at   document-start
// ==/UserScript==

if ( ! /print\.html$/i.test (location.pathname) ) {
    var printPath   = location.pathname.replace (/(\.html)$/, "-print$1");
    var newURL      = location.protocol + "//"
                    + location.host
                    + printPath
                    + location.search
                    + location.hash
                    ;
    location.replace (newURL);
}

请注意,我们使用的正则表达式版本@include

这篇关于Greasemonkey将站点URL从.html重定向到-print.html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆