Changeset 4950 for lang/javascript
- Timestamp:
- 01/19/08 15:55:42 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/userscripts/niconicodougaanalytics.user.js
r4816 r4950 3 3 // @author noriaki 4 4 // @namespace http://blog.fulltext-search.biz/ 5 // @description 'NicoNicoDouga - Analytics' analyzes comments for movie in NicoNicoDouga5 // @description Analyzes comments for movie in NicoNicoDouga 6 6 // @license The MIT License 7 7 // @version 0.1.0 8 // @released 2008-01-1 7 23:00:009 // @updated 2008-01-1 7 23:00:008 // @released 2008-01-19 14:00:00 9 // @updated 2008-01-19 14:00:00 10 10 // @compatible Greasemonkey 11 11 // @include http://www.nicovideo.jp/watch/* … … 13 13 14 14 // Main 15 function i sReady() {15 function init() { 16 16 var $j = unsafeWindow.jQuery.noConflict(); 17 17 if(!$j('#WATCHFOOTER')) return; … … 57 57 method: 'POST', 58 58 headers: { 59 'User-Agent': 'Mozilla/4.0 (compatible) Greasemonkey (NicoNicoDouga - Plot Comments)',59 'User-Agent': 'Mozilla/4.0 (compatible) Greasemonkey (NicoNicoDouga - Analytics)', 60 60 'Content-type': 'text/xml' 61 61 }, … … 184 184 $j('<div></div>') 185 185 .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'}) 187 187 .appendTo($j('#niconicodouga_analytics')) 188 188 ); … … 340 340 GM_addStyle(<><![CDATA[ 341 341 #niconicodouga_analytics { 342 padding: 10px 0;342 margin: 10px 0; 343 343 border: 1px solid #444; 344 344 } 345 345 #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; 348 349 line-heigth: 1; 349 350 font-size: 120%; 350 border-bottom: 2px solid #ccc; 351 border-bottom: 2px dotted #ccc; 352 background-color: #333; 351 353 } 352 354 #niconicodouga_analytics h4 { … … 356 358 width: 600px; 357 359 height: 300px; 360 margin: 0 10px; 358 361 } 359 362 #niconicodouga_analytics #overtime_graph { … … 362 365 #niconicodouga_analytics .gridLabel { font-size: 80%; } 363 366 .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; 366 370 font-size: 80%; 367 371 color: #ccc; … … 374 378 375 379 // 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 415 380 Number.prototype.z = function(len){ 416 381 if(Math.pow(10,len) <= this) return this.toString(); … … 430 395 return this; 431 396 }; 397 432 398 /** 433 399 * Date.strftime … … 442 408 function LZ(x) {return(x<0||x>9?"":"0")+x} 443 409 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(); 455 413 var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k; 456 414 // Convert real date parts into formatted versions 457 415 var value=new Object(); 458 416 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); 472 421 if (H==0){value["h"]=12;} 473 422 else if (H>12){value["h"]=H-12;} … … 475 424 value["hh"]=LZ(value["h"]); 476 425 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"]); 480 427 if (H > 11) { value["a"]="PM"; } 481 428 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); 486 430 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)) 490 433 token += format.charAt(i_format++); 491 }492 434 if (value[token] != null) { result=result + value[token]; } 493 435 else { result=result + token; } 494 }436 } 495 437 return result; 496 438 } 497 439 440 // External JavaScript Loader 498 441 function ScriptLoader() { this.initialize.apply(this, arguments); }; 499 442 ScriptLoader.prototype = { … … 505 448 }, 506 449 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; 510 453 var self = this; 511 454 for(var i=0,len=this.libs.length; i<len; i++) { … … 539 482 this.wait(); 540 483 } else { 541 setTimeout(arguments.callee, 10); 484 var self = this; 485 setTimeout(function() { self.eval(); }, 10); 542 486 } 543 487 }, … … 545 489 wait: function() { 546 490 if(unsafeWindow.jQuery) { 547 this. onload();491 this.complete(); 548 492 } else { 549 setTimeout(arguments.callee, 10); 493 var self = this; 494 setTimeout(function() { self.wait(); }, 10); 550 495 } 551 496 } … … 557 502 'jquery.dimensions', 'jquery.hoverIntent', 'jquery.cluetip' // tooltip 558 503 ); 559 scripts.load(i sReady);504 scripts.load(init); 560 505 561 506 // for tooltip … … 610 555 UpdateChecker.prototype = { 611 556 script_name: 'NicoNicoDouga Analytics', 612 script_url: 'http://blog.fulltext-search.biz/files/nico analytics.user.js',557 script_url: 'http://blog.fulltext-search.biz/files/niconicodougaanalytics.user.js', 613 558 current_version: '0.1.0', 614 559 more_info_url: 'http://blog.fulltext-search.biz/pages/niconicodouga-analytics', … … 651 596 close_link.setAttribute('href', 'javascript:void(0);'); 652 597 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()); 654 599 var update_alert = document.getElementById('gm_update_alert'); 655 600 update_alert.parentNode.removeChild(update_alert); … … 704 649 } 705 650 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 { 707 655 font-weight: bold; 708 656 } … … 712 660 // Check script update remote 713 661 check_update: function() { 714 if(!this.has_need_for_check ) return;662 if(!this.has_need_for_check()) return; 715 663 var user_script = this; 716 664 GM_xmlhttpRequest({ … … 723 671 user_script.render_update_info(); 724 672 } else { 725 GM_setValue('last_check_day', user_script. days_since_start());673 GM_setValue('last_check_day', user_script.beginning_of_day().toString()); 726 674 } 727 675 }, … … 733 681 // return [true] if necessary 734 682 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) { 738 686 return true; 739 687 } else { … … 751 699 }, 752 700 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() { 755 702 var now = new Date(); 756 return(n ow.getYear() * 365 + DAYS_IN_MONTH[now.getMonth()] + now.getDate());703 return(new Date(now.getFullYear(), now.getMonth(), now.getDate())); 757 704 } 758 705 };
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)