Changeset 3639
- Timestamp:
- 12/27/07 21:12:48 (11 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/userscripts/twitterrepliescontext.user.js
r3431 r3639 4 4 // @description Twitter - Viewer Replies Context: Usage: click replies-side image. 5 5 // @license The MIT License 6 // @version 0.1. 56 // @version 0.1.6 7 7 // @released 2007-12-17 14:00:00 8 // @updated 2007-12-2 1 23:00:008 // @updated 2007-12-27 21:00:00 9 9 // @conpatible Greasemonkey 10 10 // @include http://twitter.com/* … … 62 62 var div = new RepliesContext.View.context(); 63 63 var updates = eval('('+res.responseText+')'); 64 if(updates.error) {65 RepliesContext.View.error(updates, obj);66 obj.icon.src = obj.icon_src;67 return;68 }69 //var ctxs = [];70 for(var i=j=0,len=updates.length; i<len && j<3; i++) {71 if(obj.published > (new Date(updates[i].created_at))) {72 //ctxs.push(updates[i]);73 div.contexts.push(updates[i]);74 j++;75 }76 }77 64 div.parentTD = obj.parentTD; 78 65 if(div.parent = obj.parent) 79 66 div.parent.children.push(div); 80 if(div.contexts.length > 0) { 81 div.success(); 67 if(updates.error) { 68 var ERROR_HANDLE = /(not authorized)/; 69 if(ERROR_HANDLE.test(updates.error)) { 70 div.contexts = updates; 71 div.contexts.user = obj.name; 72 div.protected_user(); 73 } else { 74 RepliesContext.View.error(updates, obj); 75 } 82 76 } else { 83 div.contexts = updates[0]; 84 div.nonexistence_contexts(); 77 for(var i=j=0,len=updates.length; i<len && j<3; i++) { 78 if(obj.published > (new Date(updates[i].created_at))) { 79 div.contexts.push(updates[i]); 80 j++; 81 } 82 } 83 if(div.contexts.length > 0) { 84 div.success(); 85 } else { 86 div.contexts = updates[0]; 87 if(!div.contexts) 88 div.contexts = { 89 user: { 90 name: obj.name, 91 screen_name: obj.name 92 } 93 }; 94 div.nonexistence_contexts(); 95 } 85 96 } 86 //RepliesContext.View.contexts(ctxs, obj);87 97 obj.icon.src = obj.icon_src; 88 98 }, … … 118 128 RepliesContext.View = function() {}; 119 129 RepliesContext.View.icon = function() { 120 var icon = document.createElement('img');121 icon.src = [122 'data:image/gif;base64,',123 'R0lGODlhDgAOANU8AH2Un0Ws4Z+wuTWk3XWNmSWb2Uuv4rG/x6vh+nPE7Gi/6ZPV9Fd0gmi+6keu',124 '4YqfqoSZpJSnsmuFklGy5IufqSGZ2GF9ikhod1ZygExreoqfqWaBjUet4YSapSSc2Smd2ofP8Z+w',125 'uktqeYfP8kWs4BuW11Ky45SosYCAgFOz5JTV9JPV9Wi+6XLE7ByW1oSapIufqjaj3FO05SWc2ZSn',126 'sYjP8YfO8Sie2nHD7IbO8RGR1D09Pf///wAAAAAAAAAAACH5BAEAADwALAAAAAAOAA4AAAaAQJ6Q',127 't9sNj8cdjGAsIomaw4OxsyWMSQKFOUKAUtjhjpHZJWotTpjYKaJ2Msd6dxJEADtccYDdQQQHAjs5',128 'CzksATNNADQheSoIKzgGHzpFEgAvOw2EOQokBZU7GBYbOyYNOAoTMS6VRBciOwMBBgEDFTquREU7',129 'BTceJblrYrxOPEEAOw=='130 ].join('');131 icon.className = 'rc-icon';132 icon.alt = icon.title = 'このReplyの文脈を見る';133 return icon;130 return $N('img', { 131 class: 'rc-icon', 132 title: 'View Replies contexts', 133 src: [ 134 'data:image/gif;base64,', 135 'R0lGODlhDgAOANU8AH2Un0Ws4Z+wuTWk3XWNmSWb2Uuv4rG/x6vh+nPE7Gi/6ZPV9Fd0gmi+6keu', 136 '4YqfqoSZpJSnsmuFklGy5IufqSGZ2GF9ikhod1ZygExreoqfqWaBjUet4YSapSSc2Smd2ofP8Z+w', 137 'uktqeYfP8kWs4BuW11Ky45SosYCAgFOz5JTV9JPV9Wi+6XLE7ByW1oSapIufqjaj3FO05SWc2ZSn', 138 'sYjP8YfO8Sie2nHD7IbO8RGR1D09Pf///wAAAAAAAAAAACH5BAEAADwALAAAAAAOAA4AAAaAQJ6Q', 139 't9sNj8cdjGAsIomaw4OxsyWMSQKFOUKAUtjhjpHZJWotTpjYKaJ2Msd6dxJEADtccYDdQQQHAjs5', 140 'CzksATNNADQheSoIKzgGHzpFEgAvOw2EOQokBZU7GBYbOyYNOAoTMS6VRBciOwMBBgEDFTquREU7', 141 'BTceJblrYrxOPEEAOw==' 142 ].join('') 143 }); 134 144 }; 135 145 RepliesContext.View.loading = function() { … … 151 161 RepliesContext.View.context.prototype = { 152 162 initialize: function() { 153 this.element = $N('div', { class: 'rc-contexts' });163 this.element = $N('div', { class: 'rc-contexts' }); 154 164 this.contexts = []; 155 165 this.children = []; … … 216 226 this.render(); 217 227 this.addCloseButton(); 218 this.parentTD.style.backgroundColor = '#F9F6BA';219 228 RepliesContext.Controller.insert(this.element, this); 220 229 }, … … 243 252 }, 244 253 245 protected: function() { 246 //TODO 254 protected_user: function() { 255 var ctx = this.contexts; 256 this.element.appendChild($N('h4', {}, ctx.error)); 257 var follow = $N('a', { 258 href: 'javascript:void(0);', 259 class: 'rc-action' 260 }, 'Request to follow ' + ctx.user); 261 follow.addEventListener('click', function(e) { 262 var loading = $N('img', { src: 'http://static.twitter.com/images/loader.gif' }); 263 this.parentNode.insertBefore(loading, this.nextSibling); 264 var self = this; 265 GM_xmlhttpRequest({ 266 method: 'GET', 267 url: 'http://twitter.com/friendships/create/' + ctx.user + '.json', 268 onload: function(res) { 269 self.parentNode.removeChild(loading); 270 var data = eval('('+res.responseText+')'); 271 if(data.error) { 272 self.parentNode.appendChild(document.createTextNode(data.error)); 273 } else { 274 self.parentNode.appendChild(document.createTextNode( 275 ctx.user + ' has been sent your request.' 276 )); 277 } 278 self.parentNode.removeChild(self); 279 }, 280 onerror: function(res) { GM_log(res.status + ':' + res.responseText); } 281 }); 282 }, false); 283 this.element.appendChild( 284 $N('p', {}, [ 285 '@', $N('a', { 286 title: ctx.user, 287 href: 'http://twitter.com/' + ctx.user 288 }, ctx.user), 289 ': ', 290 follow 291 ]) 292 ); 293 this.setPosition(); 294 this.render(); 295 this.addCloseButton(); 247 296 }, 248 297 … … 273 322 render: function() { 274 323 document.getElementById('content').appendChild(this.element); 324 this.parentTD.style.backgroundColor = '#F9F6BA'; 275 325 }, 276 326 … … 337 387 z-index: 3; 338 388 } 339 .rc-contexts > h4 { 340 padding-left: 3px; 341 } 389 .rc-contexts td.content { padding-right: 16px; } 390 .rc-contexts > h4 { padding-left: 3px; } 391 .rc-contexts > p { padding-left: 8px; } 392 .rc-contexts .rc-action { margin: 0 3px; } 342 393 .rc-close { 343 394 background-color: #f88; … … 550 601 script_name: 'Twitter - Replies Context', 551 602 script_url: 'http://blog.fulltext-search.biz/files/twitterrepliescontext.user.js', 552 current_version: '0.1. 5',603 current_version: '0.1.6', 553 604 more_info_url: 'http://blog.fulltext-search.biz/pages/twitter-replies-context', 554 605
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)