From 56cb882fc6f122c75608f8eb6142a607d3dc855f Mon Sep 17 00:00:00 2001 From: janus_wel Date: Tue, 4 Nov 2008 21:02:16 +0000 Subject: for vimperator 1.2 git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/branches/1.2@22732 d0d07461-0603-4401-acd4-de1884942a52 --- nnp_cooperation.js | 265 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 265 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..71c2d1f --- /dev/null +++ b/nnp_cooperation.js @@ -0,0 +1,265 @@ +/* + * ==VimperatorPlugin== + * @name niconicoplaylist_cooperation.js + * @description this script give you keyboard opration for NicoNicoPlaylist. + * @description-ja NicoNicoPlaylist をキーボードで操作できるようにする。 + * @author janus_wel + * @version 0.32 + * @minversion 2.0pre 2008/10/16 + * ==/VimperatorPlugin== + * + * CONSTRAINT + * need NicoNicoPlaylist version 1.12 or above + * + * LICENSE + * New BSD License + * + * USAGE + * :nnppushallvideos + * 現在のページ内のすべての動画を再生リストに送る。 + * ランキングやマイリストのほか、動画ページではオススメ動画が追加される。 + * :nnppushthisvideo + * 現在見ている動画を再生リストに送る。 + * :nnpplaynext [next] + * 再生リストの次の動画を再生する。 + * :nnpremove [index] + * index 番目の動画を再生リストから取り除く。 index は 0 から数える。 + * 指定しない場合は一番上が取り除かれる。 + * :nnpclear + * 再生リストをすべてクリアする。 + * :nnpgetlist [numof] + * 再生リストの上から numof 個を表示する。指定しない場合は g:nnp_coop_numoflist が使われる。 + * :nnprandom + * ランダムモードの on / off + * :nnploop + * ループモードの on / off + * :nnpfullscreen + * 全画面モードの on / off + * + * VARIABLES + * g:nnp_coop_numoflist + * :NNPGetList で表示するリストの個数を指定する。デフォルトは 10 。 + * + * HISTORY + * 2008/07/11 ver. 0.10 - initial written. + * 2008/07/15 ver. 0.20 - refactoring. + * 2008/09/26 ver. 0.30 - change XPath expression. + * - correspond mode toggling (fullscreen, random, loop). + * - change caption: display now-playing title and mode's statuses. + * - mode's statuses are displayed with the following word. + * R: random mode is on + * L: loop mode is on + * F: fullscreen mode is on + * 2008/09/28 ver. 0.31 - bugfix :nnpgetlist in ranking page. + * + * */ +/* +以下のコードを _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 = 'now playing: $PLAYTITLE (display $NUMOFDISPLAY / $NUMOFTOTAL$STATUSES)'; + +// 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; + } + + var titleNode = $f('//h1') || $f('./html/head/title'); + var playTitle = titleNode.textContent; + var statuses = ''; + if($f('.//input[contains(@id, "-checkbox-random")]', playlist).checked) statuses += 'R'; + if($f('.//input[contains(@id, "-checkbox-loop")]', playlist).checked) statuses += 'L'; + if($f('.//input[contains(@id, "-checkbox-full")]', playlist).checked) statuses += 'F'; + if(statuses) statuses = ' ' + statuses; + + // check existence of items in NicoNicoPlaylist + var nodes = $s('./div[contains(concat(" ", @class, " "), " playlist-list-outer ")]/ul/li/a', 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(let i=0 ; i