Auto New Tab

Open new tab, when click specified link.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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;
            }
        });
    }
})();