ページ

2012年10月16日

Nico Comment Graph

// ==UserScript==
// @name Nico Comment Graph
// @version 0.20121016
// @description Niconico video comment chart script for Chrome
// @include http://www.nicovideo.jp/watch/*
// @require http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js
// ==/UserScript==

(function(){
player = document.getElementById('flvplayer');
videoLength = unsafeWindow.Video.length + 1;
barQty = 0;
arrayBar = Array();
arrayTime = Array();
arrayColor = [
'000', '00f', '33c', '36c', '39c', '3cc', '3c9', '3c6',
'3c3', '6c3', '9c3', 'cc3', 'c93', 'c63', 'c33', 'f00'
];
func = {
container : function(){
doc = document.createElement('div');
doc.id = 'graph_container';
$('#WATCHFOOTER').prepend($(doc));
$('#graph_container').html('<table><tr><td id="graph_body"></td><td id="graph_text"></td><tr></table>');
this.body();
},
body : function(){
for (i = 0; i < 10; i++) {
if(player.ext_getComments(i).length > 0) threadId = i;
}
arrayComment = player.ext_getComments(threadId);
for (i = 0; i < arrayComment.length; i++) {
if (videoLength + 1 < Math.floor(arrayComment[i].vpos / 1000)) {
videoLength += 10;
break;
}
}
barTimeLength = videoLength / barQty;
for (i = 0, barTime = 0, barNumMax = 0; i < barQty; i++) {
barTime += barTimeLength;
arrayBar[i] = 0;
for (j = 0; j < arrayComment.length; j++) {
vpos = arrayComment[j].vpos / 1000;
if (barTime - barTimeLength <= vpos && vpos < barTime) arrayBar[i]++;
}
if (arrayBar[i] > barNumMax) barNumMax = arrayBar[i];
vposMin = Math.floor((barTime - barTimeLength) / 60);
vposSec = Math.floor(barTime - barTimeLength) - vposMin * 60;
if (vposMin < 10) vposMin = '0' + vposMin;
if (vposSec < 10) vposSec = '0' + vposSec;
arrayTime[i] = vposMin + ':' + vposSec + ' - ';
vposMin = Math.floor(barTime / 60);
vposSec = Math.floor(barTime) - vposMin * 60;
if (vposMin < 10) vposMin = '0' + vposMin;
if (vposSec < 10) vposSec = '0' + vposSec;
arrayTime[i] += vposMin + ':' + vposSec;
}
for (i = 0, bar = ''; i < barQty; i++) {
strColor = arrayColor[Math.round(arrayBar[i] / barNumMax * 15)];
if(arrayBar[i] == 0) strColor = 'fff';
strComment = arrayBar[i] + ' ' + arrayTime[i];
bar += '<div class="graph_bar" style="margin-top:' + arrayBar[i] + 'px;background:#' + strColor + ';" title="Comment : ' + strComment + '"></div>';
}
$('#graph_body').html(bar);
$('#graph_text').html('<a id="reload">' + arrayComment.length + ' Comment GET</a>');
$('#reload').click(function(){func.body()});
}
}
if (player.getAttribute('flashvars').indexOf('isWide=1') > 0) {
if (videoLength < 600) {
barQty = 170;
}else if (videoLength < 6000) {
barQty = 163;
}else{
barQty = 156;
}
}else{
if (videoLength < 600) {
barQty = 106;
}else if (videoLength < 6000) {
barQty = 99;
}else{
barQty = 92;
}
}
t = setInterval(function(){
if (player.ext_getStatus() != 'stopped') {
func.container();
clearInterval(t);
}
}, 3000);
GM_addStyle((<><![CDATA[
#player_bottom_textlink a{
color: #ccc;
}
#graph_container{
margin: -506px 0 0 75px;
color: #333;
font-size: 12px;
}
#graph_text{
padding: 504px 5px 0;
cursor: pointer;
}
.graph_bar{
width: 2px;
height: 500px;
float: left;
}
]]></>).toString());
})();