NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name Robin Vote Counter
// @namespace http://tampermonkey.net/
// @version 0.1
// @description count Robin votes with percentages
// @author fucking_weebs and errant_semicolon
// @match https://www.reddit.com/robin/*
// @grant none
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
/* jshint -W097 */
'use strict';
var updateCounter = function() {
var stay = 0,
grow = 0,
abandon = 0,
novote = 0,
sPct = 0,
gPct = 0,
aPct = 0,
abPct = 0,
total = 0;
;
var percentages = function(n1,n2){
p = (n1/n2) * 100
return p;
}
$("#robinUserList .robin-room-participant").each(function(i) {
var status = $(this).attr('class').match(/robin--vote-class--(.+)/)[1];
if(status == "novote") {
novote += 1;
total +=1;
} else if(status == "increase") {
grow += 1;
total +=1;
} else if(status == "continue") {
stay += 1;
total +=1;
} else if(status == "abandon") {
abandon += 1;
total +=1;
}
sPct = Math.round(percentages(stay,total));
gPct = Math.round(percentages(grow,total));
aPct = Math.round(percentages(abandon,total));
abPct = Math.round(percentages(novote, total));
});
$("#robinVoteWidget #content").html('');
$("#robinVoteWidget #content").append("<h3>Vote Counter<h3>");
$("#robinVoteWidget #content").append("Grow: " + grow + " // <em> " + gPct + "%</em> " + "<br />");
$("#robinVoteWidget #content").append("Abandon: " + abandon + " // <em> " + aPct + "%</em>" + "<br />");
$("#robinVoteWidget #content").append("Stay: " + stay + " //<em> " + sPct + "%</em>" + "<br />");
$("#robinVoteWidget #content").append("Abstaining: " + novote + " //<em> " + abPct + "%</em>" + "<br />");
$("#robinVoteWidget #content").append("Total " + total + "<br />");
}
$(document).ready(function() {
$("#robinVoteWidget").append("<div id='counter'></div>");
$("#robinVoteWidget #counter").append("<div id='content'></div>");
$("#robinVoteWidget #content").css("width", "150px");
$("#robinVoteWidget #counter").append("<button>Refresh Counter</button>");
$("#counter").css("margin", "0 auto");
$("#counter").css("width", "300px");
$("#content").css("float", "left");
$("#counter button").css("margin", "0 auto");
$("#counter button").css("float", "right");
$("#counter button").css("width", "75px");
$("#counter button").css("top", "0px");
$("#counter").css("font-size", "13px");
$("#counter button").click(updateCounter);
updateCounter();
});