Skip to content

Instantly share code, notes, and snippets.

@lyoshenka
Last active December 23, 2015 03:49
Show Gist options
  • Save lyoshenka/6576028 to your computer and use it in GitHub Desktop.
Save lyoshenka/6576028 to your computer and use it in GitHub Desktop.
Count the total length of all the player names on my ESPN fantasy football team
jQuery(function(){
var regex = new RegExp("[^A-Za-z0-9]+",'g'),
playerNameSelector = 'td.playertablePlayerName a:first-child',
teamAId = '#playertable_0',
teamBId = jQuery('#playertable_6').length ? '#playertable_6' : '#playertable_1',
teamA = jQuery(teamAId)
.closest('div')
.find(playerNameSelector)
.filter(function(){ return jQuery(this).closest('.hideableGroup').length === 0 && jQuery(this).text().length > 0; }),
teamAPlayers = teamA.length,
teamALength = teamA.text().replace(regex,'').length,
teamB = jQuery(teamBId)
.closest('div')
.find(playerNameSelector)
.filter(function(){ return jQuery(this).closest('.hideableGroup').length === 0 && jQuery(this).text().length > 0; })
teamBPlayers = teamB.length,
teamBLength = teamB.text().replace(regex,'').length
;
alert(
jQuery(teamAId+' .playertableTableHeader').text().replace(' Box Score','') + ": " +
teamALength + '/' + teamAPlayers + ' = ' + (teamALength/teamAPlayers)
+ "\n" +
jQuery(teamBId+' .playertableTableHeader').text().replace(' Box Score','') + ": " +
teamBLength + '/' + teamBPlayers + ' = ' + (teamBLength/teamBPlayers)
);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment