From 3f11efc93457759337997f7b7b82a25892b12cd1 Mon Sep 17 00:00:00 2001 From: janus_wel Date: Wed, 1 Oct 2008 12:47:41 +0000 Subject: add :nicodescription git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@20390 d0d07461-0603-4401-acd4-de1884942a52 --- nicontroller.js | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 120 insertions(+), 11 deletions(-) (limited to 'nicontroller.js') diff --git a/nicontroller.js b/nicontroller.js index 3923e3d..28965d7 100644 --- a/nicontroller.js +++ b/nicontroller.js @@ -4,7 +4,7 @@ * @description this script give you keyboard opration for nicovideo.jp. * @description-ja ニコニコ動画のプレーヤーをキーボードで操作できるようにする。 * @author janus_wel - * @version 0.41 + * @version 0.50 * @minversion 1.2 * ==VimperatorPlugin== * @@ -36,6 +36,8 @@ * :nicovolume! delta * ボリュームを現在の値から変更する。 -100 ~ +100 を指定可能。 * 指定なしの場合変化しない。 + * :nicodescription + * 説明文・メニューの表示 / 非表示を切り替える * :nicomment comment * コメント欄を指定した文字列で埋める。 * 詳しい機能は http://d.hatena.ne.jp/janus_wel/20080913/1221317583 @@ -45,19 +47,21 @@ * 補完はけっこう賢くなったと思う。 * * 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. + * 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'). + * - 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 + * 2008/10/01 ver. 0.50 - add :nicodescription. * * */ @@ -102,7 +106,7 @@ EOM function NicoPlayerController(){} NicoPlayerController.prototype = { constants: { - VERSION: '0.41', + VERSION: '0.50', WATCH_URL: '^http://www\\.nicovideo\\.jp/watch/[a-z]{2}\\d+', TAG_URL: '^http://www\\.nicovideo\\.jp/tag/', WATCH_PAGE: 1, @@ -253,8 +257,70 @@ NicoPlayerController.prototype = { }; +// cookie manager +function CookieManager() { + this.initialize.apply(this, arguments); +} +CookieManager.prototype = { + initialize: function (uri) { + const Cc = Components.classes; + const Ci = Components.interfaces; + + const MOZILLA = '@mozilla.org/'; + const IO_SERVICE = MOZILLA + 'network/io-service;1'; + const COOKIE_SERVICE = MOZILLA + 'cookieService;1'; + + this.ioService = Cc[IO_SERVICE].getService(Ci.nsIIOService); + this.cookieService = Cc[COOKIE_SERVICE].getService(Ci.nsICookieService); + this.readCookie(uri); + }, + + readCookie: function (uri) { + if (uri) { + this.uri = uri; + this.uriObject = this.ioService.newURI(uri, null, null); + this.deserializeCookie(this._getCookieString()); + } + }, + + _getCookieString: function () { + return this.cookieService.getCookieString(this.uriObject, null); + }, + + _setCookieString: function (cookieString) { + this.cookieService.setCookieString(this.uriObject, null, cookieString, null); + }, + + deserializeCookie: function (cookieString) { + var cookies = cookieString.split('; '); + var cookie = {}; + var key, val; + for (var i=0, max=cookies.length ; i