Created
September 13, 2009 16:40
-
-
Save savetheclocktower/186236 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Score Monitor | |
// @namespace http://andrewdupont.net/greasemonkey | |
// @description Monitors fantasy football scores. | |
// @include http://*.football.cbssports.com/scoring/live/* | |
// @author Andrew Dupont | |
// ==/UserScript== | |
(function () { | |
if (!window.fluid) return; | |
const TEAM_NAME = "The Shame-Hiding Paper Bags"; | |
function $(id) { | |
return document.getElementById(id); | |
} | |
function growl(title, description) { | |
window.fluid.showGrowlNotification({ | |
title: title, description: description || "", | |
sticky: false, priority: 0, identifier: "ffl", | |
onclick: activate | |
}); | |
} | |
function activate() { | |
window.fluid.activate(); | |
} | |
function marginToDockBadge(diff) { | |
if (diff === 0) return "tied"; | |
var str = diff > 0 ? "up " : "dn "; | |
str += Math.abs(diff); | |
return str; | |
} | |
function marginToGrowlDescription(diff) { | |
if (diff === 0) return "Score is tied!"; | |
var str = diff > 0 ? "Up by " : "Down by "; | |
str += Math.abs(diff); | |
return str; | |
} | |
// hide stupid annoying ad | |
$('contentEndRailRight').style.display = "none"; | |
document.querySelector("table.banner_bg").style.display = "none"; | |
// horizontal scrollbar is unnecessary | |
document.body.style.overflowX = "hidden"; | |
var $AWAY_SCORE = $('away_big_score'); | |
var $HOME_SCORE = $('home_big_score'); | |
var lastDiff; | |
function check() { | |
var isHome = $("home_big_name").innerHTML.indexOf(TEAM_NAME) > -1; | |
var away = window.parseInt($AWAY_SCORE.innerHTML, 10); | |
var home = window.parseInt($HOME_SCORE.innerHTML, 10); | |
var diff = isHome ? home - away : away - home; | |
if (diff != lastDiff && typeof lastDiff !== "undefined") { | |
growl("Score Update", marginToGrowlDescription(diff)); | |
} | |
window.fluid.dockBadge = marginToDockBadge(diff); | |
lastDiff = diff; | |
} | |
window.live_receive_flash_old = window.live_receive_flash; | |
window.live_receive_flash = function() { | |
var ret = window.live_receive_flash_old.apply(this, arguments); | |
check(); | |
return ret; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment