aboutsummaryrefslogtreecommitdiffstats
path: root/readitlater.js
diff options
context:
space:
mode:
authoranekos2011-11-28 10:37:47 +0900
committeranekos2011-11-28 10:37:47 +0900
commit0b06fcc75f4a914c7217a2352220de4056a6bbb9 (patch)
tree2ff24daa03ffc37c52ba4c7a8141814bfdacbfbe /readitlater.js
parent3dc39393599777bda264bf2d63068d36a5cbbf2d (diff)
downloadvimperator-plugins-0b06fcc75f4a914c7217a2352220de4056a6bbb9.tar.bz2
Get full unread list
Diffstat (limited to 'readitlater.js')
-rw-r--r--readitlater.js37
1 files changed, 19 insertions, 18 deletions
diff --git a/readitlater.js b/readitlater.js
index 8d87fb7..73a38d5 100644
--- a/readitlater.js
+++ b/readitlater.js
@@ -189,7 +189,16 @@ let PLUGIN_INFO =
save: function() CacheStore.save(),
- get isExpired() (!this.lastUpdated || (new Date().getTime() > (this.lastUpdated + this.limit)))
+ get isExpired() (!this.lastUpdated || (new Date().getTime() > (this.lastUpdated + this.limit))),
+ 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();
+ } // }}}
};
// }}}
@@ -228,7 +237,7 @@ let PLUGIN_INFO =
}, // }}}
- get : function(callback){ // {{{
+ get : function(state, callback){ // {{{
// document => http://readitlaterlist.com/api/docs#get
let manager = Components.classes["@mozilla.org/login-manager;1"].getService(Components.interfaces.nsILoginManager);
@@ -246,7 +255,7 @@ let PLUGIN_INFO =
password : logins[0].password,
format : "json",
count : (liberator.globalVariables.readitlater_get_count? liberator.globalVariables.readitlater_get_count : 50 ),
- //state : (args["read"]) ? "read" : "unread",
+ state : state
//tags : (args["tags"]) ? 1 : 0,
//myAppOnly: (args["myAppOnly"]) ? 1 : 0,
}
@@ -427,20 +436,14 @@ 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();
- }; // }}}
+ let ListCache = {
+ all: new Cache({name: 'list', updater: ReadItLater.get.bind(ReadItLater, '')}),
+ unread: new Cache({name: 'list', updater: ReadItLater.get.bind(ReadItLater, 'unread')})
+ };
function markAsRead(urls){ // {{{
for (let [, url] in Iterator(urls))
- ListCache.remove(url);
+ ListCache.unread.remove(url);
ReadItLater.send(urls, echo.bind(null, "Mark as read: " + urls.length));
} // }}}
@@ -451,7 +454,7 @@ let PLUGIN_INFO =
url = buffer.URL;
ReadItLater.add(url, title, function(){
echo("Added: " + (title || url));
- ListCache.update(true);
+ ListCache.unread.update(true);
});
} // }}}
@@ -476,14 +479,12 @@ let PLUGIN_INFO =
context.anchored = false;
context.incomplete = true;
- ListCache.get(function(data){
+ ListCache[args.bang ? 'all' : 'unread'].get(function(data){
context.completions = [
[item.url,item.title]
for([, item] in Iterator(data.list))
if(
!args.some(function (arg) arg == item.url)
- &&
- (!args["bang"] ? item.state == 0 : item.state == 1)
)
];
context.incomplete = false;