From 060dc6b811c86dcde4bbabbd9eced4412f9d1381 Mon Sep 17 00:00:00 2001
From: mattn
Date: Thu, 8 May 2008 01:21:16 +0000
Subject: * todo機能追加(できかけ)
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@11265 d0d07461-0603-4401-acd4-de1884942a52
---
wassr.js | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 85 insertions(+), 2 deletions(-)
(limited to 'wassr.js')
diff --git a/wassr.js b/wassr.js
index 3f523e1..c76aaf7 100644
--- a/wassr.js
+++ b/wassr.js
@@ -35,7 +35,7 @@
.replace(/(?:\r?\n|\r)[ \t]*/g, " ") +
statuses.map(function(status)
<>
-
@@ -48,6 +48,59 @@
//liberator.log(html);
liberator.echo(html, true);
}
+ function todoAction(username, password, arg){
+ var xhr = new XMLHttpRequest();
+ liberator.log(arg)
+ if (arg.match(/\+ (.*)/)) {
+ xhr.open("POST", "http://api.wassr.jp/todo/add.json", false, username, password);
+ xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+ xhr.send("body=" + encodeURIComponent(RegExp.$1));
+ } else
+ if (arg.match(/- (.*)/)) {
+ xhr.open("POST", "http://api.wassr.jp/todo/delete.json", false, username, password);
+ xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+ xhr.send("todo_rid=" + encodeURIComponent(RegExp.$1));
+ } else
+ if (arg.match(/\* (.*)/)) {
+ xhr.open("POST", "http://api.wassr.jp/todo/start.json", false, username, password);
+ xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+ xhr.send("todo_rid=" + encodeURIComponent(RegExp.$1));
+ } else
+ if (arg.match(/\/ (.*)/)) {
+ xhr.open("POST", "http://api.wassr.jp/todo/stop.json", false, username, password);
+ xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+ xhr.send("todo_rid=" + encodeURIComponent(RegExp.$1));
+ } else
+ if (arg.match(/! (.*)/)) {
+ xhr.open("POST", "http://api.wassr.jp/todo/done.json", false, username, password);
+ xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+ xhr.send("todo_rid=" + encodeURIComponent(RegExp.$1));
+ }
+
+ xhr.open("GET", "http://api.wassr.jp/todo/list.json", false, username, password);
+ xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+ xhr.send(null);
+ var todos = window.eval(xhr.responseText);
+
+ var html = .toSource()
+ .replace(/(?:\r?\n|\r)[ \t]*/g, " ") +
+ todos.map(function(todo)
+ <>
+
+ {todo.todo_rid}
+ >.toSource()
+ .replace(/(?:\r?\n|\r)[ \t]*/g, " ") +
+ sprintf(': %s', todo.body))
+ .join("
");
+
+ liberator.echo(html, true);
+ }
liberator.commands.addUserCommand(["wassr"], "Change wassr status",
function(arg, special){
var password;
@@ -70,9 +123,39 @@
if (!arg || arg.length == 0)
showFollowersStatus(username, password);
+ else
+ if (arg.match(/^-todo(.*)/))
+ todoAction(username, password, RegExp.$1);
else
sayWassr(username, password, arg);
},
- { });
+ {
+ completer: function(filter) {
+ liberator.log(filter)
+ candidates = [];
+ if (filter.match(/-todo([^!].*)/)) {
+ var password;
+ var username;
+ try {
+ var logins = passwordManager.findLogins({}, "http://wassr.jp", "http://wassr.jp", null);
+ if (logins.length)
+ [username, password] = [logins[0].username, logins[0].password];
+ else
+ throw "Wassr: account not found";
+ var xhr = new XMLHttpRequest();
+ xhr.open("GET", "http://api.wassr.jp/todo/list.json", false, username, password);
+ xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+ xhr.send(null);
+ var todos = window.eval(xhr.responseText);
+ for(let i in todos) candidates.push([filter + ' ' + todos[i].todo_rid, todos[i].body]);
+ liberator.log(candidates)
+ }
+ catch (ex){
+ liberator.echoerr(ex);
+ }
+ }
+ return [0,candidates];
+ }
+ });
})();
// vim:sw=4 ts=4 et:
--
cgit v1.2.3