1

需要帮助为 Greasemonkey 编写脚本,以帮助我更有效地阅读论坛。

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

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

到这个可打印版本的 URL:

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


(添加-print,就在结束之前.html

4

1 回答 1

3

为此,请考虑可能的 URL 参数和哈希标签:

// ==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.

于 2012-09-30T09:01:42.993 回答