Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Reddit: The button: The stat chart
- // @version 0.1
- // @description button stat tracker 9001
- // @author /u/tcghyit
- // @match http://www.reddit.com/r/thebutton*
- // @grant none
- // @require http://canvasjs.com/assets/script/canvasjs.min.js
- // ==/UserScript==
- console.log('Button chart')
- var dps = []; // dataPoints
- var el = document.createElement("div");
- el.id = "chartContainer";
- el.style.width="100%";
- el.style.height= "350px";
- el.style.clear= "both";
- var theButton = document.getElementsByClassName('thebutton-form')[0];
- theButton.appendChild(el);
- var chart = new CanvasJS.Chart("chartContainer",{
- title :{
- text: "Button Presses"
- },
- legend:{
- verticalAlign: "top",
- horizontalAlign: "centre",
- fontSize: 18,
- },
- axisY: {
- title: "# of clicks"
- },
- data: [{
- type: "line",
- xValueType: "dateTime",
- dataPoints: dps,
- showInLegend: true,
- legendMarkerType: "square",
- legendMarkerBorderThickness: 5,
- legendMarkerBorderColor: "white",
- legendMarkerColor: "white",
- legendText: "Lowest recorded time left: 60"
- }]
- });
- var updateInterval = 1000;
- var dataLength = 300; // number of dataPoints visible at any point
- var participants;
- var partEl = document.getElementsByClassName('thebutton-participants')[0];
- var oldParticipants = 0;
- var lowestMS = 60000;
- var updateChart = function (count) {
- participants = parseInt(partEl.innerHTML.replace(/,/, ''));
- dps.push({
- x: new Date().getTime(),
- y: (participants-(oldParticipants||participants)),
- toolTipContent: "<span style='\"'color: blue;'\"'>{x}</span>: {y} people clicked"
- });
- oldParticipants = participants;
- //delete excess data
- if (dps.length > dataLength)
- {
- dps.shift();
- }
- var msLeft = r.thebutton._msLeft;
- if(lowestMS>msLeft && msLeft!=0) {
- lowestMS=msLeft;
- chart.options.data[0].legendText = "Lowest recorded time left: "+(lowestMS/1000);
- }
- chart.render();
- };
- // update chart after specified time.
- $(document).ready(function(){
- setInterval(function(){updateChart()}, updateInterval);
- });
Add Comment
Please, Sign In to add comment