Changeset 18437
- Timestamp:
- 08/29/08 19:54:03 (4 months ago)
- Files:
-
- 1 modified
-
lang/javascript/vimperator-plugins/trunk/wassr.js (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/vimperator-plugins/trunk/wassr.js
r15935 r18437 1 1 // Vimperator plugin: "Update Wassr" 2 // Last Change: 17-Jul-2008. Jan 20082 // Last Change: 29-Aug-2008. Jan 2008 3 3 // License: Creative Commons 4 4 // Maintainer: mattn <mattn.jp@gmail.com> - http://mattn.kaoriya.net/ … … 6 6 // 7 7 // 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. 8 36 9 37 (function(){ 38 var passwordManager = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager); 10 39 var evalFunc = window.eval; 11 40 try { … … 18 47 } catch(e) { liberator.log('warning: wassr.js is working with unsafe sandbox.'); } 19 48 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 } 22 54 function emojiConv(str){ 23 55 return str.replace(/[^*+.-9A-Z_a-z-]/g,function(s){ … … 32 64 xhr.send("status=" + encodeURIComponent(stat) + "&source=" + encodeURIComponent("vimperator/wassr.js")); 33 65 } 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 }39 66 function showFollowersStatus(username, password, target){ 40 67 var xhr = new XMLHttpRequest(); … … 65 92 .join("<br/>"); 66 93 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}‬</strong> 134 </>.toSource() 135 .replace(/(?:\r?\n|\r)[ \t]*/g, " ") + 136 sprintf(': <span class="wassr entry-content">%s‬</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(/>/g, '>').replace(/</g, '<').replace(/^%/, '')}‬</strong> 154 : <span class="wassr entry-content">{items[n].getElementsByTagName('description')[0].textContent.replace(/>/g, '>').replace(/</g, '<')}‬</span> 155 156 <br /> 157 </>.toSource() 158 .replace(/(?:\r?\n|\r)[ \t]*/g, " "); 67 159 liberator.echo(html, true); 68 160 } … … 183 275 .replace(/%TITLE%/g, liberator.buffer.title); 184 276 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 185 289 if (special || arg.length == 0) 186 290 showFollowersStatus(username, password, arg);
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)