delicious nico thumb

deliciousでニコニコ動画のサムネイルを表示する

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @id             delicious.nico.thumb
// @name           delicious nico thumb
// @version        1.0
// @namespace      http://efcl.info/
// @author         azu
// @description    deliciousでニコニコ動画のサムネイルを表示する
// @include        http://delicious.com/*/
// @run-at         document-end
// ==/UserScript==
(function(){
    function getNicoThumbURL(videoURL){
        var match = videoURL.match(/^http:\/\/(?:www\.nicovideo\.jp\/watch|nico\.ms)\/[a-z][a-z](\d+)$/);
        if (!match){
            return;
        }
        var id = match[1];
        var host = parseInt(id, "10") % 4 + 1;
        return 'http://tn-skr' + host + '.smilevideo.jp/smile?i=' + id;

    }

    function addThumb(elem){
        var bookmarkURL = getURL(elem);
        var refImg = getElementForInsert(elem);
        var thumbURL = getNicoThumbURL(bookmarkURL);
        if (thumbURL){
            refImg.src = thumbURL;
        }
    }

    function getURL(elem){
        var action = elem.getElementsByClassName("action")[0];
        if (!action){
            throw new Error("action node not found");
        }
        return action.getAttribute("href");
    }

    function getElementForInsert(elem){
        var thumbElem = elem.getElementsByClassName("thumb")[0];
        if (!thumbElem){
            throw new Error("thumbElem node not found");
        }
        var imgElem = thumbElem.getElementsByTagName("img")[0];
        if(!imgElem){
            var newImage = document.createElement("img");
            var delayDiv = thumbElem.firstElementChild;
            thumbElem.replaceChild(newImage, delayDiv);
            return newImage;
        }
        return imgElem;
    }

    function delegateMain(node){
        var bookmarks = node.getElementsByClassName("link");
        for (var i = 0, len = bookmarks.length; i < len; i++){
            var bookmark = bookmarks[i];
            addThumb(bookmark);
        }

    }

    document.body.addEventListener('AutoPagerize_DOMNodeInserted', function(evt){
        var node = evt.target;
        // var requestURL = evt.newValue;
        // var parentNode = evt.relatedNode;
        delegateMain(node);
    }, false);


    delegateMain(document);
})();