aboutsummaryrefslogtreecommitdiffstats
path: root/twitter.js
diff options
context:
space:
mode:
authordrry2008-04-10 13:22:24 +0000
committerdrry2008-04-10 13:22:24 +0000
commit5a85103eeca48a86e732a02639abf08dfd223429 (patch)
treec511baff524dbc9ffd94ec3a58dbd7f9da7780cb /twitter.js
parente0cf30d7cff04c97e7c67a7e2915592a8113414b (diff)
downloadvimperator-plugins-5a85103eeca48a86e732a02639abf08dfd223429.tar.bz2
lang/javascript/vimperator-plugins/trunk/twitter.js:
* diff:lang/javascript/vimperator-plugins/trunk/twitter.js@9207:9244 git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@9266 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'twitter.js')
-rw-r--r--twitter.js90
1 files changed, 43 insertions, 47 deletions
diff --git a/twitter.js b/twitter.js
index cb8a5b7..ad2e9ef 100644
--- a/twitter.js
+++ b/twitter.js
@@ -1,81 +1,77 @@
-// Vimperator plugin: 'Update Twitter'
-// Last Change: 09-Apr-2008. Jan 2008
+// Vimperator plugin: "Update Twitter"
+// Last Change: 10-Apr-2008. Jan 2008
// License: Creative Commons
// Maintainer: Trapezoid <trapezoid.g@gmail.com> - http://unsigned.g.hatena.ne.jp/Trapezoid
//
-// update twitter status script for vimperator0.6.*
+// The script allows you to update Twitter status from Vimperator 0.6.*.
(function(){
var passwordManager = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
- function sayTwitter(username,password,stat){
+ 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.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) {
+ 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){
+ function showFollowersStatus(username, password){
var xhr = new XMLHttpRequest();
- xhr.open("GET","http://twitter.com/statuses/friends_timeline.json",false,username,password);
+ xhr.open("GET", "http://twitter.com/statuses/friends_timeline.json", false, username, password);
// for debug
- //xhr.open("GET","http://twitter.com/statuses/user_timeline/otsune.json",false,username,password);
- xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
+ //xhr.open("GET", "http://twitter.com/statuses/user_timeline/otsune.json", false, username, password);
+ xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(null);
- var followers_status = window.eval(xhr.responseText);
+ var statuses = window.eval(xhr.responseText);
- var html = <><![CDATA[
- <style type="text/css"><!--
- a { text-decoration: none; }
- img { border; 0px; width: 16px; height: 16px; vertical-align: baseline; }
- --></style>
- ]]></>.toString().replace(/\n\s*/g, '');
- for (var i = 0; i < followers_status.length; i++) {
- var stat = followers_status[i];
- stat.user.name += "\u202c";
- stat.text += "\u202c";
- html += sprintf(
- <><![CDATA[
- <img src="%s" title="%s" border="0" />
- <strong>%s</strong>
- : %s<br />
- ]]></>.toString().replace(/\n\s*/g, ''),
- stat.user.profile_image_url,
- stat.user.screen_name,
- stat.user.name,
- stat.text
- );
- }
- liberator.log(html);
+ var html = <style type="text/css"><![CDATA[
+ span.twitter.entry-content a { text-decoration: none; }
+ img.twitter.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="twitter photo"/>
+ <strong>{status.user.name}&#x202C;</strong>
+ </>.toSource()
+ .replace(/(?:\r?\n|\r)[ \t]*/g, " ") +
+ sprintf(': <span class="twitter entry-content">%s&#x202C;</span>', status.text))
+ .join("<br/>");
+
+ //liberator.log(html);
liberator.echo(html, true);
}
- liberator.commands.addUserCommand(['twitter'], 'Change twitter status',
- function(arg,special){
+ liberator.commands.addUserCommand(["twitter"], "Change Twitter status",
+ function(arg, special){
var password;
var username;
try {
- var logins = passwordManager.findLogins({}, 'http://twitter.com', 'https://twitter.com', null);
- if(logins.length)
+ var logins = passwordManager.findLogins({}, "http://twitter.com", "https://twitter.com", null);
+ if (logins.length)
[username, password] = [logins[0].username, logins[0].password];
else
- liberator.echoerr("Twitter: account not found");
+ throw "Twitter: account not found";
}
- catch(ex) {
+ catch (ex){
+ liberator.echoerr(ex);
}
- if(special){
+ if (special){
arg = arg.replace(/%URL%/g, liberator.buffer.URL)
- .replace(/%TITLE%/g ,liberator.buffer.title);
+ .replace(/%TITLE%/g, liberator.buffer.title);
}
if (!arg || arg.length == 0)
- showFollowersStatus(username,password);
+ showFollowersStatus(username, password);
else
- sayTwitter(username,password,arg);
- },{ }
- );
+ sayTwitter(username, password, arg);
+ },
+ { });
})();
// vim:sw=4 ts=4 et: