[niconico video] Add the "Add My List" button to search result page

Add the "Add My List" button to niconico video search result page

Stan na 11-04-2020. Zobacz najnowsza wersja.

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         [niconico video] Add the "Add My List" button to search result page
// @name:ja      [ニコニコ動画] 検索結果ページからマイリストするボタンを追加
// @description  Add the "Add My List" button to niconico video search result page
// @description:ja 検索結果ページページからマイリストするボタンを追加
// @namespace    masshiro.blog
// @version      20200412
// @author       masshiro
// @license      MIT License
// @match        http://www.nicovideo.jp/search/*
// @match        https://www.nicovideo.jp/search/*
// @match        http://www.nicovideo.jp/tag/*
// @match        https://www.nicovideo.jp/tag/*
// @grant        none
// ==/UserScript==
(function () {
    'use strict';

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

    var li = document.createElement('li');
    li.appendChild(span);
    li.className = 'count';

    li.addEventListener('click',function () {
        window.open('http://www.nicovideo.jp/mylist_add/video/' + encodeURIComponent(document.querySelectorAll('li[data-video-item]')[0].getAttribute('data-video-id')), 'nicomylistadd', 'width=500, height=400, menubar=no, scrollbars=no');
    },false);

    Array.prototype.forEach.call(document.querySelectorAll('li[data-video-item] div.itemContent div.itemData ul.list'), function(item,i) {
        var lis = li.cloneNode(true);
        lis.addEventListener('click',function () {
            window.open('http://www.nicovideo.jp/mylist_add/video/' + encodeURIComponent(document.querySelectorAll('li[data-video-item]')[i].getAttribute('data-video-id')), 'nicomylistadd', 'width=500, height=400, menubar=no, scrollbars=no');
        },false);
        item.appendChild(lis);
    });

    document.body.addEventListener('AutoPagerize_DOMNodeInserted',function(evt){
        Array.prototype.forEach.call(evt.target.querySelectorAll('li[data-video-item] div.itemContent div.itemData ul.list'), function(item,i) {
            var lis = li.cloneNode(true);
            lis.addEventListener('click', function () {
                window.open('http://www.nicovideo.jp/mylist_add/video/' + encodeURIComponent(evt.target.querySelectorAll('li[data-video-item]')[i].getAttribute('data-video-id')), 'nicomylistadd', 'width=500, height=400, menubar=no, scrollbars=no');
            },false);
            item.appendChild(lis);
        });
    }, false);
})();