Changeset 4950 for lang/javascript

Show
Ignore:
Timestamp:
01/19/08 15:55:42 (5 years ago)
Author:
noriaki
Message:

lang/javascript/userscripts/niconicodougaanalytics.user.js: Initial Release!.

Files:
1 modified

Legend:

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

    r4816 r4950  
    33// @author         noriaki 
    44// @namespace      http://blog.fulltext-search.biz/ 
    5 // @description    'NicoNicoDouga - Analytics' analyzes comments for movie in NicoNicoDouga 
     5// @description    Analyzes comments for movie in NicoNicoDouga 
    66// @license        The MIT License 
    77// @version        0.1.0 
    8 // @released       2008-01-17 23:00:00 
    9 // @updated        2008-01-17 23:00:00 
     8// @released       2008-01-19 14:00:00 
     9// @updated        2008-01-19 14:00:00 
    1010// @compatible     Greasemonkey 
    1111// @include        http://www.nicovideo.jp/watch/* 
     
    1313 
    1414// Main 
    15 function isReady() { 
     15function init() { 
    1616        var $j = unsafeWindow.jQuery.noConflict(); 
    1717        if(!$j('#WATCHFOOTER')) return; 
     
    5757                method: 'POST', 
    5858                headers: { 
    59             'User-Agent': 'Mozilla/4.0 (compatible) Greasemonkey (NicoNicoDouga - Plot Comments)', 
     59            'User-Agent': 'Mozilla/4.0 (compatible) Greasemonkey (NicoNicoDouga - Analytics)', 
    6060            'Content-type': 'text/xml' 
    6161        }, 
     
    184184                        $j('<div></div>') 
    185185                        .attr({id: 'overtime_graph', className: 'placeholder'}) 
    186                         .css({width: (ddd_len > 20 ? 950 : (ddd_len - 1) * 50) + 'px'}) 
     186                        .css({width: (ddd_len > 19 ? 930 : (ddd_len - 1) * 50) + 'px'}) 
    187187                        .appendTo($j('#niconicodouga_analytics')) 
    188188                ); 
     
    340340GM_addStyle(<><![CDATA[ 
    341341        #niconicodouga_analytics { 
    342                 padding: 10px 0; 
     342        margin: 10px 0; 
    343343                border: 1px solid #444; 
    344344        } 
    345345        #niconicodouga_analytics h3 { 
    346                 margin: 10px 0.5em 0; 
    347                 padding-left: 0.5em; 
     346                margin-bottom: 10px; 
     347                padding: 10px 0.5em; 
     348        color: #ddd; 
    348349                line-heigth: 1; 
    349350                font-size: 120%; 
    350                 border-bottom: 2px solid #ccc; 
     351                border-bottom: 2px dotted #ccc; 
     352        background-color: #333; 
    351353        } 
    352354        #niconicodouga_analytics h4 { 
     
    356358                width: 600px; 
    357359                height: 300px; 
     360        margin: 0 10px; 
    358361        } 
    359362        #niconicodouga_analytics #overtime_graph { 
     
    362365        #niconicodouga_analytics .gridLabel { font-size: 80%; } 
    363366        .userscript_credit { 
    364                 border-top: 1px dotted #eaeaea; 
    365                 padding-top: 5px; 
     367        background-color: #333; 
     368                border-top: 2px dotted #ccc; 
     369                padding: 5px; 
    366370                font-size: 80%; 
    367371                color: #ccc; 
     
    374378 
    375379// Utility 
    376 function $x(xpath, ctx){ 
    377         ctx = ctx || document; 
    378         var res = document.evaluate(xpath, ctx, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null); 
    379         for(var i, nodes = [] ; i=res.iterateNext() ; nodes.push(i)); 
    380         return nodes; 
    381 } 
    382  
    383 function $N(name, attr, childs) { 
    384     var ret = document.createElement(name); 
    385     for(k in attr) { 
    386         if(!attr.hasOwnProperty(k)) continue; 
    387         if(k == "class") { 
    388             ret.className = attr[k]; 
    389         } else if(k == "style" && typeof(attr[k]) == "object") { 
    390             for(j in attr[k]) ret.style[j] = attr[k][j]; 
    391         } else { 
    392             ret.setAttribute(k, attr[k]); 
    393         } 
    394     } 
    395     switch(typeof childs) { 
    396     case "string": { 
    397         ret.appendChild(document.createTextNode(childs)); 
    398         break; 
    399     } 
    400     case "object": { 
    401         for(var i=0,len=childs.length; i<len; i++) { 
    402             var child = childs[i]; 
    403             if(typeof child == "string") { 
    404                 ret.appendChild(document.createTextNode(child)); 
    405             } else { 
    406                 ret.appendChild(child); 
    407             } 
    408         } 
    409         break; 
    410     } 
    411     } 
    412     return ret; 
    413 } 
    414  
    415380Number.prototype.z = function(len){ 
    416381    if(Math.pow(10,len) <= this) return this.toString(); 
     
    430395    return this; 
    431396}; 
     397 
    432398/** 
    433399* Date.strftime 
     
    442408        function LZ(x) {return(x<0||x>9?"":"0")+x} 
    443409        format=format+""; 
    444         var result=""; 
    445         var i_format=0; 
    446         var c=""; 
    447         var token=""; 
    448         var y=this.getYear()+""; 
    449         var M=this.getMonth()+1; 
    450         var d=this.getDate(); 
    451         var E=this.getDay(); 
    452         var H=this.getHours(); 
    453         var m=this.getMinutes(); 
    454         var s=this.getSeconds(); 
     410        var result="", i_format=0, c="", token=""; 
     411        var y=this.getYear()+"", M=this.getMonth()+1, d=this.getDate(), E=this.getDay(); 
     412        var H=this.getHours(), m=this.getMinutes(), s=this.getSeconds(); 
    455413        var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k; 
    456414        // Convert real date parts into formatted versions 
    457415        var value=new Object(); 
    458416        if (y.length < 4) {y=""+(y-0+1900);} 
    459         value["y"]=""+y; 
    460         value["yyyy"]=y; 
    461         value["yy"]=y.substring(2,4); 
    462         value["M"]=M; 
    463         value["MM"]=LZ(M); 
    464         value["MMM"]=Date.MONTH_NAMES[M-1]; 
    465         value["NNN"]=Date.MONTH_NAMES[M+11]; 
    466         value["d"]=d; 
    467         value["dd"]=LZ(d); 
    468         value["E"]=Date.DAY_NAMES[E+7]; 
    469         value["EE"]=Date.DAY_NAMES[E]; 
    470         value["H"]=H; 
    471         value["HH"]=LZ(H); 
     417        value["y"]=""+y; value["yyyy"]=y; value["yy"]=y.substring(2,4); value["M"]=M; 
     418        value["MM"]=LZ(M); value["MMM"]=Date.MONTH_NAMES[M-1]; value["NNN"]=Date.MONTH_NAMES[M+11]; 
     419        value["d"]=d; value["dd"]=LZ(d); value["E"]=Date.DAY_NAMES[E+7]; 
     420    value["EE"]=Date.DAY_NAMES[E]; value["H"]=H; value["HH"]=LZ(H); 
    472421        if (H==0){value["h"]=12;} 
    473422        else if (H>12){value["h"]=H-12;} 
     
    475424        value["hh"]=LZ(value["h"]); 
    476425        if (H>11){value["K"]=H-12;} else {value["K"]=H;} 
    477         value["k"]=H+1; 
    478         value["KK"]=LZ(value["K"]); 
    479         value["kk"]=LZ(value["k"]); 
     426        value["k"]=H+1; value["KK"]=LZ(value["K"]); value["kk"]=LZ(value["k"]); 
    480427        if (H > 11) { value["a"]="PM"; } 
    481428        else { value["a"]="AM"; } 
    482         value["m"]=m; 
    483         value["mm"]=LZ(m); 
    484         value["s"]=s; 
    485         value["ss"]=LZ(s); 
     429        value["m"]=m; value["mm"]=LZ(m); value["s"]=s; value["ss"]=LZ(s); 
    486430        while (i_format < format.length) { 
    487                 c=format.charAt(i_format); 
    488                 token=""; 
    489                 while ((format.charAt(i_format)==c) && (i_format < format.length)) { 
     431                c=format.charAt(i_format); token=""; 
     432                while ((format.charAt(i_format)==c) && (i_format < format.length)) 
    490433                        token += format.charAt(i_format++); 
    491                         } 
    492434                if (value[token] != null) { result=result + value[token]; } 
    493435                else { result=result + token; } 
    494                 } 
     436        } 
    495437        return result; 
    496438} 
    497439 
     440// External JavaScript Loader 
    498441function ScriptLoader() { this.initialize.apply(this, arguments); }; 
    499442ScriptLoader.prototype = { 
     
    505448    }, 
    506449 
    507     load: function(onload) { 
    508         if(typeof onload != 'function') return; 
    509         this.onload = onload; 
     450    load: function(complete) { 
     451        if(typeof complete != 'function') return; 
     452        this.complete = complete; 
    510453        var self = this; 
    511454        for(var i=0,len=this.libs.length; i<len; i++) { 
     
    539482            this.wait(); 
    540483        } else { 
    541                         setTimeout(arguments.callee, 10); 
     484            var self = this; 
     485                        setTimeout(function() { self.eval(); }, 10); 
    542486        } 
    543487    }, 
     
    545489        wait: function() { 
    546490                if(unsafeWindow.jQuery) { 
    547                         this.onload(); 
     491                        this.complete(); 
    548492                } else { 
    549                         setTimeout(arguments.callee, 10); 
     493            var self = this; 
     494                        setTimeout(function() { self.wait(); }, 10); 
    550495                } 
    551496        } 
     
    557502        'jquery.dimensions', 'jquery.hoverIntent', 'jquery.cluetip' // tooltip 
    558503        ); 
    559 scripts.load(isReady); 
     504scripts.load(init); 
    560505 
    561506// for tooltip 
     
    610555UpdateChecker.prototype = { 
    611556    script_name: 'NicoNicoDouga Analytics', 
    612     script_url: 'http://blog.fulltext-search.biz/files/nicoanalytics.user.js', 
     557    script_url: 'http://blog.fulltext-search.biz/files/niconicodougaanalytics.user.js', 
    613558    current_version: '0.1.0', 
    614559    more_info_url: 'http://blog.fulltext-search.biz/pages/niconicodouga-analytics', 
     
    651596        close_link.setAttribute('href', 'javascript:void(0);'); 
    652597        close_link.addEventListener('click', function() { 
    653             GM_setValue('last_check_day', self.days_since_start()); 
     598            GM_setValue('last_check_day', self.beginning_of_day().toString()); 
    654599            var update_alert = document.getElementById('gm_update_alert'); 
    655600            update_alert.parentNode.removeChild(update_alert); 
     
    704649            } 
    705650 
    706             #gm_update_alert p + a:link { 
     651            #gm_update_alert p + a:link, 
     652            #gm_update_alert p + a:visited, 
     653            #gm_update_alert p + a:active, 
     654            #gm_update_alert p + a:hover { 
    707655                font-weight: bold; 
    708656            } 
     
    712660    // Check script update remote 
    713661    check_update: function() { 
    714         if(!this.has_need_for_check) return; 
     662        if(!this.has_need_for_check()) return; 
    715663        var user_script = this; 
    716664        GM_xmlhttpRequest({ 
     
    723671                    user_script.render_update_info(); 
    724672                } else { 
    725                     GM_setValue('last_check_day', user_script.days_since_start()); 
     673                    GM_setValue('last_check_day', user_script.beginning_of_day().toString()); 
    726674                } 
    727675            }, 
     
    733681    // return [true] if necessary 
    734682    has_need_for_check: function() { 
    735         var last_check_day = GM_getValue('last_check_day'); 
    736         var current_day = this.days_since_start(); 
    737         if(typeof last_check_day == 'undefined' || current_day > last_check_day) { 
     683        var last_check_day = new Date(GM_getValue('last_check_day', "Thu Jan 01 1970 00:00:00 GMT+0900")); 
     684        var current_day = this.beginning_of_day(); 
     685        if(current_day > last_check_day) { 
    738686            return true; 
    739687        } else { 
     
    751699    }, 
    752700 
    753     days_since_start: function() { 
    754         var DAYS_IN_MONTH = [31,59,90,120,151,181,212,243,273,304,334,365]; 
     701    beginning_of_day: function() { 
    755702        var now = new Date(); 
    756         return(now.getYear() * 365 + DAYS_IN_MONTH[now.getMonth()] + now.getDate()); 
     703        return(new Date(now.getFullYear(), now.getMonth(), now.getDate())); 
    757704    } 
    758705};