Show
Ignore:
Timestamp:
08/29/08 19:54:03 (3 months ago)
Author:
mattn
Message:

・リプライ表示に対応 :wassr!@
・検索に対応 :wassr!? yappo
・イイネに対応 :wassr!+ yappo
・イイネ削除に対応 :wassr!- yappo

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/vimperator-plugins/trunk/wassr.js

    r15935 r18437  
    11// Vimperator plugin: "Update Wassr" 
    2 // Last Change: 17-Jul-2008. Jan 2008 
     2// Last Change: 29-Aug-2008. Jan 2008 
    33// License: Creative Commons 
    44// Maintainer: mattn <mattn.jp@gmail.com> - http://mattn.kaoriya.net/ 
     
    66// 
    77// The script allows you to update Wassr status from Vimperator 0.6.*. 
     8// 
     9// Commands: 
     10//  :wassr some thing text 
     11//      post "some thing text" to wassr. 
     12//  :wassr! someone 
     13//      show someone's statuses. 
     14//  :wassr!? someword 
     15//      show search result of 'someword' from "http://labs.ceek.jp/wassr/". 
     16//  :wassr!@ 
     17//      show replies. 
     18//  :wassr!+ someone 
     19//      fav someone's last status.. mean put iine. 
     20//  :wassr!- someone 
     21//      un-fav someone's last status.. mean remove iine. 
     22//  :wassr -footmark 
     23//      show footmarks. 
     24//  :wassr -todo 
     25//      show your todos. 
     26//  :wassr -todo+ some thing text 
     27//      add 'some thing text' to your todo. 
     28//  :wassr -todo- todo-id 
     29//      remove todo which id is todo-id. 
     30//  :wassr -todo* todo-id 
     31//      start todo which id is todo-id. 
     32//  :wassr -todo/ todo-id 
     33//      stop todo which id is todo-id. 
     34//  :wassr -todo! todo-id 
     35//      done todo which id is todo-id. 
    836 
    937(function(){ 
     38    var passwordManager = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager); 
    1039    var evalFunc = window.eval; 
    1140    try { 
     
    1847    } catch(e) { liberator.log('warning: wassr.js is working with unsafe sandbox.'); } 
    1948 
    20     var passwordManager = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager); 
    21  
     49    function sprintf(format){ 
     50        var i = 1, re = /%s/, result = "" + format; 
     51        while (re.test(result) && i < arguments.length) result = result.replace(re, arguments[i++]); 
     52        return result; 
     53    } 
    2254    function emojiConv(str){ 
    2355        return str.replace(/[^*+.-9A-Z_a-z-]/g,function(s){ 
     
    3264        xhr.send("status=" + encodeURIComponent(stat) + "&source=" + encodeURIComponent("vimperator/wassr.js")); 
    3365    } 
    34     function sprintf(format){ 
    35         var i = 1, re = /%s/, result = "" + format; 
    36         while (re.test(result) && i < arguments.length) result = result.replace(re, arguments[i++]); 
    37         return result; 
    38     } 
    3966    function showFollowersStatus(username, password, target){ 
    4067        var xhr = new XMLHttpRequest(); 
     
    6592                        .join("<br/>"); 
    6693 
     94        liberator.echo(html, true); 
     95    } 
     96    function favWassr(username, password, user){ 
     97        var xhr = new XMLHttpRequest(); 
     98        xhr.open("POST", "http://api.wassr.jp/user_timeline.json?id=" + user, false, username, password); 
     99        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
     100        xhr.send(null); 
     101        xhr.open("POST", "http://api.wassr.jp/favorites/create/" + evalFunc(xhr.responseText)[0].rid + ".json", false, username, password); 
     102        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
     103        xhr.send(null); 
     104    } 
     105    function unfavWassr(username, password, user){ 
     106        var xhr = new XMLHttpRequest(); 
     107        xhr.open("POST", "http://api.wassr.jp/user_timeline.json?id=" + user, false, username, password); 
     108        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
     109        xhr.send(null); 
     110        xhr.open("POST", "http://api.wassr.jp/favorites/destroy/" + evalFunc(xhr.responseText)[0].rid + ".json", false, username, password); 
     111        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
     112        xhr.send(null); 
     113    } 
     114    function showWassrReply(username, password){ 
     115        var xhr = new XMLHttpRequest(); 
     116        xhr.open("POST", "http://api.wassr.jp/statuses/replies.json", false, username, password); 
     117        xhr.setRequestHeader("User-Agent", "XMLHttpRequest"); 
     118        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
     119        xhr.send(null); 
     120        var statuses = evalFunc(xhr.responseText); 
     121 
     122        var html = <style type="text/css"><![CDATA[ 
     123            span.wassr.entry-content a { text-decoration: none; } 
     124            img.wassr.photo { border; 0px; width: 16px; height: 16px; vertical-align: baseline; } 
     125        ]]></style>.toSource() 
     126                   .replace(/(?:\r?\n|\r)[ \t]*/g, " ") + 
     127            statuses.map(function(status) 
     128                <> 
     129                    <img src={status.user.profile_image_url} 
     130                         alt={status.user.screen_name} 
     131                         title={status.user.screen_name} 
     132                         class="wassr photo"/> 
     133                    <strong>{status.user_login_id}&#x202C;</strong> 
     134                </>.toSource() 
     135                   .replace(/(?:\r?\n|\r)[ \t]*/g, " ") + 
     136                    sprintf(': <span class="wassr entry-content">%s&#x202C;</span>', status.text)) 
     137                        .join("<br/>"); 
     138 
     139        //liberator.log(html); 
     140        liberator.echo(html, true); 
     141    } 
     142    function showWassrSearchResult(word){ 
     143        var xhr = new XMLHttpRequest(); 
     144        xhr.open("GET", "http://labs.ceek.jp/wassr/rss?k=" + encodeURIComponent(word), false); 
     145        xhr.send(null); 
     146        var items = xhr.responseXML.getElementsByTagName('item'); 
     147        var html = <style type="text/css"><![CDATA[ 
     148            span.wassr.entry-content a { text-decoration: none; } 
     149        ]]></style>.toSource() 
     150            .replace(/(?:\r?\n|\r)[ \t]*/g, " "); 
     151        for (var n = 0; n < items.length; n++) 
     152            html += <> 
     153                <strong>{items[n].getElementsByTagName('title')[0].textContent.replace(/&gt;/g, '>').replace(/&lt;/g, '<').replace(/^%/, '')}&#x202C;</strong> 
     154                : <span class="wassr entry-content">{items[n].getElementsByTagName('description')[0].textContent.replace(/&gt;/g, '>').replace(/&lt;/g, '<')}&#x202C;</span> 
     155 
     156                <br /> 
     157            </>.toSource() 
     158                .replace(/(?:\r?\n|\r)[ \t]*/g, " "); 
    67159        liberator.echo(html, true); 
    68160    } 
     
    183275                .replace(/%TITLE%/g, liberator.buffer.title); 
    184276 
     277            if (special && arg.match(/^\?\s*(.*)/)) 
     278                showWassrSearchResult(RegExp.$1) 
     279            else 
     280            if (special && arg.match(/^\+\s*(.*)/)) 
     281                favWassr(username, password, RegExp.$1) 
     282            else 
     283            if (special && arg.match(/^\-\s*(.*)/)) 
     284                unfavWassr(username, password, RegExp.$1) 
     285            else 
     286            if (special && arg.match(/^@/)) 
     287                showWassrReply(username, password) 
     288            else 
    185289            if (special || arg.length == 0) 
    186290                showFollowersStatus(username, password, arg);