ページ

2012年2月28日

heatmeter

// ==UserScript==
// @name NicoWatch Tools heatmeter
// @description Nico Nico Douga Greasemonkey script
// @include http://www.nicovideo.jp/watch/*
// @version 0.5.20110519.20120228
// @require http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js
// ==/UserScript==

(function(){
var player = document.getElementById('flvplayer');
var video = unsafeWindow.Video;
var main = {
prm : {
color : [
'333', '33c', '36c', '39c', '3cc', '3c9', '3c6', '3c3',
'6c3', '9c3', 'cc3', 'c93', 'c63', 'c33', 'c33', 'c33'
],
videoLength : video.length,
titleNum : Array(),
chatNum : Array(),
widthSep : 0
},
container : function(){
doc = document.createElement("div");
doc.id = "meter_container";
$('#WATCHFOOTER').prepend($(doc));
$('#meter_container').html('<table><tr><td id="meter_body"></td><td id="meter_sub"></td><tr></table>');
this.body();
},
body : function(){
var nowTime = 0, chatNumMax = 0, bar = '';
for (i = 0; i < 100; i++) {
if(player.ext_getComments(i).length > 0) mainThreadId = i;
}
commentNum = player.ext_getComments(mainThreadId);
for (i = 0; i < commentNum.length; i++) {
if (this.prm.videoLength < Math.floor(commentNum[i].vpos / 1000)) {
this.prm.videoLength += 10;
break;
}
}
var timeInterval = (this.prm.videoLength * 100) / this.prm.widthSep;
for (i = 0; i < this.prm.widthSep; i++) {
nowTime += timeInterval;
this.prm.chatNum[i] = 0;
for (j = 0; j < commentNum.length; j++) {
vpos = commentNum[j].vpos / 10;
if (nowTime - timeInterval <= vpos && vpos < nowTime) this.prm.chatNum[i]++;
}
if (this.prm.chatNum[i] > chatNumMax) chatNumMax = this.prm.chatNum[i];
vposMin = Math.floor((nowTime - timeInterval) / 100 / 60);
vposSec = Math.floor((nowTime - timeInterval) / 100) - vposMin * 60;
if (vposMin < 10) vposMin = '0' + vposMin;
if (vposSec < 10) vposSec = '0' + vposSec;
timeSep = vposMin + ":" + vposSec + " - ";
vposMin = Math.floor(nowTime / 100 / 60);
vposSec = Math.floor(nowTime / 100) - vposMin * 60;
if (vposMin < 10) vposMin = '0' + vposMin;
if (vposSec < 10) vposSec = '0' + vposSec;
timeSep += vposMin + ":" + vposSec;
this.prm.titleNum[i] = timeSep;
}
this.prm.chatNumMax = chatNumMax;
for (i = 0; i < this.prm.widthSep; i++) {
strColor = this.prm.color[Math.round(this.prm.chatNum[i] / this.prm.chatNumMax * 15)];
strComment = this.prm.chatNum[i] + ' ' + this.prm.titleNum[i];
bar += '<div class="meter_bar" id="meter_bar' + i + '" style="background-color:#' + strColor + ';" title="Comment : ' + strComment + '"></div>';
}
for (i = 0, chatNumAll = 0; i < this.prm.widthSep; i++) {
chatNumAll += this.prm.chatNum[i];
}
$('#meter_body').html(bar);
$('#meter_sub').html('<a id="reload">' + chatNumAll + ' Comment GET</a>');
$('#reload').click(function(){main.body()});
}
}
if (player.getAttribute('flashvars').indexOf('isWide=1') > 0) {
if (main.prm.videoLength < 600) {
main.prm.widthSep = 170;
}else if (main.prm.videoLength < 6000) {
main.prm.widthSep = 163;
}else{
main.prm.widthSep = 156;
}
}else{
if (main.prm.videoLength < 600) {
main.prm.widthSep = 106;
}else if (main.prm.videoLength < 6000) {
main.prm.widthSep = 99;
}else{
main.prm.widthSep = 92;
}
}
t = setInterval(function(){
if (player.ext_getStatus() != 'stopped') {
main.container();
clearInterval(t);
}
}, 1000);
GM_addStyle((<><![CDATA[
#player_bottom_textlink a{
color: #ccc;
}
#meter_container{
margin: -9px 0 0 73px;
color: #999;
font-size: 12px;
}
#meter_body{
border: 2px solid #000;
}
#meter_sub{
padding: 5px 5px 0;
cursor: pointer;
}
.meter_bar{
width: 2px;
height: 16px;
float: left;
}
]]></>).toString());
})();