Auto New Tab

Open new tab, when click specified link.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name           Auto New Tab
// @description:en Open new tab, when click specified link.
// @version        0.1
// @namespace      https://twitter.com/foldrr
// @include        *
// @require        http://code.jquery.com/jquery-1.5.min.js
// @description Open new tab, when click specified link.
// ==/UserScript==
(function(){
    var settings = [
        // Google
        {
            url: 'http://www.google.com/search',
            selector: 'h3 a'
        },
        
        // YouTube
        {
            url: 'http://www.youtube.com/results',
            selector: ['.result-item-thumb', 'h3 a']
        },
        
        // ニコニコ動画 キーワード検索
        {
            url: 'http://www.nicovideo.jp/search/',
            selector: ['.uad_thumbfrm p a', '.watch']
        },
        
        // ニコニコ動画 タグ検索
        {
            url: 'http://www.nicovideo.jp/tag/',
            selector: ['.uad_thumbfrm p a', '.watch']
        },
        
        // ニコニコ動画 コミュニティ動画
        {
            url: 'http://com.nicovideo.jp/community/co',
            selector: 'table[summary] a'
        },
        
        // ニコニコ動画 マイリスト
        {
        	url: 'http://www.nicovideo.jp/mylist/',
        	selector: '#SYS_page_items a'
        },
        
        // ニコニコ動画 マイページ マイリスト
        {
            url: 'http://www.nicovideo.jp/my/mylist/',
            selector: ['.mypageThumb', '.mylistVideo a']
        },
        
        // ニコニコ動画 マイページ 視聴履歴
        {
            url: 'http://www.nicovideo.jp/my/history',
            selector: ['.mypageThumb', '.mylistVideo a']
        },
        
        // ニコニコ生放送
        {
            url: 'http://live.nicovideo.jp/watch/',
            selector: '.grid a'
        }
    ];
    
    main();
    
    document.body.addEventListener('AutoPagerize_DOMNodeInserted',function(e){
        main();
    }, false);
    
    function main(){
        $(settings).each(function(){
            if(0 <= location.href.indexOf(this.url)){
                var selectorArray = this.selector instanceof Array ? this.selector : [this.selector];
                var selector = selectorArray.join(", ");
                (function(){
                    var elems = $(selector);
                    if(elems.length == 0){
                        return;
                    }
                    
                    // GM_log("selector = " + selector);
                    // GM_log("elems.length = " + elems.length);
                    elems.attr("target", "_blank");
                })();
                
                return false;
            }
        });
    }
})();