From 79c6d7ca22c1b85897f78db0171836ff999f896e Mon Sep 17 00:00:00 2001
From: mattn
Date: Fri, 20 Jun 2008 08:56:46 +0000
Subject: 「:twitter!+ someone」でfav、「:twitter!-
someone」でun-favとなる様修正
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@14292 d0d07461-0603-4401-acd4-de1884942a52
---
twitter.js | 82 +++++++++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 60 insertions(+), 22 deletions(-)
(limited to 'twitter.js')
diff --git a/twitter.js b/twitter.js
index 38ea2e1..7dfbf03 100644
--- a/twitter.js
+++ b/twitter.js
@@ -14,45 +14,58 @@
// show search result of 'someword' from "http://twitter.1x1.jp".
// :twitter!@
// show replies.
+// :twitter!+ someone
+// fav someone's last status..
+// :twitter!- someone
+// un-fav someone's last status..
(function(){
var passwordManager = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
+ var evalFunc = window.eval;
+ try {
+ var sandbox = new Components.utils.Sandbox(window);
+ if (Components.utils.evalInSandbox("true", sandbox) === true) {
+ evalFunc = function(text) {
+ return Components.utils.evalInSandbox(text, sandbox);
+ }
+ }
+ } catch(e) { liberator.log('warning: twitter.js is working with unsafe sandbox.'); }
+
+ 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 sayTwitter(username, password, stat){
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://twitter.com/statuses/update.json", false, username, password);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("status=" + encodeURIComponent(stat));
}
- 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 favTwitter(username, password, user){
+ var xhr = new XMLHttpRequest();
+ xhr.open("POST", "http://twitter.com/statuses/user_timeline/" + user + ".json?count=1", false, username, password);
+ xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+ xhr.send(null);
+ xhr.open("POST", "http://twitter.com/favourings/create/" + window.eval(xhr.responseText)[0].id, false, username, password);
+ xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+ xhr.send(null);
}
- function showTwitterSearchResult(word){
+ function unfavTwitter(username, password, user){
var xhr = new XMLHttpRequest();
- xhr.open("GET", "http://twitter.1x1.jp/rss/search/?keyword=" + encodeURIComponent(word) + "&text=1", false);
+ xhr.open("POST", "http://twitter.com/statuses/user_timeline/" + user + ".json?count=1", false, username, password);
+ xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+ xhr.send(null);
+ xhr.open("POST", "http://twitter.com/favourings/destroy/" + window.eval(xhr.responseText)[0].id, false, username, password);
+ xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
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}
- :
-
-
- >.toSource()
- .replace(/(?:\r?\n|\r)[ \t]*/g, " ");
- liberator.echo(html, true);
}
function showTwitterReply(username, password){
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://twitter.com/statuses/replies.json", false, username, password);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(null);
- var statuses = window.eval(xhr.responseText);
+ var statuses = evalFunc(xhr.responseText);
var html = .toSource()
+ .replace(/(?:\r?\n|\r)[ \t]*/g, " ");
+ for (var n = 0; n < items.length; n++)
+ html += <>
+ {items[n].getElementsByTagName('title')[0].textContent}
+ :
+
+
+ >.toSource()
+ .replace(/(?:\r?\n|\r)[ \t]*/g, " ");
+ liberator.echo(html, true);
+ }
liberator.commands.addUserCommand(["twitter"], "Change Twitter status",
function(arg, special){
var password;
@@ -126,6 +158,12 @@
if (special && arg.match(/^\?\s*(.*)/))
showTwitterSearchResult(RegExp.$1)
else
+ if (special && arg.match(/^\+\s*(.*)/))
+ favTwitter(username, password, RegExp.$1)
+ else
+ if (special && arg.match(/^\-\s*(.*)/))
+ unfavTwitter(username, password, RegExp.$1)
+ else
if (special && arg.match(/^@/))
showTwitterReply(username, password)
else
--
cgit v1.2.3