Changeset 9266
- Timestamp:
- 04/10/08 22:22:24 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/vimperator-plugins/trunk/twitter.js
r9246 r9266 1 // Vimperator plugin: 'Update Twitter'2 // Last Change: 09-Apr-2008. Jan 20081 // Vimperator plugin: "Update Twitter" 2 // Last Change: 10-Apr-2008. Jan 2008 3 3 // License: Creative Commons 4 4 // Maintainer: Trapezoid <trapezoid.g@gmail.com> - http://unsigned.g.hatena.ne.jp/Trapezoid 5 5 // 6 // update twitter status script for vimperator0.6.*6 // The script allows you to update Twitter status from Vimperator 0.6.*. 7 7 8 8 (function(){ 9 9 var passwordManager = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager); 10 function sayTwitter(username, password,stat){10 function sayTwitter(username, password, stat){ 11 11 var xhr = new XMLHttpRequest(); 12 xhr.open("POST", "http://twitter.com/statuses/update.json",false,username,password);13 xhr.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded');12 xhr.open("POST", "http://twitter.com/statuses/update.json", false, username, password); 13 xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 14 14 xhr.send("status=" + encodeURIComponent(stat)); 15 15 } 16 function sprintf(format) {16 function sprintf(format){ 17 17 var i = 1, re = /%s/, result = "" + format; 18 18 while (re.test(result) && i < arguments.length) result = result.replace(re, arguments[i++]); 19 19 return result; 20 20 } 21 function showFollowersStatus(username, password){21 function showFollowersStatus(username, password){ 22 22 var xhr = new XMLHttpRequest(); 23 xhr.open("GET", "http://twitter.com/statuses/friends_timeline.json",false,username,password);23 xhr.open("GET", "http://twitter.com/statuses/friends_timeline.json", false, username, password); 24 24 // for debug 25 //xhr.open("GET", "http://twitter.com/statuses/user_timeline/otsune.json",false,username,password);26 xhr.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded');25 //xhr.open("GET", "http://twitter.com/statuses/user_timeline/otsune.json", false, username, password); 26 xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 27 27 xhr.send(null); 28 var followers_status = window.eval(xhr.responseText);28 var statuses = window.eval(xhr.responseText); 29 29 30 var html = <><![CDATA[ 31 <style type="text/css"><!-- 32 a { text-decoration: none; } 33 img { border; 0px; width: 16px; height: 16px; vertical-align: baseline; } 34 --></style> 35 ]]></>.toString().replace(/\n\s*/g, ''); 36 for (var i = 0; i < followers_status.length; i++) { 37 var stat = followers_status[i]; 38 stat.user.name += "\u202c"; 39 stat.text += "\u202c"; 40 html += sprintf( 41 <><![CDATA[ 42 <img src="%s" title="%s" border="0" /> 43 <strong>%s</strong> 44 : %s<br /> 45 ]]></>.toString().replace(/\n\s*/g, ''), 46 stat.user.profile_image_url, 47 stat.user.screen_name, 48 stat.user.name, 49 stat.text 50 ); 51 } 52 liberator.log(html); 30 var html = <style type="text/css"><![CDATA[ 31 span.twitter.entry-content a { text-decoration: none; } 32 img.twitter.photo { border; 0px; width: 16px; height: 16px; vertical-align: baseline; } 33 ]]></style>.toSource() 34 .replace(/(?:\r?\n|\r)[ \t]*/g, " ") + 35 statuses.map(function(status) 36 <> 37 <img src={status.user.profile_image_url} 38 alt={status.user.screen_name} 39 title={status.user.screen_name} 40 class="twitter photo"/> 41 <strong>{status.user.name}‬</strong> 42 </>.toSource() 43 .replace(/(?:\r?\n|\r)[ \t]*/g, " ") + 44 sprintf(': <span class="twitter entry-content">%s‬</span>', status.text)) 45 .join("<br/>"); 46 47 //liberator.log(html); 53 48 liberator.echo(html, true); 54 49 } 55 liberator.commands.addUserCommand([ 'twitter'], 'Change twitter status',56 function(arg, special){50 liberator.commands.addUserCommand(["twitter"], "Change Twitter status", 51 function(arg, special){ 57 52 var password; 58 53 var username; 59 54 try { 60 var logins = passwordManager.findLogins({}, 'http://twitter.com', 'https://twitter.com', null);61 if (logins.length)55 var logins = passwordManager.findLogins({}, "http://twitter.com", "https://twitter.com", null); 56 if (logins.length) 62 57 [username, password] = [logins[0].username, logins[0].password]; 63 58 else 64 liberator.echoerr("Twitter: account not found");59 throw "Twitter: account not found"; 65 60 } 66 catch(ex) { 61 catch (ex){ 62 liberator.echoerr(ex); 67 63 } 68 64 69 if (special){65 if (special){ 70 66 arg = arg.replace(/%URL%/g, liberator.buffer.URL) 71 .replace(/%TITLE%/g ,liberator.buffer.title);67 .replace(/%TITLE%/g, liberator.buffer.title); 72 68 } 73 69 74 70 if (!arg || arg.length == 0) 75 showFollowersStatus(username, password);71 showFollowersStatus(username, password); 76 72 else 77 sayTwitter(username, password,arg);78 }, { }79 );73 sayTwitter(username, password, arg); 74 }, 75 { }); 80 76 })(); 81 77 // vim:sw=4 ts=4 et:
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)