Show
Ignore:
Timestamp:
06/28/08 23:37:57 (5 months ago)
Author:
kga
Message:

キャッシュ機能つけた。

Files:
1 modified

Legend:

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

    r14791 r14795  
    1414window.addEventListener('load', function () { with (D()) { 
    1515    var w = (typeof unsafeWindow == 'undefined') ? window : unsafeWindow; 
     16    var cache = new Cache(); 
    1617 
    1718    if (GM_getValue('hide', false)) addClass('right_body', 'nocomment'); 
     
    5354                            '<span class="date">', dt.ymd_jp(), ' ', dt.hms(), '</span>', 
    5455                            '<a href="http://b.hatena.ne.jp/', id, '/">', 
    55                             '<img src="http://www.hatena.ne.jp/users/', id.substr(0, 2), '/', id, '/profile_s.gif" width="16" height="16">', id, '</a>', 
     56                            '<img src="http://www.hatena.ne.jp/users/', id.substr(0, 2), '/', id, '/profile_s.gif" width="16" height="16">', id, '</a> ', 
    5657                            tags, o.comment, 
    5758                        '</div>' 
     
    8889                            '<span class="date">', dt.ymd_jp(), ' ', dt.hms(), '</span>', 
    8990                            '<a href="http://clip.livedoor.com/clips/', id, '">', 
    90                             '<img src="http://image.profile.livedoor.jp/icon/', id, '_16.gif" width="16" height="16">', id, '</a>', 
     91                            '<img src="http://image.profile.livedoor.jp/icon/', id, '_16.gif" width="16" height="16">', id, '</a> ', 
    9192                            tags, o.notes.escapeHTML(), 
    9293                        '</div>' 
     
    9697        }; 
    9798 
    98         w.LoadEffect.Start(); 
    9999 
    100         parallel([ 
    101             xhttp.get(hatena.api + url).next(hatena.parseResponse), 
    102             xhttp.get(livedoor.api + url).next(livedoor.parseResponse) 
    103         ]).next(function (o) { 
    104             w.LoadEffect.Stop(); 
     100        if (elem) { 
     101            elem.parentNode.removeChild(elem); 
     102        } 
     103        else if (cache.has(item_id)) { 
     104            showComments(cache.get(item_id)); 
     105        } 
     106        else { 
     107            w.LoadEffect.Start(); 
    105108 
    106             var comments = merge(o).sort(function (a, b) { 
    107                 return b.sort_key - a.sort_key; 
    108             }).map(function (c) { return c.comment }).join('\n'); 
     109            parallel([ 
     110                xhttp.get(hatena.api + url).next(hatena.parseResponse), 
     111                xhttp.get(livedoor.api + url).next(livedoor.parseResponse) 
     112            ]).next(function (o) { 
     113                w.LoadEffect.Stop(); 
    109114 
     115                var comments = merge(o).sort(function (a, b) { 
     116                    return b.sort_key - a.sort_key; 
     117                }).map(function (c) { return c.comment }).join('\n'); 
     118 
     119                cache.set(item_id, comments); 
     120 
     121                showComments(comments); 
     122            }).error(function (e) { 
     123                alert(e); 
     124            }); 
     125        } 
     126 
     127        function showComments (comments) { 
    110128            var d = $N('div', { 
    111129                id    : 'sbm_' + item_id, 
     
    116134//            d.innerHTML = '<h2 class="flat_menu sbm_comment">SBM Comments</h2>' + comments; 
    117135 
    118             try { $('item_' + item_id).appendChild(d); } catch (e) { alert(e) } 
    119         }).error(function (e) { 
    120             alert(e); 
    121         }); 
     136            try { $('item_' + item_id).appendChild(d); } catch (e) {} 
     137        } 
    122138    }); 
    123139