Changeset 3639

Show
Ignore:
Timestamp:
12/27/07 21:12:48 (11 months ago)
Author:
noriaki
Message:

lang/javascript/userscripts/twitterrepliescontext.user.js: fix "Haven\’t updated yet!" users bug. add "follow request" link in protected users context.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/userscripts/twitterrepliescontext.user.js

    r3431 r3639  
    44// @description    Twitter - Viewer Replies Context: Usage: click replies-side image. 
    55// @license        The MIT License 
    6 // @version        0.1.5 
     6// @version        0.1.6 
    77// @released       2007-12-17 14:00:00 
    8 // @updated        2007-12-21 23:00:00 
     8// @updated        2007-12-27 21:00:00 
    99// @conpatible     Greasemonkey 
    1010// @include        http://twitter.com/* 
     
    6262            var div = new RepliesContext.View.context(); 
    6363            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             } 
    7764            div.parentTD = obj.parentTD; 
    7865            if(div.parent = obj.parent) 
    7966                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                } 
    8276            } 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                } 
    8596            } 
    86             //RepliesContext.View.contexts(ctxs, obj); 
    8797            obj.icon.src = obj.icon_src; 
    8898        }, 
     
    118128RepliesContext.View = function() {}; 
    119129RepliesContext.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    }); 
    134144}; 
    135145RepliesContext.View.loading = function() { 
     
    151161RepliesContext.View.context.prototype = { 
    152162    initialize: function() { 
    153         this.element = $N('div', { class: 'rc-contexts'    }); 
     163        this.element = $N('div', { class: 'rc-contexts' }); 
    154164        this.contexts = []; 
    155165        this.children = []; 
     
    216226        this.render(); 
    217227        this.addCloseButton(); 
    218         this.parentTD.style.backgroundColor = '#F9F6BA'; 
    219228        RepliesContext.Controller.insert(this.element, this); 
    220229    }, 
     
    243252    }, 
    244253 
    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(); 
    247296    }, 
    248297 
     
    273322    render: function() { 
    274323        document.getElementById('content').appendChild(this.element); 
     324        this.parentTD.style.backgroundColor = '#F9F6BA'; 
    275325    }, 
    276326 
     
    337387        z-index: 3; 
    338388    } 
    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; } 
    342393    .rc-close { 
    343394        background-color: #f88; 
     
    550601    script_name: 'Twitter - Replies Context', 
    551602    script_url: 'http://blog.fulltext-search.biz/files/twitterrepliescontext.user.js', 
    552     current_version: '0.1.5', 
     603    current_version: '0.1.6', 
    553604    more_info_url: 'http://blog.fulltext-search.biz/pages/twitter-replies-context', 
    554605