Skip to content

Instantly share code, notes, and snippets.

@joshwilsonnc
Last active May 18, 2016 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshwilsonnc/36311178c40a056dbf21 to your computer and use it in GitHub Desktop.
Save joshwilsonnc/36311178c40a056dbf21 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name FanGraphs Player Name Hider
// @namespace http://joshwilson.net/gmscripts
// @author jw@joshwilson.net
// @include http://www.fangraphs.com/leaders.aspx*
// @grant none
// @version 1.0
// ==/UserScript==
///////////////////////////////////////////////////////////////////////////////
/**
* Hides player names and teams on FanGraphs leaderboards so you can assess stats
* without name-recognition influences. You can click to reveal and or all names.
*/
//Grab all the data rows, hide the player name and team in each
var allRows = new Array(2);
allRows[0] = document.getElementsByClassName("rgRow");
allRows[1] = document.getElementsByClassName("rgAltRow");
var nameNode, teamNode;
var idCounter=1;
for (var i=0; i<allRows.length; i++) {
for (var n=0; n<allRows[i].length; n++) {
try {
nameNode = allRows[i][n].childNodes[2];
teamNode = allRows[i][n].childNodes[3];
newNameElem = makeFanGraphsLeadersElem("name", nameNode.textContent, idCounter);
newTeamElem = makeFanGraphsLeadersElem("team", teamNode.textContent, idCounter);
allRows[i][n].replaceChild(newNameElem, nameNode);
allRows[i][n].replaceChild(newTeamElem, teamNode);
idCounter++;
} catch(e) {}
}
}
//Add a link to reveal all data
var displayElem = document.getElementsByClassName("br_dby");
var revealAllElem = document.createElement("span");
revealAllElem.setAttribute("onclick", "try{var hiddenElems=document.getElementsByClassName('hidden-data');for (e in hiddenElems){hiddenElems[e].textContent=hiddenElems[e].getAttribute('actual-data')};}catch(err){}");
revealAllElem.appendChild(document.createTextNode(" | Reveal All Data (click individual names/teams to reveal)"));
displayElem[0].childNodes[1].appendChild(revealAllElem);
//Creates the hidden data elements
function makeFanGraphsLeadersElem(uid, data, idCounter) {
var newElem = document.createElement("td");
newElem.setAttribute("class","grid_line_regular");
var revealElem = document.createElement("span");
revealElem.setAttribute("id", "hidden-" + uid + "-" + idCounter);
revealElem.setAttribute("class", "hidden-data");
revealElem.setAttribute("actual-data", data);
revealElem.setAttribute("onclick", "this.textContent='" + data + "'");
revealElem.appendChild(document.createTextNode("CLICK TO REVEAL"));
newElem.appendChild(revealElem);
return newElem;
}
@joshwilsonnc
Copy link
Author

joshwilsonnc commented Sep 30, 2014

Never be biased again! Hides player names and teams on FanGraphs leaderboards so you can assess stats without being influenced by name recognition. You can click to reveal individual names/teams, or use the "Reveal All Data" link to see all the names again.

Hey, look a screenshot! https://www.dropbox.com/s/9qw86mrp5jw0hhl/fangraphs_name_hider.jpg?dl=0

This is a user script for GreaseMonkey (Firefox) or Tampermonkey (Chrome) (I have not tested GreaseKit for Safari, but I understand that works the same). To use it, install GreaseMonkey or Tampermonkey, then click the "Raw" button above and confirm to install.

Quick and dirty work done here, I'm happy to hear suggestions on functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment