Whirlpool Ratings Count Ex

By Johnny Bravo Last update Feb 11, 2008 — Installed 196 times.
// ==UserScript==
// @name		Ratings Count Ex
// @namespace	forums.whirlpool.net.au
// @version		0.9.1
// @description	Shows ratings counts
// @include		http://forums.whirlpool.net.au/forum-user-yourvotes.cfm
// ==/UserScript==

var self=document.evaluate('//DIV[@class="nav_item_name"]/A[contains(@href, "forum-user.cfm?id=")]', 
         document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue;
var numSelf=-1;
if(self) {
  var srch='forum-user.cfm?id=';
  numSelf=parseInt(self.href.substr(self.href.indexOf(srch)+srch.length));
}
var preURL='http://forums.whirlpool.net.au/forum-replies-uservote.cfm?x='+numSelf+'&s=0&u=';

var allChecks = [];

var allVotes = document.evaluate("//TR[TD[DIV[@class='voteblock']]]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null );
var tblHead =  document.evaluate("//TR[TH]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue;
var newCol = document.createElement('TH');
newCol.appendChild(document.createTextNode('Clear'));
tblHead.appendChild(newCol);
for(var i=0; i < allVotes.snapshotLength; i++) {
  var vote=allVotes.snapshotItem(i);
  var spans=vote.getElementsByTagName('SPAN');
  var linky = document.evaluate("./TD/A", vote, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue;
  var newCol = document.createElement('TD');
  newCol.style.textAlign='center';
  var chk = newCol.appendChild(document.createElement('INPUT'));
  chk.type='checkbox';
  chk.selected=false;
  chk.name='gm_u_'+linky.href.substr(linky.href.indexOf('id=')+3);
  chk.id=chk.name;
  for(var j=0; j < spans.length; j++) {
    if (spans[j].className != 'voteitem') {
      var n = j+1;
      chk.className=spans[j].className.substr(4)+'_'+n;
      break;
    }
  }
  allChecks[i] = chk;
  vote.appendChild(newCol);
}
var active=[];
var crusty=[];
var total=[];

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

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

for(var i=0; i < 5; i++) total[i] = 0;
for(var i=1; i < 5; i++) {
  total[i] = active[i]+crusty[i];
  active[0] += active[i];
  crusty[0] += crusty[i];
  total[0] += total[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=["Total", "Irritating Scum", "Typical", "Constructive", "Top Person"];

function doMassCheckbox(e) {
  var el=e.target;
  var ar=el.name.split('_');
  var age=ar[1];
  var lvl=parseInt(ar[2]);
  var ageLvl = (age=='any'?'':age)+'_'+lvl;
  allChecks.forEach(function(theEl, i, a) {
    if(age == 'any') {
      if(lvl && theEl.className.indexOf(ageLvl) > 0) {
        theEl.checked = el.checked;
      }
      else if (lvl == 0) {
        theEl.checked = el.checked;
      }
    }
    else {
      if(lvl && theEl.className == ageLvl) {
        theEl.checked = el.checked;
      }
      else if (lvl == 0 && theEl.className.indexOf(age+'_') == 0) {
        theEl.checked = el.checked;
      }
    }
  });
}

function makeRow(vals, hd, bg, typ) {
  var newRow = tfoot.appendChild(document.createElement('TR'));
  newRow.style.backgroundColor = bg;
  var lft = newRow.appendChild(document.createElement('TD'));
  lft.setAttribute('colspan', '3');
  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));

    var newCol = document.createElement('TD');
    newCol.style.textAlign='center';
    var btn = newCol.appendChild(document.createElement('INPUT'));
    btn.selected=false;
    btn.type = 'checkbox';
    btn.name = 'gmb_'+typ+'_'+i;
    btn.id = btn.name;
    btn.addEventListener('click', doMassCheckbox, false);
    newRow.appendChild(newCol);
  });
}

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

var newRow = tfoot.appendChild(document.createElement('TR'));
newRow.style.backgroundColor = "#eeeeee";
var lft = newRow.appendChild(document.createElement('TD'));
lft.setAttribute('colspan', '3');
lft.style.textAlign = 'center';
var btn = lft.appendChild(document.createElement('INPUT'));
btn.type = 'button';
btn.name = 'gm_submit';
btn.id = btn.name;
btn.value='Sumbit Reset';
btn.addEventListener('click', function() {
  allChecks.forEach(function(theEl, i, a) {
    if(theEl.checked) {
      var unum=theEl.name.split('_')[2];
    GM_xmlhttpRequest( {
      method:"GET",
      url:preURL+unum,
      headers: {
        "User-Agent":"Mozilla/5.0 Gecko",
        "Accept":"text/html,text/xml,text/plain"
      },
      onload: function(resp) {
      }
    });
    }
  });
  return;
}, false);