Advertisement
Guest User

twitchkeyvisualizer

a guest
Feb 18th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. document.querySelector("#channel_panels_contain").innerHTML="";if(!style){var style=document.createElement("style");var css=".chart rect{stroke:#fff;fill:#4682b4}.axis{font:10px sans-serif}.axis line,.axis path{fill:none;stroke:#000;shape-rendering:crispEdges}.x.axis path{display:none})";style.type="text/css";if(style.styleSheet){style.styleSheet.cssText=css}else{style.appendChild(document.createTextNode(css))}document.getElementsByTagName("head")[0].appendChild(style)}function runViz(){var query="#channel_panels_contain";var keysNDS=["a","b","left","right","up","down","x","y","start","select","anarchy","democracy"];var MyMutationTest=(function(){var mod={};mod.resetCount=function(){return[{lab:"u",key:"up",n:0},{lab:"d",key:"down",n:0},{lab:"l",key:"left",n:0},{lab:"r",key:"right",n:0},{lab:"a",key:"a",n:0},{lab:"b",key:"b",n:0},{lab:"st",key:"start",n:0},{lab:"se",key:"select",n:0},{lab:"a",key:"anarchy",n:0},{lab:"d",key:"democracy",n:0}]};mod.keys=mod.resetCount();mod.numKeys=0;mod.lastTime=new Date().getTime();mod.last=0;mod.target=document.querySelector("#chat_line_list");mod.config={subtree:true,childList:true};mod.observe=function(){mod.observer.observe(mod.target,mod.config)};mod.mutLog=function(mutations){var lastChatMessage,current;lastChatMessage=mutations[0].target.lastChild;current=lastChatMessage.textContent.replace(/[\u00BB]/g,"").trim();var content=current.split(":");if(content.length===2){user=content[0];input=content[1]}else{input=content[0]}var key=input.toLowerCase().trim();if(_.contains(keysNDS,key)){_.find(mod.keys,function(obj){return obj.key===key}).n++}};mod.observer=new MutationObserver(mod.mutLog);var tallyTime=1;var count=0;var timer=1;var run=setInterval(function(){redraw(mod.keys);d3.timer.flush();if(timer>60){mod.keys=mod.resetCount();timer=1}else{timer++}},1000);var w=20,h=80,width=w*mod.keys.length-1;height=h;var x=d3.scale.linear().domain([0,mod.keys.length]).range([0,w*mod.keys.length-1]);var y=d3.scale.linear().domain([0,d3.max(mod.keys,function(d){return d.n})]).rangeRound([0,h]);var chart3=d3.select(query).append("svg").attr("class","chart").attr("width",w*mod.keys.length-1).attr("height",h+16);chart3.append("line").attr("x1",0).attr("x2",w*mod.keys.length).attr("y1",h-0.5).attr("y2",h-0.5).style("stroke","#000");chart3.append("g").selectAll("text").data(mod.keys).enter().append("text").text(function(d){return d.lab}).attr("x",function(d,i){return x(i)+(w/2)-2}).attr("y",function(d){return h-y(d.n)+12});function redraw(data){y=d3.scale.linear().domain([0,d3.max(data,function(d){return d.n})]).rangeRound([0,h]);var rect=chart3.selectAll("rect").data(data);rect.enter().insert("rect","line").attr("x",function(d,i){return x(i)}).attr("y",h).attr("width",w).attr("height",function(d){return y(d.n)}).transition().duration(1000).attr("y",function(d){return h-y(d.n)});var text=chart3.selectAll(".num").data(data);text.enter().append("text").text(function(d){return d.n}).attr("class","num").attr("x",function(d,i){return x(i)+(w/2)-4}).attr("font-family","sans-serif").attr("font-size","11px").attr("fill","white");rect.transition().duration(function(d){if(d.n===0){return 50}else{return 100}}).attr("y",function(d,i){return h-y(d.n)}).attr("height",function(d){return y(d.n)});text.transition().duration(function(d){if(d.n===0){return 50}else{return 100}}).attr("y",function(d,i){if(d.n===0){return h-1}else{return h-y(d.n)+14}}).text(function(d){return d.n})}return mod}()).observe()}(function(d,script){script=d.createElement("script");script.type="text/javascript";script.async=true;script.onload=function(){(function(d,script){script=d.createElement("script");script.type="text/javascript";script.async=true;script.onload=function(){runViz()};script.src="http://cdnjs.cloudflare.com/ajax/libs/d3/3.4.1/d3.min.js";d.getElementsByTagName("head")[0].appendChild(script)}(document))};script.src="http://underscorejs.org/underscore-min.js";d.getElementsByTagName("head")[0].appendChild(script)}(document));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement