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

Adds a button that add mylist to mylist page

当前为 2017-03-15 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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.11
// @author       masshiro
// @match        http://www.nicovideo.jp/mylist/*
// @grant        none
// ==/UserScript==

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

})();