diff options
-rw-r--r-- | wassr.js | 120 |
1 files changed, 112 insertions, 8 deletions
@@ -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 <mattn.jp@gmail.com> - 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 = <style type="text/css"><![CDATA[
+ span.wassr.entry-content a { text-decoration: none; }
+ img.wassr.photo { border; 0px; width: 16px; height: 16px; vertical-align: baseline; }
+ ]]></style>.toSource()
+ .replace(/(?:\r?\n|\r)[ \t]*/g, " ") +
+ statuses.map(function(status)
+ <>
+ <img src={status.user.profile_image_url}
+ alt={status.user.screen_name}
+ title={status.user.screen_name}
+ class="wassr photo"/>
+ <strong>{status.user_login_id}‬</strong>
+ </>.toSource()
+ .replace(/(?:\r?\n|\r)[ \t]*/g, " ") +
+ sprintf(': <span class="wassr entry-content">%s‬</span>', status.text))
+ .join("<br/>");
+
+ //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 = <style type="text/css"><![CDATA[
+ span.wassr.entry-content a { text-decoration: none; }
+ ]]></style>.toSource()
+ .replace(/(?:\r?\n|\r)[ \t]*/g, " ");
+ for (var n = 0; n < items.length; n++)
+ html += <>
+ <strong>{items[n].getElementsByTagName('title')[0].textContent.replace(/>/g, '>').replace(/</g, '<').replace(/^%/, '')}‬</strong>
+ : <span class="wassr entry-content">{items[n].getElementsByTagName('description')[0].textContent.replace(/>/g, '>').replace(/</g, '<')}‬</span>
+
+ <br />
+ </>.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
|