diff options
author | anekos | 2011-11-28 10:37:47 +0900 |
---|---|---|
committer | anekos | 2011-11-28 10:37:47 +0900 |
commit | 0b06fcc75f4a914c7217a2352220de4056a6bbb9 (patch) | |
tree | 2ff24daa03ffc37c52ba4c7a8141814bfdacbfbe /readitlater.js | |
parent | 3dc39393599777bda264bf2d63068d36a5cbbf2d (diff) | |
download | vimperator-plugins-0b06fcc75f4a914c7217a2352220de4056a6bbb9.tar.bz2 |
Get full unread list
Diffstat (limited to 'readitlater.js')
-rw-r--r-- | readitlater.js | 37 |
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; |