Skip to content

Instantly share code, notes, and snippets.

@kei-s
Created May 15, 2010 15:36
Show Gist options
  • Save kei-s/402246 to your computer and use it in GitHub Desktop.
Save kei-s/402246 to your computer and use it in GitHub Desktop.
Heat the nicovideo up (patched)
//// -*- mode: javascript; coding: utf-8 -*-
// ==UserScript==
// @name Heat the nicovideo up
// @author noriaki
// @namespace http://blog.fulltext-search.biz/
// @description Visualize comments upsurge for Nicovideo
// @license MIT License
// @version 0.4.0
// @released 2007-09-11 09:00:00
// @updated 2009-06-07 19:58:00
// @compatible >= Greasemonkey-0.8.20080609.0
// @include http://www.nicovideo.jp/watch/*
// @require http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js
// @require http://blog.fulltext-search.biz/files/gm/gm-config-helper.js
// @require http://blog.fulltext-search.biz/files/gm/gm-update-checker.js
// @require http://blog.fulltext-search.biz/javascripts/gm/jquery.heatcolor.0.0.1.js
// @resource bg http://blog.fulltext-search.biz/images/gm/heat-background.gif
// ==/UserScript==
/*
* This file is a Greasemonkey user script. To install it, you need
* the Firefox plugin "Greasemonkey" (URL: http://greasemonkey.mozdev.org/)
* After you installed the extension, restart Firefox and revisit
* this script. Now you will see a new menu item "Install User Script"
* in your tools menu.
*
* To uninstall this script, go to your "Tools" menu and select
* "Manage User Scripts", then select this script from the list
* and click uninstall :-)
*
* The MIT License (--> or Public Domain)
* http://www.opensource.org/licenses/mit-license.php
* http://sourceforge.jp/projects/opensource/wiki/licenses%2FMIT_license (Japanese)
*/
jQuery.noConflict();
jQuery.parseQueryString = function(str) {
var memo = str.split('&');
for(var i=0,obj={},l=memo.length; i<l; i++) {
var pair = memo[i];
if((pair = pair.split('='))[0]) {
var name = decodeURIComponent(pair[0]),
value = pair[1] ? decodeURIComponent(pair[1]) :undefined;
if(obj[name] !== undefined) {
if(obj[name].constructor != Array) obj[name] = [obj[name]];
if(value) obj[name].push(value);
} else {
var dummy = parseInt(new Number(value), 10);
obj[name] = isNaN(dummy) ? value : dummy;
}
}
}
return obj;
};
jQuery.fill = function(array,v){
if(v.constructor !== Number) {
var F = function(){};
F.prototype = v;
for(var i=0,l=array.length;i<l;i++) array[i] = new F();
} else {
for(var i=0,l=array.length;i<l;array[i++]=v);
}
return array;
};
jQuery(function($) {
var config = new ConfigHelper(),
DIVISION = 55,
heat = {
ua: ['Mozilla/5.0',
'(compatible Greasemonkey Heat the Nicovideo up-0.4.0',
'+http://blog.fulltext-search.biz/pages/visualize-comments-upsurge-greasemonkey-script-for-nicovideo)'
].join(' ')
},
u = unsafeWindow,
nico = {
user: {
id: u.user_id
},
video: {
id: u.video_id,
thread: $('input[name="thread_id"]').val()
}
};
GM_xmlhttpRequest({
method: 'GET',
url: 'http://flapi.nicovideo.jp/api/getflv?v='+nico.video.id+'&ts='+nico.video.thread,
onload: function(data) {
data = $.parseQueryString(data.responseText);
$.extend(nico.video, {
ms: data.ms,
url: data.url,
l: data.l,
link: data.link
});
GM_xmlhttpRequest({
method: 'POST',
headers: {
'User-Agent': heat.ua,
'Content-type': 'text/xml'
},
url: nico.video.ms,
data: '<thread thread="' + nico.video.thread + '" version="20061206" res_from="-1000" user_id="' + nico.user.id + '" />',
onload: function(xhr) {
heatmap(xhr);
},
onerror: function(xhr){ GM_log(xhr.status + ':' + xhr.responseText); }
});
}
});
function heatmap(data) {
var xml = $(data.responseText),
sep = nico.video.l / DIVISION,
comments = $.fill(new Array(DIVISION), 0),
chats = xml.find('chat').map(function(i,chat) {
chat = $(chat);
var obj = {
no: parseInt(chat.attr('no'),10),
thread: chat.attr('thread'),
date: new Date(parseInt(chat.attr('date'),10) * 1000),
vpos: parseInt(chat.attr('vpos'),10) / 100,
user_id: chat.attr('user_id'),
premium: chat.attr('premium') == '1',
anonymity: chat.attr('anonymity') == '1',
mail: chat.attr('mail') ? chat.attr('mail').split(' ') : [],
text: chat.text()
},
idx = ~~(obj.vpos /sep);
comments[idx / DIVISION >= 1 ? DIVISION - 1 : idx]++;
return obj;
});
$('#WATCHFOOTER').before('<div id="heatmap_container"><div id="heatmap"></div></div>');
$.each(comments, function(i,c) {
$('#heatmap').append('<span title="'+c+'">.</span>');
});
$('#heatmap span').heatcolor(
function() { return $(this).attr('title'); },
{
maxval: Math.max.apply(null,comments),
minval: 0,
lightness: 0
}
);
$('<div />')
.attr({ id: 'heatmenu' })
.append(
$('<input type="submit" />')
.val('動画ダウンロード')
.addClass('submit')
.click(function() { GM_openInTab(nico.video.url); })
)
.appendTo($('#heatmap_container'));
$('<p />')
.addClass('userscript_credit')
.html('provided by <a href="http://blog.fulltext-search.biz/">noriaki</a>.<br />' +
'powered by <a href="http://www.nicovideo.jp/">ニコニコ動画</a>, ' +
'<a href="http://www.greasespot.net/">Greasemonkey</a>, ' +
'<a href="http://jquery.com/">jQuery</a>.')
.appendTo($('#heatmap_container'));
}
});
GM_addStyle(<><![CDATA[
#heatmap_container {
margin: 5px;
padding: 4px;
font-size: 80%;
position: relative;
border: 1px solid #ccc;
min-height: 3em;
}
#heatmap {
margin-left: 84px;
border: 1px solid #ddd;
min-height: 1.4em;
padding: 2px;
/*width: 165px;*/
float: left;
}
#heatmap > span {
display: block;
height: 1.4em;
float: left;
cursor: default;
overflow: hidden;
width: 3.7px;
color: #fff;
text-indent: -9999px;
}
#heatmenu {
margin-left: 250px;
}
#heatmenu input {
margin: 0 0.3em;
font-size: 80%;
}
#heat_filter_list {
position: absolute;
width: 300px;
border: #eb720a 1px solid;
z-index: 4;
background-color: #fff;
}
#heat_filter_list p {
padding: 2px 5px;
font-weight: bold;
color: #eee;
background-color: #333;
}
#heat_filter_list ul {
margin: 0;
padding: 10px;
font-family: Tahoma, Arial, Helvetica, sans-serif;
font-size: 13px;
line-height: 1.5;
background-color: #f6f6f6;
}
#heat_filter_list ul li {
margin: 0 0.2em 0.4em 0;
padding: 0;
display: inline;
font-size: 100%;
list-style: none;
cursor: pointer;
border: #aaa 1px solid;
padding: 2px;
background-color: #fff;
}
#heat_filter_list ul li:hover {
border-color: #eb720a;
background-color: #333;
color: #fff;
}
p.userscript_credit {
position: absolute;
bottom: 5px;
right: 5px;
text-align: right;
font-size: 80%;
color: #aaa;
margin: 0;
clear: both;
}
p.userscript_credit a {
color: #aaa;
}
]]></>.toString());
GM_addStyle([
'#heatmap_container {',
' background: #fff url(' + GM_getResourceURL('bg') + ') no-repeat left bottom;',
'}'
].join("\n"));
function log() {
if(unsafeWindow.console) unsafeWindow.console.log(arguments);
}
new UpdateChecker({
script_name: 'Heat the nicovideo up'
,script_url: 'http://blog.fulltext-search.biz/files/heat_the_nicovideo_up.user.js'
,current_version: '0.4.0'
,more_info_url: 'http://blog.fulltext-search.biz/pages/visualize-comments-upsurge-greasemonkey-script-for-nicovideo'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment