From 52692ab4924641f7b991aec9f326a553bc4e496c Mon Sep 17 00:00:00 2001 From: mattn Date: Fri, 9 May 2008 10:20:32 +0000 Subject: * added completer for -todo * added new option -footmark git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@11300 d0d07461-0603-4401-acd4-de1884942a52 --- wassr.js | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 69 insertions(+), 6 deletions(-) (limited to 'wassr.js') diff --git a/wassr.js b/wassr.js index c76aaf7..31cddd1 100644 --- a/wassr.js +++ b/wassr.js @@ -1,5 +1,5 @@ // Vimperator plugin: "Update Wassr" -// Last Change: 08-May-2008. Jan 2008 +// Last Change: 09-May-2008. Jan 2008 // License: Creative Commons // Maintainer: mattn - http://mattn.kaoriya.net/ // Based On: twitter.js by Trapezoid @@ -45,12 +45,10 @@ sprintf(': %s‬', status.text)) .join("
"); - //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"); @@ -101,6 +99,52 @@ liberator.echo(html, true); } + function footmarkAction(username, password){ + var xhr = new XMLHttpRequest(); + xhr.open("GET", "http://api.wassr.jp/footmark/recent.json", false, username, password); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.send(null); + var footmarks = window.eval(xhr.responseText); + + var html = .toSource() + .replace(/(?:\r?\n|\r)[ \t]*/g, " ") + + footmarks.map(function(footmark) + <> + {footmark.nick} + {footmark.login_id}‬ + .toSource() + .replace(/(?:\r?\n|\r)[ \t]*/g, " ")).join("
"); + + liberator.echo(html, true); + } + function footmarkAction(username, password){ + var xhr = new XMLHttpRequest(); + xhr.open("GET", "http://api.wassr.jp/footmark/recent.json", false, username, password); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.send(null); + var footmarks = window.eval(xhr.responseText); + + var html = .toSource() + .replace(/(?:\r?\n|\r)[ \t]*/g, " ") + + footmarks.map(function(footmark) + <> + {footmark.nick} + {footmark.login_id}‬ + .toSource() + .replace(/(?:\r?\n|\r)[ \t]*/g, " ")).join("
"); + + liberator.echo(html, true); + } liberator.commands.addUserCommand(["wassr"], "Change wassr status", function(arg, special){ var password; @@ -126,14 +170,29 @@ else if (arg.match(/^-todo(.*)/)) todoAction(username, password, RegExp.$1); + else + if (arg.match(/^-footmark$/)) + footmarkAction(username, password); else sayWassr(username, password, arg); }, { + args: [ + [['-todo'], commands.OPTION_STRING], + [['-footmark'], null] + ], completer: function(filter) { - liberator.log(filter) candidates = []; - if (filter.match(/-todo([^!].*)/)) { + if (filter.match(/-todo$/)) { + candidates = [ + ['-todo+', 'add todo'], + ['-todo-', 'delete todo'], + ['-todo*', 'start todo'], + ['-todo/', 'stop todo'], + ['-todo!', 'done todo'], + ]; + } else + if (filter.match(/-todo[^\+].*/)) { var password; var username; try { @@ -148,11 +207,15 @@ 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); } + } else { + candidates = [ + ['-todo', 'todo'], + ['-footmark', 'footmark'], + ]; } return [0,candidates]; } -- cgit v1.2.3