aboutsummaryrefslogtreecommitdiffstats
path: root/vimp_to_android_phone.js
diff options
context:
space:
mode:
Diffstat (limited to 'vimp_to_android_phone.js')
0 files changed, 0 insertions, 0 deletions
='#n73'>73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
// Vimperator plugin: "Update Wassr"
// Last Change: 19-Jan-2009. Jan 2008
// License: Creative Commons
// Maintainer: mattn <mattn.jp@gmail.com> - http://mattn.kaoriya.net/
// Based On: twitter.js by Trapezoid
//
// The script allows you to update Wassr status from Vimperator 0.6.*.
//
// Commands:
//  :wassr some thing text
//      post "some thing text" to wassr.
//  :wassr! someone
//      show someone's statuses.
//  :wassr!? someword
//      show search result of 'someword' from "http://labs.ceek.jp/wassr/".
//  :wassr!@
//      show replies.
//  :wassr!+ someone
//      fav someone's last status.. mean put iine.
//  :wassr!- someone
//      un-fav someone's last status.. mean remove iine.
//  :wassr -footmark
//      show footmarks.
//  :wassr -todo
//      show your todos.
//  :wassr -todo+ some thing text
//      add 'some thing text' to your todo.
//  :wassr -todo- todo-id
//      remove todo which id is todo-id.
//  :wassr -todo* todo-id
//      start todo which id is todo-id.
//  :wassr -todo/ todo-id
//      stop todo which id is todo-id.
//  :wassr -todo! todo-id
//      done todo which id is todo-id.

(function(){
    var passwordManager = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
    var evalFunc = window.eval;
    try {
        var sandbox = new Components.utils.Sandbox(window);
        if (Components.utils.evalInSandbox("true", sandbox) === true) {
            evalFunc = function(text) {
                return Components.utils.evalInSandbox(text, sandbox);
            }
        }
    } catch(e) { liberator.log('warning: wassr.js is working with unsafe sandbox.'); }

    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 emojiConv(str){
        return str.replace(/[^*+.-9A-Z_a-z-]/g,function(s){
            var c = s.charCodeAt(0);
            return (0xE001 <= c && c <= 0xF0FC) ? '<img src="http://wassr.jp/img/pictogram/' + c.toString(16).toUpperCase() + '.gif"/>' : s;
        })
    }
    function sayWassr(username, password, stat){
        var xhr = new XMLHttpRequest();
        xhr.open("POST", "http://api.wassr.jp/statuses/update.json", false, username, password);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xhr.send("status=" + encodeURIComponent(stat) + "&source=" + encodeURIComponent("vimperator/wassr.js"));
    }
    function showFollowersStatus(username, password, target){
        var xhr = new XMLHttpRequest();
        var endPoint = target ? "http://api.wassr.jp/user_timeline.json?id=" + target
            : "http://api.wassr.jp/statuses/friends_timeline.json?id=" + username;
        xhr.open("GET", endPoint, false, username, password);
        xhr.setRequestHeader("User-Agent", "XMLHttpRequest");
        // for debug
        //xhr.open("GET", "http://api.wassr.jp/statuses/user_timeline/otsune.json", false, username, password);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xhr.send(null);
        var statuses = evalFunc(xhr.responseText) || [];

        var html = <style type="text/css"><![CDATA[
            span.wassr.entry-content a { text-decoration: none; }
            img.wassr.photo { border; 0px; width: 16px; height: 16px; vertical-align: baseline; margin: 1px; }
        ]]></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="wassr photo"/>
                    <strong>{status.user_login_id}&#x202C;</strong>
                </>.toSource()
                   .replace(/(?:\r?\n|\r)[ \t]*/g, " ") +
                    sprintf(': <span class="wassr entry-content">%s&#x202C;</span>', status.html))
                        .join("<br/>");

        liberator.echo(html, true);
    }
    function favWassr(username, password, user){
        var xhr = new XMLHttpRequest();
        xhr.open("POST", "http://api.wassr.jp/user_timeline.json?id=" + user, false, username, password);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xhr.send(null);
        xhr.open("POST", "http://api.wassr.jp/favorites/create/" + evalFunc(xhr.responseText)[0].rid + ".json", false, username, password);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xhr.send(null);
    }
    function unfavWassr(username, password, user){
        var xhr = new XMLHttpRequest();
        xhr.open("POST", "http://api.wassr.jp/user_timeline.json?id=" + user, false, username, password);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xhr.send(null);
        xhr.open("POST", "http://api.wassr.jp/favorites/destroy/" + evalFunc(xhr.responseText)[0].rid + ".json", false, username, password);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xhr.send(null);
    }
    function showWassrReply(username, password){
        var xhr = new XMLHttpRequest();
        xhr.open("POST", "http://api.wassr.jp/statuses/replies.json", false, username, password);
        xhr.setRequestHeader("User-Agent", "XMLHttpRequest");
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xhr.send(null);
        var statuses = evalFunc(xhr.responseText);

        var html = <style type="text/css"><![CDATA[
            span.wassr.entry-content a { text-decoration: none; }
            img.wassr.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="wassr photo"/>
                    <strong>{status.user_login_id}&#x202C;</strong>
                </>.toSource()
                   .replace(/(?:\r?\n|\r)[ \t]*/g, " ") +
                    sprintf(': <span class="wassr entry-content">%s&#x202C;</span>', status.html))
                        .join("<br/>");

        //liberator.log(html);
        liberator.echo(html, true);
    }
    function showWassrSearchResult(word){
        var xhr = new XMLHttpRequest();
        xhr.open("GET", "http://labs.ceek.jp/wassr/rss?k=" + encodeURIComponent(word), false);
        xhr.send(null);
        var items = xhr.responseXML.getElementsByTagName('item');
        var html = <style type="text/css"><![CDATA[
            span.wassr.entry-content a { text-decoration: none; }
        ]]></style>.toSource()
            .replace(/(?:\r?\n|\r)[ \t]*/g, " ");
        for (var n = 0; n < items.length; n++)
            html += <>
                <strong>{items[n].getElementsByTagName('title')[0].textContent.replace(/&gt;/g, '>').replace(/&lt;/g, '<').replace(/^%/, '')}&#x202C;</strong>
                : <span class="wassr entry-content">{items[n].getElementsByTagName('description')[0].textContent.replace(/&gt;/g, '>').replace(/&lt;/g, '<')}&#x202C;</span>

                <br />
            </>.toSource()
                .replace(/(?:\r?\n|\r)[ \t]*/g, " ");
        liberator.echo(html, true);
    }
    function todoAction(username, password, arg){
        var xhr = new XMLHttpRequest();
        if (arg.match(/\+ (.*)/)) {
            xhr.open("POST", "http://api.wassr.jp/todo/add.json", false, username, password);
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xhr.send("body=" + encodeURIComponent(RegExp.$1));
        } else
        if (arg.match(/- (.*)/)) {
            xhr.open("POST", "http://api.wassr.jp/todo/delete.json", false, username, password);
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xhr.send("todo_rid=" + encodeURIComponent(RegExp.$1));
        } else
        if (arg.match(/\* (.*)/)) {
            xhr.open("POST", "http://api.wassr.jp/todo/start.json", false, username, password);
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xhr.send("todo_rid=" + encodeURIComponent(RegExp.$1));
        } else
        if (arg.match(/\/ (.*)/)) {
            xhr.open("POST", "http://api.wassr.jp/todo/stop.json", false, username, password);
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xhr.send("todo_rid=" + encodeURIComponent(RegExp.$1));
        } else
        if (arg.match(/! (.*)/)) {
            xhr.open("POST", "http://api.wassr.jp/todo/done.json", false, username, password);
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xhr.send("todo_rid=" + encodeURIComponent(RegExp.$1));
        }

        xhr.open("GET", "http://api.wassr.jp/todo/list.json", false, username, password);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xhr.send(null);
        var todos = evalFunc(xhr.responseText);

        var html = <style type="text/css"><![CDATA[
            span.wassr.entry-content a { text-decoration: none; }
            img.wassr.icon { border; 0px; width: 16px; height: 16px; vertical-align: baseline; }
        ]]></style>.toSource()
                   .replace(/(?:\r?\n|\r)[ \t]*/g, " ") +
            todos.map(function(todo)
                <>
                    <img src="http://wassr.jp/img/icn-balloon.gif"
                         alt="todo"
                         title="todo"
                         class="wassr icon"/>
                    <strong>{todo.todo_rid}</strong>
                </>.toSource()
                   .replace(/(?:\r?\n|\r)[ \t]*/g, " ") +
                    sprintf(': <span class="wassr entry-content">%s</span>', todo.body))
                        .join("<br/>");

        liberator.echo(html, true);
    }
    function footmarkAction(username, password){
        var xhr = new XMLHttpRequest();
        xhr.open("GET", "http://api.wassr.jp/footmark/recent.json", false, username, password);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xhr.send(null);
        var footmarks = evalFunc(xhr.responseText);

        var html = <style type="text/css"><![C