/* * ==VimperatorPlugin== * @name nnp_cooperation.js * @description this script give you keyboard opration for NicoNicoPlaylist. * @description-ja NicoNicoPlaylist をキーボードで操作できるようにする。 * @author janus_wel * @version 0.33 * @minversion 2.0pre * @maxversion 2.0pre * ==/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 <= numofList) break; // get video id let id = node.href.match(/\d+$/); // evaluate variables and push to list items.push({ index: ++length, thumbnailURL: thumbnailURL(id), title: node.textContent, url: node.href, }); } // evaluate variables let xml = <> {style()} {table({ numofDisplay: (nodesLength < numofList) ? nodesLength : numofList, numofTotal: nodesLength, playTitle: getPlayTitle(), statuses: getStatusText(playlistNode.id), items: items, })} liberator.echo(xml, liberator.modules.commandline.FORCE_MULTILINE); }, {} ); // define other commands // only send CommandEvent to NicoNicoPlaylist script [ [['nnppushallvideos'], 'push all videos to NicoNicoPlaylist', 'GMNNPPushAllVideos'], [['nnppushthisvideo'], 'push current video to NicoNicoPlaylist', 'GMNNPPushThisVideo'], [['nnpplaynext'], 'play next in NicoNicoPlaylist', 'GMNNPPlayNext'], [['nnpremove'], 'remove item in NicoNicoPlaylist', 'GMNNPRemove'], [['nnpclear'], 'clear all items in NicoNicoPlaylist', 'GMNNPClear'], [['nnprandom'], 'toggle random mode of NicoNicoPlaylist', 'GMNNPRandom'], [['nnploop'], 'toggle loop mode of NicoNicoPlaylist', 'GMNNPLoop'], [['nnpfullscreen'], 'toggle fullscreen mode of NicoNicoPlaylist', 'GMNNPFullScreen'], ].forEach( function ([command, description, eventname]){ liberator.modules.commands.addUserCommand( command, description, function (arg) { let r = document.createEvent('CommandEvent'); r.initCommandEvent(eventname, true, true, arg[0]); window.content.dispatchEvent(r); }, {} ); }); // stuff functions --- // return first node function $f(query, node) { node = node || window.content.document; let result = (node.ownerDocument || node).evaluate( query, node, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ); return result.singleNodeValue ? result.singleNodeValue : null; } function getPlayTitle() { let titleNode = $f('//h1') || $f('//title'); return titleNode.textContent; } function getStatusText(idPrefix) { let statuses = []; [ ['//input[starts-with(@id, "playlist") and contains(@id, "-checkbox-random")]', 'R'], ['//input[starts-with(@id, "playlist") and contains(@id, "-checkbox-loop")]', 'L'], ['//input[starts-with(@id, "playlist") and contains(@id, "-checkbox-full")]', 'F'], ].forEach(function ([query, text]) { if ($f(query).checked) statuses.push(text); }); return (statuses.length) ? ' ' + statuses.join('') : ''; } // thumbnail URL // refer: http://d.hatena.ne.jp/ZIGOROu/20081014/1223991205 function thumbnailURL(videoId) { return [ 'http://tn-skr', (videoId % 2 + 1), '.smilevideo.jp/smile?i=', videoId ].join(''); } // E4X hell --- // style function style(css) { return } // table function table(data) { return {caption(data)} {thead()} {liberator.modules.template.map(data.items, item)}
} // table caption function caption(data) { return now playing: {data.playTitle} (display {data.numofDisplay} / {data.numofTotal}{data.statuses}) } // table head function thead() { return thumbnail title url } // item function item(datum) { return {datum.index}: {datum.title} {datum.url} } })(); // vim:sw=4 ts=4 et: href='#n179'>179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294