From 999fe1b70f77a50e2e977dd56c60a54da86b5a9b Mon Sep 17 00:00:00 2001 From: mattn Date: Fri, 29 Aug 2008 10:54:03 +0000 Subject: ・リプライ表示に対応 :wassr!@ ・検索に対応 :wassr!? yappo ・イイネに対応 :wassr!+ yappo ・イイネ削除に対応 :wassr!- yappo git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@18437 d0d07461-0603-4401-acd4-de1884942a52 --- wassr.js | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 112 insertions(+), 8 deletions(-) (limited to 'wassr.js') diff --git a/wassr.js b/wassr.js index 6aed1ce..32d1a80 100644 --- a/wassr.js +++ b/wassr.js @@ -1,12 +1,41 @@ // Vimperator plugin: "Update Wassr" -// Last Change: 17-Jul-2008. Jan 2008 +// Last Change: 29-Aug-2008. Jan 2008 // License: Creative Commons // Maintainer: mattn - http://mattn.kaoriya.net/ // Based On: twitter.js by Trapezoid // // The script allows you to update Wassr status from Vimperator 0.6.*. +// +// Commands: +// :wassr some thing text +// post "some thing text" to wassr. +// :wassr! someone +// show someone's statuses. +// :wassr!? someword +// show search result of 'someword' from "http://labs.ceek.jp/wassr/". +// :wassr!@ +// show replies. +// :wassr!+ someone +// fav someone's last status.. mean put iine. +// :wassr!- someone +// un-fav someone's last status.. mean remove iine. +// :wassr -footmark +// show footmarks. +// :wassr -todo +// show your todos. +// :wassr -todo+ some thing text +// add 'some thing text' to your todo. +// :wassr -todo- todo-id +// remove todo which id is todo-id. +// :wassr -todo* todo-id +// start todo which id is todo-id. +// :wassr -todo/ todo-id +// stop todo which id is todo-id. +// :wassr -todo! todo-id +// done todo which id is todo-id. (function(){ + var passwordManager = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager); var evalFunc = window.eval; try { var sandbox = new Components.utils.Sandbox(window); @@ -17,8 +46,11 @@ } } catch(e) { liberator.log('warning: wassr.js is working with unsafe sandbox.'); } - var passwordManager = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager); - + function sprintf(format){ + var i = 1, re = /%s/, result = "" + format; + while (re.test(result) && i < arguments.length) result = result.replace(re, arguments[i++]); + return result; + } function emojiConv(str){ return str.replace(/[^*+.-9A-Z_a-z-]/g,function(s){ var c = s.charCodeAt(0); @@ -31,11 +63,6 @@ xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.send("status=" + encodeURIComponent(stat) + "&source=" + encodeURIComponent("vimperator/wassr.js")); } - function sprintf(format){ - var i = 1, re = /%s/, result = "" + format; - while (re.test(result) && i < arguments.length) result = result.replace(re, arguments[i++]); - return result; - } function showFollowersStatus(username, password, target){ var xhr = new XMLHttpRequest(); var endPoint = target ? "http://api.wassr.jp/user_timeline.json?id=" + target @@ -66,6 +93,71 @@ liberator.echo(html, true); } + function favWassr(username, password, user){ + var xhr = new XMLHttpRequest(); + xhr.open("POST", "http://api.wassr.jp/user_timeline.json?id=" + user, false, username, password); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.send(null); + xhr.open("POST", "http://api.wassr.jp/favorites/create/" + evalFunc(xhr.responseText)[0].rid + ".json", false, username, password); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.send(null); + } + function unfavWassr(username, password, user){ + var xhr = new XMLHttpRequest(); + xhr.open("POST", "http://api.wassr.jp/user_timeline.json?id=" + user, false, username, password); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.send(null); + xhr.open("POST", "http://api.wassr.jp/favorites/destroy/" + evalFunc(xhr.responseText)[0].rid + ".json", false, username, password); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.send(null); + } + function showWassrReply(username, password){ + var xhr = new XMLHttpRequest(); + xhr.open("POST", "http://api.wassr.jp/statuses/replies.json", false, username, password); + xhr.setRequestHeader("User-Agent", "XMLHttpRequest"); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.send(null); + var statuses = evalFunc(xhr.responseText); + + var html = .toSource() + .replace(/(?:\r?\n|\r)[ \t]*/g, " ") + + statuses.map(function(status) + <> + {status.user.screen_name} + {status.user_login_id}‬ + .toSource() + .replace(/(?:\r?\n|\r)[ \t]*/g, " ") + + sprintf(': %s‬', status.text)) + .join("
"); + + //liberator.log(html); + liberator.echo(html, true); + } + function showWassrSearchResult(word){ + var xhr = new XMLHttpRequest(); + xhr.open("GET", "http://labs.ceek.jp/wassr/rss?k=" + encodeURIComponent(word), false); + xhr.send(null); + var items = xhr.responseXML.getElementsByTagName('item'); + var html = .toSource() + .replace(/(?:\r?\n|\r)[ \t]*/g, " "); + for (var n = 0; n < items.length; n++) + html += <> + {items[n].getElementsByTagName('title')[0].textContent.replace(/>/g, '>').replace(/</g, '<').replace(/^%/, '')}‬ + : {items[n].getElementsByTagName('description')[0].textContent.replace(/>/g, '>').replace(/</g, '<')}‬ + +
+ .toSource() + .replace(/(?:\r?\n|\r)[ \t]*/g, " "); + liberator.echo(html, true); + } function todoAction(username, password, arg){ var xhr = new XMLHttpRequest(); if (arg.match(/\+ (.*)/)) { @@ -182,6 +274,18 @@ arg = arg.replace(/%URL%/g, liberator.buffer.URL) .replace(/%TITLE%/g, liberator.buffer.title); + if (special && arg.match(/^\?\s*(.*)/)) + showWassrSearchResult(RegExp.$1) + else + if (special && arg.match(/^\+\s*(.*)/)) + favWassr(username, password, RegExp.$1) + else + if (special && arg.match(/^\-\s*(.*)/)) + unfavWassr(username, password, RegExp.$1) + else + if (special && arg.match(/^@/)) + showWassrReply(username, password) + else if (special || arg.length == 0) showFollowersStatus(username, password, arg); else -- cgit v1.2.3