From 05de0546f98b1184f71beaeae186cc1cb00fa602 Mon Sep 17 00:00:00 2001 From: janus_wel Date: Mon, 22 Sep 2008 20:49:22 +0000 Subject: import matanico.js, nicontroller.js, nnp_cooperation.js git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@19750 d0d07461-0603-4401-acd4-de1884942a52 --- nnp_cooperation.js | 235 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 nnp_cooperation.js (limited to 'nnp_cooperation.js') diff --git a/nnp_cooperation.js b/nnp_cooperation.js new file mode 100644 index 0000000..1334230 --- /dev/null +++ b/nnp_cooperation.js @@ -0,0 +1,235 @@ +/* + * ==VimperatorPlugin== + * @name niconicoplaylist_cooperation.js + * @description this script give you keyboard opration for NicoNicoPlaylist. + * @description-ja NicoNicoPlaylist をキーボードで操作できるようにする。 + * @author janus_wel + * @version 0.20 + * @minversion 1.1 + * ==VimperatorPlugin== + * + * CONSTRAINT + * need NicoNicoPlaylist version 0.3 or above + * + * LICENSE + * New BSD License + * + * USAGE + * :nnppushallvideos + * 現在のページ内のすべての動画を再生リストに送る。 + * ランキングやマイリストのほか、動画ページではオススメ動画が追加される。 + * :nnppushthisvideo + * 現在見ている動画を再生リストに送る。 + * :nnpplaynext [next] + * 再生リストの次の動画を再生する。 + * :nnpremove [index] + * index 番目の動画を再生リストから取り除く。 index は 0 から数える。 + * 指定しない場合は一番上が取り除かれる。 + * :nnpclear + * 再生リストをすべてクリアする。 + * :nnpgetlist [numof] + * 再生リストの上から numof 個を表示する。指定しない場合は g:nnp_coop_numoflist が使われる。 + * + * VARIABLES + * g:nnp_coop_numoflist + * :NNPGetList で表示するリストの個数を指定する。デフォルトは 10 。 + * + * HISTORY + * 2008/07/11 initial written. + * 2008/07/15 refactoring + * + * */ +/* +以下のコードを _vimperatorrc に貼り付けると幸せになれるかも。 +コマンド ( [',nn'] や [',nr'] の部分 ) は適宜変えてね。 + +javascript <', + 'table.nnp_coop .index { text-align:right; width:2em; }', + 'table.nnp_coop .thumbnail { text-align:center; }', + 'table.nnp_coop caption { color:green; }', + 'table.nnp_coop thead { text-align:center; }', + '', +].join(''); + +// table +const tableTemplate = [ + '', + '$CAPTION', + '$THEAD', + '$ITEMS', + '
', +].join(''); + +// table caption +const captionTemplate = '$NUMOFDISPLAY / $NUMOFTOTAL items from NicoNicoPlaylist'; + +// table head +const thead = [ + '', + '', + ' ', + 'thumbnail', + 'title', + 'url', + '', + '', +].join(''); + +// item +const itemHTML = [ + '', + '$INDEX:', + '', + '$TITLE', + '$URL', + '', +].join(''); + + +// scrape from div element that inserted by NicoNicoPlaylist +liberator.commands.addUserCommand(['nnpgetlist'], 'get NicoNicoPlaylist', + function(arg) { + // check existence of NicoNicoPlaylist + var playlist = $f('//div[contains(@id, "playlistcontroller_")]'); + if(!playlist) { + liberator.echoerr('NicoNicoPlaylist is not found.'); + return; + } + + // check existence of items in NicoNicoPlaylist + var nodes = $s('div[2]/ul/li/a[2]', playlist); + var nodesLength = nodes.length + if(nodesLength === 0) { + liberator.echoerr('no items in NicoNicoPlaylist.'); + return; + } + + // get number of displayed items + var numofList = arg.match(/^\d+$/) + ? arg + : (liberator.globalVariables.nnp_coop_numoflist || 10); + + // struct display string + // generate data + var items = new Array; + for(var i=0 ; i