show content tree

にこにこ動画でコンテンツツリーボタンを追加

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         show content tree
// @namespace    com.blowham.show_content_tree
// @version      0.1.1
// @description  にこにこ動画でコンテンツツリーボタンを追加
// @author       hukihamu
// @match        https://www.nicovideo.jp/watch/*
// @require      https://code.jquery.com/jquery-3.3.1.min.js
// @grant        none
// ==/UserScript==

(function() {
    function setIcon(){
        let findCount = 0
        const findInterval = setInterval(function(){
            if(180 < findCount){
                clearInterval(findInterval)
                findCount = 10000
            }
            findCount++
            const menu = document.getElementsByClassName("VideoMenuContainer-areaLeft")[0]
            if ( menu !== undefined ){
                const treeDiv = document.createElement("div")
                treeDiv.className = "ClickInterceptor is-inline LoginRequirer"
                const dStyle = treeDiv.style
                dStyle.width = "28px"
                dStyle.height = "28px"
                dStyle.margin = "0px"

                const treeButton = document.createElement("button")
                treeButton.className = "ActionButton VideoMenuContainer-button"
                treeButton.onclick = onClickTree
                $(treeButton).attr("data-title","コンテンツツリー")
                const bStyle = treeButton.style
                bStyle.backgroundImage = "url(http://commons.nicovideo.jp/cpp/img/common/sprite/sprite_gmenu.png)"
                bStyle.backgroundColor = "transparent"
                bStyle.backgroundRepeat = "no-repeat"
                bStyle.border = "none"
                bStyle.padding = "2px"
                bStyle.backgroundPosition = "2px -104px"
                bStyle.transitionDuration = "0ms"
                bStyle.width = "24px"
                bStyle.height = "24px"
                $(treeButton).hover(function(){
                    $(this).css("background-position", "2px -140px");
                },function(){
                    $(this).css("background-position", "2px -104px");
                })

                treeDiv.appendChild(treeButton)
                menu.insertBefore(treeDiv,menu.childNodes[2])


                clearInterval(findInterval)
                findCount = 10000

            }
        }, 1000)
    }
    function onClickTree(){
        window.open("http://commons.nicovideo.jp/tree/" + location.href.substring(location.href.lastIndexOf('/') + 1))

    }
    window.onLoad = setIcon()
})();