Show
Ignore:
Timestamp:
08/02/08 15:41:48 (4 months ago)
Author:
cho45
Message:
  • 展開数制限をひとまず実装
  • さらに展開を続けられるようにしたい
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/userscripts/hatena.haiku.expandrepliestree.user.js

    r16962 r16974  
    77 
    88(function (unsafeWindow) { with (D()) { 
    9         const WAIT = 1; 
    10         const ICON = [ 
     9        const WAIT  = 1; 
     10        const LEVEL = 9; 
     11        const ICON  = [ 
    1112                "data:image/png;base64,", 
    1213                "iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAMAAAAolt3jAAAAD1BMVEX45u/y", 
     
    4243        } 
    4344 
    44         function expandChildReplies (entry) { 
    45                 var body = $X("./div[@class='list-body']", entry)[0]; 
    46                 return parallel( 
    47                         $X("./div[@class='info']/span[@class='replies']/a[@href]", body).map(function (a) { 
    48                                 a.style.opacity = "0.6"; 
    49                                 // don't show if this was showed entry 
    50                                 var raw_href = $X("string(@href)", a); 
    51                                 if ($X("boolean(.//span[@class='timestamp']/a[@href = '"+raw_href+"'])", entry)) { 
    52                                         a.style.opacity = "0.2"; 
    53                                         return next(); 
    54                                 } 
    55                                 // don't load already showed entry 
    56                                 var es = $X("//div[@class='entry' and .//span[@class='timestamp']/a[@href = '"+raw_href+"']]"); 
    57                                 if (es.length) return appendAndLoadNext(es[0]); 
    58                                 return xhttp.get(a.href).next(function (data) { 
    59                                         // remove unnecessary tags 
    60                                         var t = h(data.responseText.replace(/<\/?(?:script|i?frame)[^>]*>/g, "")); 
    61                                         return parallel($X(".//div[@class='entries']/div[@class='entry']", t).map(appendAndLoadNext)); 
    62                                 }); 
    63  
    64                                 function appendAndLoadNext (e) { 
    65                                         a.style.opacity = "0.2"; 
    66                                         $X("./div[@class='list-body']/div/a[img[@src='/images/icon-replylink.gif']]", e)[0].style.opacity = "0.2"; 
    67  
    68                                         // 時系列に並ぶ様に注意する 
    69                                         var time = $X("string(div/div/span[@class='timestamp']/a)", e); 
    70                                         var ref = $X("./div[@class='entry']", body).filter(function (i) { 
    71                                                 return $X("string(div/div/span[@class='timestamp']/a)", i) < time; 
    72                                         })[0]; 
    73  
    74                                         body.insertBefore(applyJavaScript(e), ref); 
    75                                         return wait(WAIT).next(function () { 
    76                                                 return call(expandChildReplies, e); 
    77                                         }); 
    78                                 } 
    79                         }) 
    80                 ); 
    81         } 
    82  
    83         function expandReplies (entry) { 
    84                 var a    = $X("./div[@class='list-body']/div/a[img[@src='/images/icon-replylink.gif']]", entry)[0]; 
     45        function expandReplies (entry, level) { 
     46                if (typeof level == "undefined") level = LEVEL; 
     47                if (level < 1) return next(); 
     48                log("level:" + level); 
     49 
     50                var a        = $X("./div[@class='list-body']/div/a[img[@src='/images/icon-replylink.gif']]", entry)[0]; 
    8551                var raw_href = $X("string(@href)", a); 
    86                 var es = $X("//div[@class='entry' and .//span[@class='timestamp']/a[@href = '"+raw_href+"']]"); 
    87                 if (a) a.style.opacity = "0.6"; 
     52                var es       = $X("//div[@class='entry' and .//span[@class='timestamp']/a[@href = '"+raw_href+"']]"); 
     53 
     54                if (a)      a.style.opacity = "0.6"; 
    8855 
    8956                $X(".//span[@class='expand']", entry).forEach(function (e) { 
     
    9158                }); 
    9259                return parallel([ 
    93                         expandChildReplies(entry), 
     60                        expandChildReplies(entry, level - 1), 
    9461                        !a ? next() : es.length ? appendAndLoadNext(es[0]) : xhttp.get(a.href).next(function (data) { 
    9562                                var t = h(data.responseText.replace(/<\/?(?:script|i?frame)[^>]*>/g, "")); 
     
    11077                        body.appendChild(entry); 
    11178                        return wait(WAIT).next(function () { 
    112                                 return call(expandReplies, e); 
     79                                return call(expandReplies, e, level - 1); 
    11380                        }); 
     81                } 
     82 
     83                function expandChildReplies (entry, level) { 
     84                        log("level:" + level); 
     85                        if (level < 1) return next(); 
     86 
     87                        var body = $X("./div[@class='list-body']", entry)[0]; 
     88                        return parallel( 
     89                                $X("./div[@class='info']/span[@class='replies']/a[@href]", body).map(function (a) { 
     90                                        a.style.opacity = "0.6"; 
     91                                        // don't show if this was showed entry 
     92                                        var raw_href = $X("string(@href)", a); 
     93                                        if ($X("boolean(.//span[@class='timestamp']/a[@href = '"+raw_href+"'])", entry)) { 
     94                                                a.style.opacity = "0.2"; 
     95                                                return next(); 
     96                                        } 
     97                                        // don't load already showed entry 
     98                                        var es = $X("//div[@class='entry' and .//span[@class='timestamp']/a[@href = '"+raw_href+"']]"); 
     99                                        if (es.length) return appendAndLoadNext(es[0]); 
     100                                        return xhttp.get(a.href).next(function (data) { 
     101                                                // remove unnecessary tags 
     102                                                var t = h(data.responseText.replace(/<\/?(?:script|i?frame)[^>]*>/g, "")); 
     103                                                return parallel($X(".//div[@class='entries']/div[@class='entry']", t).map(appendAndLoadNext)); 
     104                                        }); 
     105 
     106                                        function appendAndLoadNext (e) { 
     107                                                a.style.opacity = "0.2"; 
     108                                                $X("./div[@class='list-body']/div/a[img[@src='/images/icon-replylink.gif']]", e)[0].style.opacity = "0.2"; 
     109 
     110                                                // 時系列に並ぶ様に注意する 
     111                                                var time = $X("string(div/div/span[@class='timestamp']/a)", e); 
     112                                                var ref = $X("./div[@class='entry']", body).filter(function (i) { 
     113                                                        return $X("string(div/div/span[@class='timestamp']/a)", i) < time; 
     114                                                })[0]; 
     115 
     116                                                body.insertBefore(applyJavaScript(e), ref); 
     117 
     118                                                return wait(WAIT).next(function () { 
     119                                                        return call(expandChildReplies, e, level - 1); 
     120                                                }); 
     121                                        } 
     122                                }) 
     123                        ); 
    114124                } 
    115125        }