[niconico video] Adds a botton that add mylist to mylist page

Adds a button that add mylist to mylist page

目前為 2017-02-17 提交的版本,檢視 最新版本

// ==UserScript==
// @name         [niconico video] Adds a botton that add mylist to mylist page
// @name:ja      [ニコニコ動画] マイリストページからマイリストするボタンを追加
// @description  Adds a button that add mylist to mylist page
// @description:ja マイリストページからマイリストするボタンを追加
// @namespace    masshiro.wpblog.jp
// @version      0.1
// @author       masshiro
// @match        http://www.nicovideo.jp/mylist/*
// @grant        none
// ==/UserScript==
/*
var addbottons = function()
{
    'use strict';

    var span = document.createElement('span');
    span.className = "value";
    span.style="color:#F00;text-decoration:underline;cursor:pointer";
    span.innerHTML="追加";

    var a = document.createElement('a');
    a.appendChild(span);

    a.addEventListener('click',function () {
        window.open("http://www.nicovideo.jp/mylist_add/video/" + encodeURIComponent(document.querySelectorAll(".SYS_box_item a")[0].getAttribute("href").replace("watch/","")), "nicomylistadd", "width=500, height=400, menubar=no, scrollbars=no");
    },false);

    Array.prototype.forEach.call(document.querySelectorAll(".SYS_box_item_buttons p"), function(item,i) {
        var as = a.cloneNode(true);
        as.addEventListener('click',function () {
            window.open("http://www.nicovideo.jp/mylist_add/video/" + encodeURIComponent(document.querySelectorAll(".SYS_box_item a")[i].getAttribute("href").replace("watch/","")), "nicomylistadd", "width=500, height=400, menubar=no, scrollbars=no");
        },false);
        item.appendChild(as);
    });
}
*/
(function () {
    'use strict';

    var addButtons = function () {
        var span = document.createElement('span');
        span.style="color:#F00;text-decoration:underline;cursor:pointer";
        span.innerHTML="追加";

        var a = document.createElement('a');
        a.className = "addmylist";
        a.appendChild(span);

        a.addEventListener('click',function () {
            window.open("http://www.nicovideo.jp/mylist_add/video/" + encodeURIComponent(document.querySelectorAll(".SYS_box_item")[0].querySelectorAll("a")[0].getAttribute("href").replace("watch/","")), "nicomylistadd", "width=500, height=400, menubar=no, scrollbars=no");
        },false);

        Array.prototype.forEach.call(document.querySelectorAll(".SYS_box_item_buttons p"), function(item,i) {
            if(typeof item.querySelectorAll("a.addmylist")[0] === "undefined"){
                var as = a.cloneNode(true);
                as.addEventListener('click',function () {
                    window.open("http://www.nicovideo.jp/mylist_add/video/" + encodeURIComponent(document.querySelectorAll(".SYS_box_item")[i].querySelectorAll("a")[0].getAttribute("href").replace("watch/","")), "nicomylistadd", "width=500, height=400, menubar=no, scrollbars=no");
                },false);
                item.appendChild(as);
            }
        });
    };

    // DOM変更で再実行
    // コピー元 (ありがとうございました)
    // https://greasyfork.org/ja/scripts/15271-extract-images-for-twitter
    (function () {
        var DOMObserverTimer = false;
        var DOMObserverConfig = {
            attributes: true,
            childList: true,
            subtree: true
        };
        var DOMObserver = new MutationObserver(function () {
            if (DOMObserverTimer !== 'false') {
                clearTimeout(DOMObserverTimer);
            }
            DOMObserverTimer = setTimeout(function () {
                DOMObserver.disconnect();
                addButtons();
                DOMObserver.observe(document.body, DOMObserverConfig);
            }, 100);
        });
        DOMObserver.observe(document.body, DOMObserverConfig);
    }) ();

})();