Skip to content

Instantly share code, notes, and snippets.

@azpat
Last active October 19, 2018 00:16
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 azpat/d2de3510744864416dfff88c651de96a to your computer and use it in GitHub Desktop.
Save azpat/d2de3510744864416dfff88c651de96a to your computer and use it in GitHub Desktop.
NBArizona UserScript for Greasemonkey/Tampermonkey to replace NBA Team Names with Arizona Wildcat Alumni 2018-19 Season
// ==UserScript==
// @name NBArizona
// @description Changes Names of NBA team on NBA Schedule Site to represent the Wildcats on that team
// @version 1.0
// @namespace
// @include http://www.espn.com/nba/schedule/*
// @run-at document-end
// ==/UserScript==
// ctrl+f "var replacements"
// stolen from here: https://github.com/boxmein/word-to-word/raw/master/userscript/script.user.js
// just a mash together of userscript stuff and cloud-to-butt stuff
// http://wiki.greasespot.net/Content_Script_Injection
function contentEval(source) {
if ('function' == typeof source) {
source = '(' + source + ')();'
}
var script = document.createElement('script');
script.setAttribute("type", "application/javascript");
script.textContent = source;
document.body.appendChild(script);
document.body.removeChild(script);
}
contentEval(function() {
var replacements = [
// a list of objects with keys from and to, signifying what to find and what
// to replace the string to
// the from key can also be a Javascript compatible (perl compatible) regex
// {"from": "cloud", "to": "butt" },
{"from": /(Chicago|Bulls)/ig, "to": "Lauri Markkanen (24) and Rawle Alkins (20)" }
,{"from": /(Phoenix|Suns)/ig, "to": "Deandre Ayton (22)" }
,{"from": /(Philadelphia|76ers)/ig, "to": "T.J. McConnell (12) and Jerryd Bayless (0)" }
,{"from": /(Cleveland|Cavaliers)/ig, "to": "Channing Frye (9)" }
,{"from": /(Orlando|Magic)/ig, "to": "Aaron Gordon (00)" }
,{"from": /(New Orleans|Pelicans)/ig, "to": "Solomon Hill (44)" }
,{"from": /(Brooklyn|Nets)/ig, "to": "Rondae Hollis-Jefferson (24)" }
,{"from": /(Golden State|Warriors)/ig, "to": "Steve Kerr (Coach) and Andre Iguodala (9)" }
,{"from": /(Detroit|Pistons)/ig, "to": "Stanley Johnson (7)" }
,{"from": /(New York|Knicks)/ig, "to": "Allonzo Trier (14)" }
,{"from": /(Los Angeles|Lakers)/ig, "to": "Luke Walton (Coach) and Miles Simon (Coach)" }
];
// I stole this 101% from https://github.com/panicsteve/cloud-to-butt/blob/master/Source/content_script.js
function walk(node)
{
// I stole this function from here:
// http://is.gd/mwZp7E
var child, next;
switch ( node.nodeType )
{
case 1: // Element
case 9: // Document
case 11: // Document fragment
child = node.firstChild;
while ( child )
{
next = child.nextSibling;
walk(child);
child = next;
}
break;
case 3: // Text node
handleText(node);
break;
}
}
function handleText(textNode)
{
var v = textNode.nodeValue;
for (var i=0, r=replacements; i<r.length; i++) {
v = v.replace(r[i].from, r[i].to);
}
textNode.nodeValue = v;
}
// notifying any stronger would be disastrously annoying
if (replacements.length == 0) {
console.log('Configure replacements in script source code');
}
walk(document.body, handleText);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment