Changeset 9266

Show
Ignore:
Timestamp:
04/10/08 22:22:24 (5 years ago)
Author:
drry
Message:

lang/javascript/vimperator-plugins/trunk/twitter.js:

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 2008 
     1// Vimperator plugin: "Update Twitter" 
     2// Last Change: 10-Apr-2008. Jan 2008 
    33// License: Creative Commons 
    44// Maintainer: Trapezoid <trapezoid.g@gmail.com> - http://unsigned.g.hatena.ne.jp/Trapezoid 
    55// 
    6 // update twitter status script for vimperator0.6.* 
     6// The script allows you to update Twitter status from Vimperator 0.6.*. 
    77 
    88(function(){ 
    99    var passwordManager = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager); 
    10     function sayTwitter(username,password,stat){ 
     10    function sayTwitter(username, password, stat){ 
    1111        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"); 
    1414        xhr.send("status=" + encodeURIComponent(stat)); 
    1515    } 
    16     function sprintf(format) { 
     16    function sprintf(format){ 
    1717        var i = 1, re = /%s/, result = "" + format; 
    1818        while (re.test(result) && i < arguments.length) result = result.replace(re, arguments[i++]); 
    1919        return result; 
    2020    } 
    21     function showFollowersStatus(username,password){ 
     21    function showFollowersStatus(username, password){ 
    2222        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); 
    2424        // 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"); 
    2727        xhr.send(null); 
    28         var followers_status = window.eval(xhr.responseText); 
     28        var statuses = window.eval(xhr.responseText); 
    2929 
    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}&#x202C;</strong> 
     42                </>.toSource() 
     43                   .replace(/(?:\r?\n|\r)[ \t]*/g, " ") + 
     44                    sprintf(': <span class="twitter entry-content">%s&#x202C;</span>', status.text)) 
     45                        .join("<br/>"); 
     46 
     47        //liberator.log(html); 
    5348        liberator.echo(html, true); 
    5449    } 
    55     liberator.commands.addUserCommand(['twitter'], 'Change twitter status', 
    56         function(arg,special){ 
     50    liberator.commands.addUserCommand(["twitter"], "Change Twitter status", 
     51        function(arg, special){ 
    5752            var password; 
    5853            var username; 
    5954            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) 
    6257                    [username, password] = [logins[0].username, logins[0].password]; 
    6358                else 
    64                     liberator.echoerr("Twitter: account not found"); 
     59                    throw "Twitter: account not found"; 
    6560            } 
    66             catch(ex) { 
     61            catch (ex){ 
     62                liberator.echoerr(ex); 
    6763            } 
    6864 
    69             if(special){ 
     65            if (special){ 
    7066                arg = arg.replace(/%URL%/g, liberator.buffer.URL) 
    71                         .replace(/%TITLE%/g ,liberator.buffer.title); 
     67                         .replace(/%TITLE%/g, liberator.buffer.title); 
    7268            } 
    7369 
    7470            if (!arg || arg.length == 0) 
    75                 showFollowersStatus(username,password); 
     71                showFollowersStatus(username, password); 
    7672            else 
    77                 sayTwitter(username,password,arg); 
    78         },{ } 
    79     ); 
     73                sayTwitter(username, password, arg); 
     74        }, 
     75    { }); 
    8076})(); 
    8177// vim:sw=4 ts=4 et: