diff options
Diffstat (limited to 'readitlater.js')
-rw-r--r-- | readitlater.js | 80 |
1 files changed, 42 insertions, 38 deletions
diff --git a/readitlater.js b/readitlater.js index 49a5636..8d87fb7 100644 --- a/readitlater.js +++ b/readitlater.js @@ -9,9 +9,9 @@ let PLUGIN_INFO = <VimperatorPlugin> <name>readitlater</name> <description lang="ja">Read it Later を快適に使うためのプラグインです</description> - <version>0.2.1</version> + <version>0.3.0</version> <minVersion>3.0</minVersion> - <maxVersion>3.2</maxVersion> + <maxVersion>3.3</maxVersion> <author mail="ninja.tottori@gmail.com" homepage="http://twitter.com/ninja_tottori">ninja.tottori</author> <updateURL>https://github.com/vimpr/vimperator-plugins/raw/master/readitlater.js</updateURL> <detail lang="ja"><![CDATA[ @@ -36,6 +36,8 @@ let PLUGIN_INFO = :ril add 今見ているページのurlとtitleを登録します オプションとして url , title が選べるので適当に編集して登録もできます。 + また、URL の補完も効きます。 + URL補完は let g:readitlater_complete = "slf" のようにして使用する補完を選択できます。 :ril get 登録されてるページの情報を取得してキャッシュしときます。 @@ -77,6 +79,7 @@ let PLUGIN_INFO = function (args) { addItemByArgs(args); },{ + literal: 0, options : [ [["url","u"],commands.OPTION_STRING,null, (function(){ @@ -90,6 +93,7 @@ let PLUGIN_INFO = }) ], ], + completer: function (context, args) completion.url(context, liberator.globalVariables.readitlater_complete) } ), @@ -125,7 +129,7 @@ let PLUGIN_INFO = } ), - new Command(["stats"], "Retrieve information about a user's list", + new Command(["stats","s"], "Retrieve information about a user's list", function (args) { ReadItLater.stats(); },{} @@ -211,11 +215,11 @@ let PLUGIN_INFO = ); - req.addEventListener("onSuccess",function(data){ + req.addEventListener("success",function(data){ e(data.responseText) }); - req.addEventListener("onFailure",function(data){ + req.addEventListener("failure",function(data){ liberator.echoerr(data.statusText); liberator.echoerr(data.responseText); }); @@ -238,8 +242,8 @@ let PLUGIN_INFO = postBody:getParameterMap( { apikey : this.api_key, - username : encodeURIComponent(logins[0].username), - password : encodeURIComponent(logins[0].password), + username : logins[0].username, + password : logins[0].password, format : "json", count : (liberator.globalVariables.readitlater_get_count? liberator.globalVariables.readitlater_get_count : 50 ), //state : (args["read"]) ? "read" : "unread", @@ -251,8 +255,8 @@ let PLUGIN_INFO = ); - req.addEventListener("onSuccess",function(data) callback(libly.$U.evalJson(data.responseText))); - req.addEventListener("onFailure",function(data){ + req.addEventListener("success",function(data) callback(libly.$U.evalJson(data.responseText))); + req.addEventListener("failure",function(data){ liberator.echoerr(data.statusText); liberator.echoerr(data.responseText); }); @@ -273,19 +277,18 @@ let PLUGIN_INFO = postBody:getParameterMap( { apikey : this.api_key, - username : encodeURIComponent(logins[0].username), - password : encodeURIComponent(logins[0].password), - url : encodeURIComponent(url), - title : encodeURIComponent(title), + username : logins[0].username, + password : logins[0].password, + url : url, + title : title, } ) } ); + req.addEventListener("success",callback); - req.addEventListener("onSuccess",callback); - - req.addEventListener("onFailure",function(data){ + req.addEventListener("failure",function(data){ liberator.echoerr(data.statusText); liberator.echoerr(data.responseText); }); @@ -303,7 +306,7 @@ let PLUGIN_INFO = function make_read_list(args){ let o = {}; for (let i = 0; i < args.length; i++) { - o[i] = {"url":encodeURIComponent(args[i])}; + o[i] = {"url":args[i]}; }; return JSON.stringify(o); } @@ -316,8 +319,8 @@ let PLUGIN_INFO = postBody:getParameterMap( { apikey : this.api_key, - username : encodeURIComponent(logins[0].username), - password : encodeURIComponent(logins[0].password), + username : logins[0].username, + password : logins[0].password, read : make_read_list(urls), } ) @@ -325,14 +328,13 @@ let PLUGIN_INFO = ); var ref = this; - req.addEventListener("onSuccess",callback); + req.addEventListener("success",callback); - req.addEventListener("onFailure",function(data){ + req.addEventListener("failure",function(data){ liberator.echoerr(data.statusText); liberator.echoerr(data.responseText); }); - liberator.log(urls) req.post(); @@ -350,8 +352,8 @@ let PLUGIN_INFO = postBody:getParameterMap( { apikey : this.api_key, - username : encodeURIComponent(logins[0].username), - password : encodeURIComponent(logins[0].password), + username : logins[0].username, + password : logins[0].password, format : "json", } ) @@ -359,7 +361,7 @@ let PLUGIN_INFO = ); - req.addEventListener("onSuccess",function(data){ + req.addEventListener("success",function(data){ let res = libly.$U.evalJson(data.responseText); liberator.echo( <style type="text/css"><![CDATA[ @@ -375,7 +377,7 @@ let PLUGIN_INFO = ); }); - req.addEventListener("onFailure",function(data){ + req.addEventListener("failure",function(data){ liberator.echoerr(data.statusText); liberator.echoerr(data.responseText); }); @@ -400,7 +402,7 @@ let PLUGIN_INFO = ); - req.addEventListener("onSuccess",function(data){ + req.addEventListener("success",function(data){ liberator.echo( <div> X-Limit-User-Limit : {data.transport.getResponseHeader("X-Limit-User-Limit")} <br /> @@ -414,7 +416,7 @@ let PLUGIN_INFO = ); }); - req.addEventListener("onFailure",function(data){ + req.addEventListener("failure",function(data){ liberator.echoerr(data.statusText); liberator.echoerr(data.responseText); }); @@ -443,10 +445,12 @@ let PLUGIN_INFO = } // }}} function addItemByArgs(args){ // {{{ - let url = args["url"] || buffer.URL; - let title = args["title"] || buffer.title; - ReadItLater.add(url, title,function(){ - echo("Added: " + title) + let url = args["url"] || args.literalArg; + let title = args["title"] || (url ? undefined : buffer.title); + if (!url) + url = buffer.URL; + ReadItLater.add(url, title, function(){ + echo("Added: " + (title || url)); ListCache.update(true); }); } // }}} @@ -494,12 +498,11 @@ let PLUGIN_INFO = } // }}} function getParameterMap(parameters){ // {{{ - let map = ""; - for (let key in parameters){ - if (map) map += "&"; - map += key + "=" + parameters[key]; - } - return map + return [ + key + "=" + encodeURIComponent(value) + for ([key, value] in Iterator(parameters)) + if (value) + ].join("&"); } // }}} function countObjectValues(obj){ // {{{ @@ -519,3 +522,4 @@ let PLUGIN_INFO = })(); +// vim: set noet : |