Whirlpool Ratings Count

By Johnny Bravo Last update Dec 1, 2007 — Installed 218 times.
// ==UserScript==
// @name		Ratings Count
// @namespace	forums.whirlpool.net.au
// @version		0.9
// @description	Shows ratings counts
// @include		http://forums.whirlpool.net.au/forum-user-yourvotes.cfm
// ==/UserScript==

var xp = "//DIV[@class='voteblock']/SPAN";
var xa = "[@class='voteactive']";
var xc = "[@class='votecrusty']";

var active=[];
var crusty=[];
var total=[];

active[0] = document.evaluate(xp+'[1]'+xa, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null ).snapshotLength; 
active[1] = document.evaluate(xp+'[2]'+xa, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null ).snapshotLength; 
active[2] = document.evaluate(xp+'[3]'+xa, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null ).snapshotLength; 
active[3] = document.evaluate(xp+'[4]'+xa, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null ).snapshotLength; 
crusty[0] = document.evaluate(xp+'[1]'+xc, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null ).snapshotLength; 
crusty[1] = document.evaluate(xp+'[2]'+xc, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null ).snapshotLength; 
crusty[2] = document.evaluate(xp+'[3]'+xc, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null ).snapshotLength; 
crusty[3] = document.evaluate(xp+'[4]'+xc, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null ).snapshotLength; 

for(var i=0; i < 4; i++) total[i] = active[i]+crusty[i];

var tableBody = document.evaluate('//TD[@class="pageforum"]/BLOCKQUOTE/TABLE/TBODY',document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;
var tfoot = tableBody.parentNode.appendChild(document.createElement('TFOOT'));
var newRow;
var lft;
var rgt;
var tb=["Irritating Scum", "Typical", "Constructive", "Top Person" ];

function makeRow(vals, hd, bg) {
  var newRow = tfoot.appendChild(document.createElement('TR'));
  newRow.style.backgroundColor = bg;
  var lft = newRow.appendChild(document.createElement('TD'));
  lft.setAttribute('colspan', '2');
  lft.style.textAlign = 'center';
  lft.appendChild(document.createTextNode(hd));

  vals.forEach(function(n, i, a) {
    var newRow = tfoot.appendChild(document.createElement('TR'));
    newRow.style.backgroundColor = bg;
    var lft = newRow.appendChild(document.createElement('TD'));
    var rgt = newRow.appendChild(document.createElement('TD'));
    rgt.style.textAlign='right';
    lft.appendChild(document.createTextNode(tb[i]));
    rgt.appendChild(document.createTextNode(n));
  });
}

makeRow(active, 'Active Ratings', '#ffffee');
makeRow(crusty, 'Crusty Ratings', '#ffeebb');
makeRow(total,  'Total Ratings', '#bbbbff');