From 4d3a21bd7eeeb6e826d06255f01ea76d656d7175 Mon Sep 17 00:00:00 2001 From: drry Date: Thu, 10 Apr 2008 07:09:21 +0000 Subject: lang/javascript/vimperator-plugins/trunk/twitter.js: * backed out to r9207 due to a links in the text. (temporary) * ... and fixed a typo. git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@9246 d0d07461-0603-4401-acd4-de1884942a52 --- twitter.js | 79 ++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 41 insertions(+), 38 deletions(-) (limited to 'twitter.js') diff --git a/twitter.js b/twitter.js index ba4cec1..cb8a5b7 100644 --- a/twitter.js +++ b/twitter.js @@ -1,78 +1,81 @@ // Vimperator plugin: 'Update Twitter' -// Last Change: 10-Apr-2008. Jan 2008 +// Last Change: 09-Apr-2008. Jan 2008 // License: Creative Commons // Maintainer: Trapezoid - http://unsigned.g.hatena.ne.jp/Trapezoid // -// update Twitter status script for Vimperator 0.6.* +// update twitter status script for vimperator0.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.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 showFollowersStatus(username, password){ + 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){ 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.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 html = <> - - .toSource(); - followers_status.forEach(function(stat){ + --> + ]]>.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 += <> - - {stat.user.name} - : {stat.text}
- .toSource() - .replace(/(?:\r?\n|\r)\s*/g, ''); - }); - liberator.log(html); + html += sprintf( + <> + %s + : %s
+ ]]>.toString().replace(/\n\s*/g, ''), + stat.user.profile_image_url, + stat.user.screen_name, + stat.user.name, + stat.text + ); + } + 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) + if(logins.length) [username, password] = [logins[0].username, logins[0].password]; else - throw "Twitter: account not found"; + liberator.echoerr("Twitter: account not found"); } - catch (ex){ - liberator.echoerr(ex); + catch(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: -- cgit v1.2.3