- readitlater
- Read it Later を快適に使うためのプラグインです
- 0.1.2
- 3.0
- 3.0
- ninja.tottori
- https://github.com/vimpr/vimperator-plugins/raw/master/readitlater.js
- readitlater
+ Read it Later を快適に使うためのプラグインです
+ 0.1.2
+ 3.0
+ 3.0
+ ninja.tottori
+ https://github.com/vimpr/vimperator-plugins/raw/master/readitlater.js
+
+ ]]>
;
(function(){
- commands.addUserCommand(["ril","readitlater"], "Read It Late plugin",
- function(args){
- ReadItLater.add(args);
- },
- {
- subCommands: [
- new Command(["add","a"], "Add a page to a user's list",
- function (args) {
- ReadItLater.add(args);
- },{
+ commands.addUserCommand(["ril","readitlater"], "Read It Late plugin",
+ function(args){
+ ReadItLater.add(args);
+ },
+ {
+ subCommands: [
+ new Command(["add","a"], "Add a page to a user's list",
+ function (args) {
+ ReadItLater.add(args);
+ },{
options : [
- [["url","u"],commands.OPTION_STRING,null,
- (function(){
- return [[ buffer.URL ,"target url"]]
- })
- ],
-
- [["title","t"],commands.OPTION_STRING,null,
- (function(){
- return [[ buffer.title ,"title"]]
- })
- ],
+ [["url","u"],commands.OPTION_STRING,null,
+ (function(){
+ return [[ buffer.URL ,"target url"]]
+ })
+ ],
+
+ [["title","t"],commands.OPTION_STRING,null,
+ (function(){
+ return [[ buffer.title ,"title"]]
+ })
+ ],
],
- }
- ),
+ }
+ ),
- new Command(["get","g"], "Retrieve a user's reading list",
- function (args) {
- ReadItLater.get(args);
- },{
+ new Command(["get","g"], "Retrieve a user's reading list",
+ function (args) {
+ ReadItLater.get(args);
+ },{
options : [
- //[["num"],commands.OPTION_INT],
- //[["read","-r"],commands.OPTION_NOARG],
- //[["tags","-t"],commands.OPTION_NOARG],
- //[["myAppOnly"],commands.OPTION_NOARG],
+ //[["num"],commands.OPTION_INT],
+ //[["read","-r"],commands.OPTION_NOARG],
+ //[["tags","-t"],commands.OPTION_NOARG],
+ //[["myAppOnly"],commands.OPTION_NOARG],
],
- }
- ),
-
- new Command(["open","o"], "Open url in new tab from RIL list.",
- function (args) {
- ReadItLater.open(args);
- },{
- bang: true,
- completer : list_completer,
- }
- ),
-
- new Command(["read","r"], "Mark items as read.",
- function (args) {
- ReadItLater.send(args);
- },{
- bang: true,
- completer : list_completer,
- }
- ),
-
- new Command(["stats"], "Retrieve information about a user's list",
- function (args) {
- ReadItLater.stats();
- },{}
- ),
-
- /*
- new Command(["test"], "Return stats / current rate limit information about your API key",
- function () {
- ReadItLater.apiTest();
- },{}
- ),
- */
+ }
+ ),
+
+ new Command(["open","o"], "Open url in new tab from RIL list.",
+ function (args) {
+ ReadItLater.open(args);
+ },{
+ bang: true,
+ completer : list_completer,
+ }
+ ),
+
+ new Command(["read","r"], "Mark items as read.",
+ function (args) {
+ ReadItLater.send(args);
+ },{
+ bang: true,
+ completer : list_completer,
+ }
+ ),
+
+ new Command(["stats"], "Retrieve information about a user's list",
+ function (args) {
+ ReadItLater.stats();
+ },{}
+ ),
+
+ /*
+ new Command(["test"], "Return stats / current rate limit information about your API key",
+ function () {
+ ReadItLater.apiTest();
+ },{}
+ ),
+ */
],
- },
- true
+ },
+ true
);
let ReadItLater = {
- api_key : (liberator.globalVariables.readitlater_api_key) ? liberator.globalVariables.readitlater_api_key : "966T6ahYgb081icU10d44byL31p5bF20" ,
+ api_key : (liberator.globalVariables.readitlater_api_key) ? liberator.globalVariables.readitlater_api_key : "966T6ahYgb081icU10d44byL31p5bF20" ,
- text : function(){ // {{{
+ text : function(){ // {{{
let req = new libly.Request(
- "https://text.readitlaterlist.com/v2/text" , // url
- null, // headers
- { // options
- asynchronous:true,
- postBody:getParameterMap(
- {
- apikey : this.api_key,
- url : buffer.URL,
- mode : "less",
- images : 0,
- }
- )
- }
-
+ "https://text.readitlaterlist.com/v2/text" , // url
+ null, // headers
+ { // options
+ asynchronous:true,
+ postBody:getParameterMap(
+ {
+ apikey : this.api_key,
+ url : buffer.URL,
+ mode : "less",
+ images : 0,
+ }
+ )
+ }
+
);
req.addEventListener("onSuccess",function(data){
- e(data.responseText)
+ e(data.responseText)
});
req.addEventListener("onFailure",function(data){
- liberator.echoerr(data.statusText);
- liberator.echoerr(data.responseText);
+ liberator.echoerr(data.statusText);
+ liberator.echoerr(data.responseText);
});
req.post();
-
- }, // }}}
-
+ }, // }}}
- get : function(args,silent){ // {{{
+ get : function(args,silent){ // {{{
// document => http://readitlaterlist.com/api/docs#get
let manager = Components.classes["@mozilla.org/login-manager;1"].getService(Components.interfaces.nsILoginManager);
@@ -190,92 +188,91 @@ let PLUGIN_INFO =
let store = storage.newMap("readitlater",{store:true});
let req = new libly.Request(
- "https://readitlaterlist.com/v2/get" , // url
- null, // headers
- { // options
+ "https://readitlaterlist.com/v2/get" , // url
+ null, // headers
+ { // options
asynchronous:true,
postBody:getParameterMap(
- {
- apikey : this.api_key,
- username : encodeURIComponent(logins[0].username),
- password : encodeURIComponent(logins[0].password),
- format : "json",
- count : (liberator.globalVariables.readitlater_get_count? liberator.globalVariables.readitlater_get_count : 50 ),
- //state : (args["read"]) ? "read" : "unread",
- //tags : (args["tags"]) ? 1 : 0,
- //myAppOnly : (args["myAppOnly"]) ? 1 : 0,
- }
+ {
+ apikey : this.api_key,
+ username : encodeURIComponent(logins[0].username),
+ password : encodeURIComponent(logins[0].password),
+ format : "json",
+ count : (liberator.globalVariables.readitlater_get_count? liberator.globalVariables.readitlater_get_count : 50 ),
+ //state : (args["read"]) ? "read" : "unread",
+ //tags : (args["tags"]) ? 1 : 0,
+ //myAppOnly: (args["myAppOnly"]) ? 1 : 0,
+ }
)
- }
-
+ }
+
);
req.addEventListener("onSuccess",function(data){
- let res = libly.$U.evalJson(data.responseText);
- let cnt = 0;
- for (let key in res.list){
- store.set(key,res.list[key]);
- cnt++;
- }
- if(!silent){liberator.echo("[ReadItLater] " + cnt + " found.")};
- store.save();
+ let res = libly.$U.evalJson(data.responseText);
+ let cnt = 0;
+ for (let key in res.list){
+ store.set(key,res.list[key]);
+ cnt++;
+ }
+ if(!silent){liberator.echo("[ReadItLater] " + cnt + " found.")};
+ store.save();
});
req.addEventListener("onFailure",function(data){
- liberator.echoerr(data.statusText);
- liberator.echoerr(data.responseText);
+ liberator.echoerr(data.statusText);
+ liberator.echoerr(data.responseText);
});
req.post();
-
- }, // }}}
+ }, // }}}
- add : function(args){ // {{{
+ add : function(args){ // {{{
let manager = Components.classes["@mozilla.org/login-manager;1"].getService(Components.interfaces.nsILoginManager);
let logins = manager.findLogins({},"http://readitlaterlist.com","",null);
let req = new libly.Request(
- "https://readitlaterlist.com/v2/add" , // url
- null, // headers
- { // options
+ "https://readitlaterlist.com/v2/add" , // url
+ null, // headers
+ { // options
asynchronous:true,
postBody:getParameterMap(
- {
- apikey : this.api_key,
- username : encodeURIComponent(logins[0].username),
- password : encodeURIComponent(logins[0].password),
- url : encodeURIComponent((args["url"]) ? (args["url"]) : buffer.URL),
- title : encodeURIComponent((args["title"]) ? args["title"] : buffer.title),
- }
+ {
+ apikey : this.api_key,
+ username : encodeURIComponent(logins[0].username),
+ password : encodeURIComponent(logins[0].password),
+ url : encodeURIComponent((args["url"]) ? (args["url"]) : buffer.URL),
+ title : encodeURIComponent((args["title"]) ? args["title"] : buffer.title),
+ }
)
- }
-
+ }
+
);
var ref = this;
req.addEventListener("onSuccess",function(data){
- liberator.echo("[ReadItLater] OK.")
- ref.get(null,true);
+ liberator.echo("[ReadItLater] OK.")
+ ref.get(null,true);
});
req.addEventListener("onFailure",function(data){
- liberator.echoerr(data.statusText);
- liberator.echoerr(data.responseText);
+ liberator.echoerr(data.statusText);
+ liberator.echoerr(data.responseText);
});
req.post();
-
- }, // }}}
- open : function(args){ //{{{
+ }, // }}}
+
+ open : function(args){ //{{{
liberator.open(args, liberator.NEW_BACKGROUND_TAB);
- if(liberator.globalVariables.readitlater_open_as_read == 1) this.send(args);
+ if(liberator.globalVariables.readitlater_open_as_read == 1) this.send(args);
- }, // }}}
+ }, // }}}
- send : function(args) { //{{{
+ send : function(args) { //{{{
// http://readitlaterlist.com/api/docs/#send
let manager = Components.classes["@mozilla.org/login-manager;1"].getService(Components.interfaces.nsILoginManager);
@@ -290,103 +287,101 @@ let PLUGIN_INFO =
};
let req = new libly.Request(
- "https://readitlaterlist.com/v2/send" , // url
- null, // headers
- { // options
- asynchronous:true,
- postBody:getParameterMap(
- {
- apikey : this.api_key,
- username : encodeURIComponent(logins[0].username),
- password : encodeURIComponent(logins[0].password),
- read : make_read_list(args),
- }
- )
- }
+ "https://readitlaterlist.com/v2/send" , // url
+ null, // headers
+ { // options
+ asynchronous:true,
+ postBody:getParameterMap(
+ {
+ apikey : this.api_key,
+ username : encodeURIComponent(logins[0].username),
+ password : encodeURIComponent(logins[0].password),
+ read : make_read_list(args),
+ }
+ )
+ }
);
-
+
var ref = this;
req.addEventListener("onSuccess",function(data){
- liberator.echo("[ReadItLater] OK.")
- ref.get(null,true);
+ liberator.echo("[ReadItLater] OK.")
+ ref.get(null,true);
});
req.addEventListener("onFailure",function(data){
- liberator.echoerr(data.statusText);
- liberator.echoerr(data.responseText);
+ liberator.echoerr(data.statusText);
+ liberator.echoerr(data.responseText);
});
req.post();
-
- }, // }}}
- stats : function(){ // {{{
+ }, // }}}
+
+ stats : function(){ // {{{
let manager = Components.classes["@mozilla.org/login-manager;1"].getService(Components.interfaces.nsILoginManager);
let logins = manager.findLogins({},"http://readitlaterlist.com","",null);
let req = new libly.Request(
- "https://readitlaterlist.com/v2/stats" , // url
- null, // headers
- { // options
- asynchronous:true,
- postBody:getParameterMap(
- {
- apikey : this.api_key,
- username : encodeURIComponent(logins[0].username),
- password : encodeURIComponent(logins[0].password),
- format : "json",
- }
- )
- }
-
+ "https://readitlaterlist.com/v2/stats" , // url
+ null, // headers
+ { // options
+ asynchronous:true,
+ postBody:getParameterMap(
+ {
+ apikey : this.api_key,
+ username : encodeURIComponent(logins[0].username),
+ password : encodeURIComponent(logins[0].password),
+ format : "json",
+ }
+ )
+ }
+
);
req.addEventListener("onSuccess",function(data){
- let res = libly.$U.evalJson(data.responseText);
- liberator.echo(
+ let res = libly.$U.evalJson(data.responseText);
+ liberator.echo(
+
- #ReadItLater Stats
+
+ ]]> +
+ #ReadItLater Stats
+
- since : {unixtimeToDate(res.user_since)}
- list : {res.count_list}
- unread : {res.count_unread}
- read : {res.count_read}
+ since : {unixtimeToDate(res.user_since)}
+ list : {res.count_list}
+ unread : {res.count_unread}
+ read : {res.count_read}
- );
+ );
});
req.addEventListener("onFailure",function(data){
- liberator.echoerr(data.statusText);
- liberator.echoerr(data.responseText);
+ liberator.echoerr(data.statusText);
+ liberator.echoerr(data.responseText);
});
req.post();
-
- }, // }}}
-
+ }, // }}}
- apiTest : function(){ // {{{
+ apiTest : function(){ // {{{
let req = new libly.Request(
- "https://readitlaterlist.com/v2/api" , // url
- null, // headers
- { // options
+ "https://readitlaterlist.com/v2/api" , // url
+ null, // headers
+ { // options
asynchronous:true,
postBody:getParameterMap(
- {
- apikey : this.api_key,
- }
+ {
+ apikey : this.api_key,
+ }
)
- }
-
+ }
+
);
req.addEventListener("onSuccess",function(data){
- liberator.echo(
+ liberator.echo(
X-Limit-User-Limit : {data.transport.getResponseHeader("X-Limit-User-Limit")}
X-Limit-User-Remaining : {data.transport.getResponseHeader("X-Limit-User-Remaining")}
@@ -394,21 +389,19 @@ let PLUGIN_INFO =
X-Limit-Key-Limit : {data.transport.getResponseHeader("X-Limit-Key-Limit")}
X-Limit-Key-Remaining : {data.transport.getResponseHeader("X-Limit-Key-Remaining")}
X-Limit-Key-Reset : {data.transport.getResponseHeader("X-Limit-Key-Reset")}
-
+
);
});
req.addEventListener("onFailure",function(data){
- liberator.echoerr(data.statusText);
- liberator.echoerr(data.responseText);
+ liberator.echoerr(data.statusText);
+ liberator.echoerr(data.responseText);
});
req.post();
-
- }, // }}}
-
+ }, // }}}
}
@@ -428,7 +421,7 @@ let PLUGIN_INFO =
context.title = ["url","title"]
context.filters = [CompletionContext.Filter.textDescription]; // titleも補完対象にする
- context.compare = void 0;
+ context.compare = void 0;
context.anchored = false;
context.completions = (function(){
let links = [];
@@ -445,31 +438,26 @@ let PLUGIN_INFO =
} //}}}
+ function unixtimeToDate(ut) { // {{{
+ var t = new Date( ut * 1000 );
+ t.setTime( t.getTime() + (60*60*1000 * 9) ); // +9は日本のタイムゾーン
+ return t;
+ } // }}}
+
+ function getParameterMap(parameters){ // {{{
+ let map = "";
+ for (let key in parameters){
+ if (map) map += "&";
+ map += key + "=" + parameters[key];
+ }
+ return map
+ } // }}}
-
-
- function unixtimeToDate(ut) {
- var t = new Date( ut * 1000 );
- t.setTime( t.getTime() + (60*60*1000 * 9) ); // +9は日本のタイムゾーン
- return t;
- }
-
- function getParameterMap(parameters){
- let map = "";
- for (let key in parameters){
- if (map) map += "&";
- map += key + "=" + parameters[key];
- }
- return map
- }
-
- // for debug
- function e(v,c){
- if(c) util.copyToClipboard(v);
- liberator.log(v,-1)
- }
+ // for debug {{{
+ function e(v,c){
+ if(c) util.copyToClipboard(v);
+ liberator.log(v,-1)
+ } // }}}
})();
-
-
--
cgit v1.2.3
From 70ba3bea9810b4a7438fa486292f1272508c52cf Mon Sep 17 00:00:00 2001
From: anekos
Date: Wed, 4 May 2011 05:02:57 +0900
Subject: 補完の非同期化とキャッシュ対応
---
readitlater.js | 157 +++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 102 insertions(+), 55 deletions(-)
diff --git a/readitlater.js b/readitlater.js
index df8f253..4d85b54 100644
--- a/readitlater.js
+++ b/readitlater.js
@@ -69,13 +69,13 @@ let PLUGIN_INFO =
commands.addUserCommand(["ril","readitlater"], "Read It Late plugin",
function(args){
- ReadItLater.add(args);
+ addItemByArgs(args);
},
{
subCommands: [
new Command(["add","a"], "Add a page to a user's list",
function (args) {
- ReadItLater.add(args);
+ addItemByArgs(args);
},{
options : [
[["url","u"],commands.OPTION_STRING,null,
@@ -95,7 +95,7 @@ let PLUGIN_INFO =
new Command(["get","g"], "Retrieve a user's reading list",
function (args) {
- ReadItLater.get(args);
+ ListCache.update(true, function(data) echo([1 for (_ in Iterator(data.list))].length + " found."));
},{
options : [
//[["num"],commands.OPTION_INT],
@@ -108,7 +108,8 @@ let PLUGIN_INFO =
new Command(["open","o"], "Open url in new tab from RIL list.",
function (args) {
- ReadItLater.open(args);
+ liberator.open(args, liberator.NEW_BACKGROUND_TAB);
+ if(liberator.globalVariables.readitlater_open_as_read == 1) markAsRead(args);
},{
bang: true,
completer : list_completer,
@@ -117,7 +118,7 @@ let PLUGIN_INFO =
new Command(["read","r"], "Mark items as read.",
function (args) {
- ReadItLater.send(args);
+ markAsRead(args);
},{
bang: true,
completer : list_completer,
@@ -144,6 +145,47 @@ let PLUGIN_INFO =
true
);
+ const CacheStore = storage.newMap("readitlater",{store:true});
+
+ function Cache ({updater, name, limit}) {
+ this.limit = limit || 10 * 1000 * 60;
+ this.name = name;
+ this.updater = updater;
+ }
+
+ Cache.prototype = {
+ get cache() CacheStore.get(name, void 0),
+ set cache(value) CacheStore.set(name, value),
+
+ get: function(callback){ // {{{
+ let self = this;
+
+ if (this.isExpired || !this.cache) {
+ this.lastUpdated = new Date().getTime();
+ this.update(true, callback);
+ return;
+ }
+
+ callback(this.cache);
+ }, // }}}
+
+ update: function(force, callback){ // {{{
+ if (!force && !this.isExpired)
+ return;
+
+ let self = this;
+
+ liberator.log('[ReadItLater] cache updating');
+ this.updater(function(data){
+ self.cache = data;
+ if (callback) callback(data);
+ });
+ }, //}}}
+
+ save: function() CacheStore.save(),
+
+ get isExpired() (!this.lastUpdated || (new Date().getTime() > (this.lastUpdated + this.limit)))
+ };
let ReadItLater = {
api_key : (liberator.globalVariables.readitlater_api_key) ? liberator.globalVariables.readitlater_api_key : "966T6ahYgb081icU10d44byL31p5bF20" ,
@@ -180,12 +222,11 @@ let PLUGIN_INFO =
}, // }}}
- get : function(args,silent){ // {{{
+ get : function(callback){ // {{{
// document => http://readitlaterlist.com/api/docs#get
let manager = Components.classes["@mozilla.org/login-manager;1"].getService(Components.interfaces.nsILoginManager);
let logins = manager.findLogins({},"http://readitlaterlist.com","",null);
- let store = storage.newMap("readitlater",{store:true});
let req = new libly.Request(
"https://readitlaterlist.com/v2/get" , // url
@@ -208,17 +249,7 @@ let PLUGIN_INFO =
);
- req.addEventListener("onSuccess",function(data){
- let res = libly.$U.evalJson(data.responseText);
- let cnt = 0;
- for (let key in res.list){
- store.set(key,res.list[key]);
- cnt++;
- }
- if(!silent){liberator.echo("[ReadItLater] " + cnt + " found.")};
- store.save();
- });
-
+ req.addEventListener("onSuccess",function(data) callback(libly.$U.evalJson(data.responseText)));
req.addEventListener("onFailure",function(data){
liberator.echoerr(data.statusText);
liberator.echoerr(data.responseText);
@@ -228,7 +259,7 @@ let PLUGIN_INFO =
}, // }}}
- add : function(args){ // {{{
+ add : function(url,title,callback){ // {{{
let manager = Components.classes["@mozilla.org/login-manager;1"].getService(Components.interfaces.nsILoginManager);
let logins = manager.findLogins({},"http://readitlaterlist.com","",null);
@@ -242,19 +273,15 @@ let PLUGIN_INFO =
apikey : this.api_key,
username : encodeURIComponent(logins[0].username),
password : encodeURIComponent(logins[0].password),
- url : encodeURIComponent((args["url"]) ? (args["url"]) : buffer.URL),
- title : encodeURIComponent((args["title"]) ? args["title"] : buffer.title),
+ url : encodeURIComponent(url),
+ title : encodeURIComponent(title),
}
)
}
);
- var ref = this;
- req.addEventListener("onSuccess",function(data){
- liberator.echo("[ReadItLater] OK.")
- ref.get(null,true);
- });
+ req.addEventListener("onSuccess",callback);
req.addEventListener("onFailure",function(data){
liberator.echoerr(data.statusText);
@@ -265,14 +292,7 @@ let PLUGIN_INFO =
}, // }}}
- open : function(args){ //{{{
-
- liberator.open(args, liberator.NEW_BACKGROUND_TAB);
- if(liberator.globalVariables.readitlater_open_as_read == 1) this.send(args);
-
- }, // }}}
-
- send : function(args) { //{{{
+ send : function(urls, callback) { //{{{
// http://readitlaterlist.com/api/docs/#send
let manager = Components.classes["@mozilla.org/login-manager;1"].getService(Components.interfaces.nsILoginManager);
@@ -284,7 +304,7 @@ let PLUGIN_INFO =
o[i] = {"url":encodeURIComponent(args[i])};
};
return JSON.stringify(o);
- };
+ }
let req = new libly.Request(
"https://readitlaterlist.com/v2/send" , // url
@@ -296,23 +316,21 @@ let PLUGIN_INFO =
apikey : this.api_key,
username : encodeURIComponent(logins[0].username),
password : encodeURIComponent(logins[0].password),
- read : make_read_list(args),
+ read : make_read_list(urls),
}
)
}
);
var ref = this;
- req.addEventListener("onSuccess",function(data){
- liberator.echo("[ReadItLater] OK.")
- ref.get(null,true);
- });
+ req.addEventListener("onSuccess",callback);
req.addEventListener("onFailure",function(data){
liberator.echoerr(data.statusText);
liberator.echoerr(data.responseText);
});
+ liberator.log(urls)
req.post();
@@ -405,6 +423,35 @@ let PLUGIN_INFO =
}
+ let ListCache = new Cache({name: 'list', updater: ReadItLater.get.bind(ReadItLater)}); // {{{
+ ListCache.remove = function(url){
+ if (!this.cache)
+ return this.udpate(true);
+ let names = [n for ([n, v] in Iterator(this.cache.list)) if (v.url == url)];
+ for (let [, name] in Iterator(names))
+ delete this.cache.list[name];
+ this.save();
+ this.update();
+ }; // }}}
+
+ function markAsRead(urls){ // {{{
+ for (let [, url] in Iterator(urls))
+ ListCache.remove(url);
+ ReadItLater.send(urls, echo.bind(null, "Mark as read: " + urls.length));
+ } // }}}
+
+ function addItemByArgs(args){
+ let url = args["url"] || buffer.URL;
+ ReadItLater.add(url, args["title"] || buffer.title,function(){
+ echo("Added: " + title)
+ ListCache.update(true);
+ });
+ }
+
+ function echo(msg){ // {{{
+ liberator.echo("[ReadItLater] " + msg);
+ } // }}}
+
function list_completer(context,args){ // {{{
function sortDate(store){
@@ -416,25 +463,20 @@ let PLUGIN_INFO =
return ary;
}
- let store = storage.newMap("readitlater",{store:true});
- let list = sortDate(store);
-
context.title = ["url","title"]
context.filters = [CompletionContext.Filter.textDescription]; // titleも補完対象にする
context.compare = void 0;
context.anchored = false;
- context.completions = (function(){
- let links = [];
- for(let i in list){
- let item = list[i][1];
- if(!args["bang"]){
- if(item.state == 0) links.push([item.url,item.title]); // 既読のみ
- }else{
- if(item.state == 1) links.push([item.url,item.title]); // 未読のみ
- }
- }
- return links;
- })();
+ context.incomplete = true;
+
+ ListCache.get(function(data){
+ context.completions = [
+ [item.url,item.title]
+ for([, item] in Iterator(data.list))
+ if(!args["bang"] ? item.state == 0 : item.state == 1)
+ ];
+ context.incomplete = false;
+ });
} //}}}
@@ -459,5 +501,10 @@ let PLUGIN_INFO =
liberator.log(v,-1)
} // }}}
+ // Export {{{
+ __context__.Cache = Cache;
+ __context__.API = ReadItLater;
+ // }}}
+
})();
--
cgit v1.2.3
From 458415e941674bf2990cf4b8142ab0f91bc9b409 Mon Sep 17 00:00:00 2001
From: anekos
Date: Wed, 4 May 2011 05:28:43 +0900
Subject: 関数名修正
---
readitlater.js | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/readitlater.js b/readitlater.js
index 4d85b54..da8a88f 100644
--- a/readitlater.js
+++ b/readitlater.js
@@ -112,7 +112,7 @@ let PLUGIN_INFO =
if(liberator.globalVariables.readitlater_open_as_read == 1) markAsRead(args);
},{
bang: true,
- completer : list_completer,
+ completer : listCompleter,
}
),
@@ -121,7 +121,7 @@ let PLUGIN_INFO =
markAsRead(args);
},{
bang: true,
- completer : list_completer,
+ completer : listCompleter,
}
),
@@ -452,7 +452,7 @@ let PLUGIN_INFO =
liberator.echo("[ReadItLater] " + msg);
} // }}}
- function list_completer(context,args){ // {{{
+ function listCompleter(context,args){ // {{{
function sortDate(store){
let ary = [];
@@ -473,7 +473,11 @@ let PLUGIN_INFO =
context.completions = [
[item.url,item.title]
for([, item] in Iterator(data.list))
- if(!args["bang"] ? item.state == 0 : item.state == 1)
+ if(
+ !args.some(function (arg) arg == item.url)
+ &&
+ (!args["bang"] ? item.state == 0 : item.state == 1)
+ )
];
context.incomplete = false;
});
--
cgit v1.2.3
From d798955c062f86ddc6e6503c282729f4e3e04888 Mon Sep 17 00:00:00 2001
From: anekos
Date: Wed, 4 May 2011 05:37:57 +0900
Subject: 公開オブジェクトのまつがい修正
---
readitlater.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/readitlater.js b/readitlater.js
index da8a88f..cbf5973 100644
--- a/readitlater.js
+++ b/readitlater.js
@@ -506,7 +506,7 @@ let PLUGIN_INFO =
} // }}}
// Export {{{
- __context__.Cache = Cache;
+ __context__.ListCache = ListCache;
__context__.API = ReadItLater;
// }}}
--
cgit v1.2.3
From d871ca944f5f1292e956f48ad8608679cd553047 Mon Sep 17 00:00:00 2001
From: anekos
Date: Wed, 4 May 2011 12:07:16 +0900
Subject: 折り畳み忘れ
---
readitlater.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/readitlater.js b/readitlater.js
index cbf5973..46a78ee 100644
--- a/readitlater.js
+++ b/readitlater.js
@@ -440,13 +440,13 @@ let PLUGIN_INFO =
ReadItLater.send(urls, echo.bind(null, "Mark as read: " + urls.length));
} // }}}
- function addItemByArgs(args){
+ function addItemByArgs(args){ // {{{
let url = args["url"] || buffer.URL;
ReadItLater.add(url, args["title"] || buffer.title,function(){
echo("Added: " + title)
ListCache.update(true);
});
- }
+ } // }}}
function echo(msg){ // {{{
liberator.echo("[ReadItLater] " + msg);
--
cgit v1.2.3
From d0e6b2add77bd7edeaf7843b880a473044625806 Mon Sep 17 00:00:00 2001
From: anekos
Date: Wed, 4 May 2011 12:12:54 +0900
Subject: 関数化
---
readitlater.js | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/readitlater.js b/readitlater.js
index 46a78ee..fa8e732 100644
--- a/readitlater.js
+++ b/readitlater.js
@@ -95,7 +95,7 @@ let PLUGIN_INFO =
new Command(["get","g"], "Retrieve a user's reading list",
function (args) {
- ListCache.update(true, function(data) echo([1 for (_ in Iterator(data.list))].length + " found."));
+ ListCache.update(true, function(data) echo(countObjectValues(data.list) + " found."));
},{
options : [
//[["num"],commands.OPTION_INT],
@@ -147,6 +147,7 @@ let PLUGIN_INFO =
const CacheStore = storage.newMap("readitlater",{store:true});
+ // Cache {{{
function Cache ({updater, name, limit}) {
this.limit = limit || 10 * 1000 * 60;
this.name = name;
@@ -186,6 +187,7 @@ let PLUGIN_INFO =
get isExpired() (!this.lastUpdated || (new Date().getTime() > (this.lastUpdated + this.limit)))
};
+ // }}}
let ReadItLater = {
api_key : (liberator.globalVariables.readitlater_api_key) ? liberator.globalVariables.readitlater_api_key : "966T6ahYgb081icU10d44byL31p5bF20" ,
@@ -499,6 +501,10 @@ let PLUGIN_INFO =
return map
} // }}}
+ function countObjectValues(obj){ // {{{
+ return [1 for (_ in Iterator(obj))].length;
+ } // }}}
+
// for debug {{{
function e(v,c){
if(c) util.copyToClipboard(v);
--
cgit v1.2.3
From dbf8c4d736e73c01c02dfbdb39a313dde920bdb0 Mon Sep 17 00:00:00 2001
From: anekos
Date: Wed, 4 May 2011 12:13:31 +0900
Subject: version++
---
readitlater.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/readitlater.js b/readitlater.js
index fa8e732..1302bf2 100644
--- a/readitlater.js
+++ b/readitlater.js
@@ -9,9 +9,9 @@ let PLUGIN_INFO =
readitlater
Read it Later を快適に使うためのプラグインです
- 0.1.2
+ 0.2.0
3.0
- 3.0
+ 3.1
ninja.tottori
https://github.com/vimpr/vimperator-plugins/raw/master/readitlater.js