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 --- nicontroller.js | 523 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 523 insertions(+) create mode 100644 nicontroller.js (limited to 'nicontroller.js') diff --git a/nicontroller.js b/nicontroller.js new file mode 100644 index 0000000..283d433 --- /dev/null +++ b/nicontroller.js @@ -0,0 +1,523 @@ +/* + * ==VimperatorPlugin== + * @name nicontroller.js + * @description this script give you keyboard opration for nicovideo.jp. + * @description-ja ニコニコ動画のプレーヤーをキーボードで操作できるようにする。 + * @author janus_wel + * @version 0.41 + * @minversion 1.2 + * ==VimperatorPlugin== + * + * LICENSE + * New BSD License + * + * USAGE + * :nicoinfo + * プレーヤーに関しての情報を表示する。今のところバージョンだけ。 + * :nicopause + * 再生 / 一時停止を切り替える。 + * :nicomute + * 音声あり / なしを切り替える。 + * :nicommentvisible + * コメント表示 / 非表示を切り替える。 + * :nicorepeat + * リピート再生するかどうかを切り替える。 + * :nicosize + * 最大化 / ノーマルを切り替える。 + * :nicoseek [position] + * 指定した場所にシークする。秒数で指定が可能。 + * 指定なしの場合一番最初にシークする。 + * :nicoseek! delta + * 現在の位置から delta 分離れた所にシークする。秒数で指定が可能。 + * マイナスを指定すると戻る。指定なしの場合変化しない。 + * :nicovolume [volume] + * ボリュームを設定する。 0 ~ 100 が指定できる。 + * 指定なしの場合 100 にセットする。 + * :nicovolume! delta + * ボリュームを現在の値から変更する。 -100 ~ +100 を指定可能。 + * 指定なしの場合変化しない。 + * :nicomment comment + * コメント欄を指定した文字列で埋める。 + * 詳しい機能は http://d.hatena.ne.jp/janus_wel/20080913/1221317583 + * :nicommand command + * コマンド欄を指定した文字列で埋める。 + * プレミアムかどうかで補完可能なコマンドも変化。 + * 補完はけっこう賢くなったと思う。 + * + * HISTORY + * 2008/07/13 ver. 0.10 initial written. + * 2008/07/14 ver. 0.20 add nicosize, nicoseek, nicovolume. + * 2008/07/15 ver. 0.30 add nicoinfo. + * 2008/07/19 ver. 0.31 allow assign mm:ss format to seekTo method. + * thanks to id:nokturnalmortum + * refer: http://d.hatena.ne.jp/nokturnalmortum/20080718#1216314934 + * fix error message. + * 2008/09/12 ver. 0.40 completer function of :nicommand -> usefull. + * add feature: comment input assistance. + * 2008/09/14 ver. 0.41 fix the bug that happen by adding method to Array. + * fix the nicopause bug associated with flvplayer's status('buffering' and 'end'). + * thanks to なまえ (no name ?) + * refer: http://d.hatena.ne.jp/janus_wel/20080914/1221387317 + * + * */ + +/* +_vimperatorrc に以下のスクリプトを貼り付けると幸せになれるかも +コマンド ( [',n-'] や [',n+'] の部分 ) は適宜変えてね。 + +javascript </g, LF); + + if(command) { + controller.setValue('inputArea.MailInput.text', command); + } + controller.setValue('ChatInput.text', comment); + } + catch(e) { liberator.echoerr(e); } + }, + {} +); + +liberator.commands.addUserCommand( + ['nicommand'], + 'fill command box', + function(arg) { + try { controller.setValue('inputArea.MailInput.text', arg); } + catch(e) { liberator.echoerr(e); } + }, + { + completer: function(arg){ + // get available commands by roll + var availableCommands = controller.getAvailableCommands(); + + // for no argument + if(!arg) { return [0, availableCommands]; } + + // make array of inputted words + // and current input word shoud be last (dayone ?) + var inputted = arg.toLowerCase().split(/\s+/); + var current = inputted[inputted.length - 1]; + // complete position is the top of last word + var completePosition = arg.lastIndexOf(' ') + 1; + + // exclude inputted word from candidates + var candidates = availableCommands.filter( function(commandSet) { + for(var i=0, numofInputted=inputted.length ; i 1) { + command = temp.shift(); + comment = temp.join(COMMAND_SEPARATOR); + } + else { + comment = arg; + } + + // ex_command is putted in braces + if(comment.match(/^\{([^\}]+)\}(.+)/)) { + var exCommand = RegExp.$1; + var text = RegExp.$2; + + var properties = analysisExCommand(exCommand); + + // fine tune command about comment size + if(properties.size) { + if(command) { + command = command.replace(/\s*big\s*/g, ' ') + .replace(/\s*medium\s*/g, ' ') + .replace(/\s*small\s*/g, ' '); + } + command += ' ' + properties.size; + } + + // expand!! + comment = buildLineBreakString(properties.line) + text; + if(properties.fixFlag) { + var post = buildLineBreakString(properties.max - properties.line + 1); + comment += post + NBSP; + } + } + + return [command, comment]; +} + +// " " and on each line +function buildLineBreakString(numof) { + // faster than string concatenate (+, +=) + var string = Array(numof * 2); + for(var i=1 ; i properties.max) line = properties.max; + properties.line = line; + } + + return properties; +} +})(); + +// vim: set sw=4 ts=4 et; -- cgit v1.2.3