Yahoo Fantasy Player Search

Last update on Sep 7, 2007

Adds player search box to sub navigation if it doesn't already exist on the page

I liked this player search script, but I wanted it at the top of the page and on more pages.

This script adds it to the end of the subnavigation links if there's not already a player search on the page.

Updates:
25-May-2007: Added check for sub-navigation which isn't there when viewing other owners' team rosters
29-May-2007 - Changed include path to allow http://beta.
06-Sep-2007 - Tweaked to work on sites other than baseball
06-Sep-2007 - Fixed to work with hockey

Was this script helpful? Feeling generous? Buy my lunch today! Make a donation

Screenshot:




You could comment on this script if you were logged in.

14 comments Feed-icon

1 point
login to vote
Posted Aug 9, 2008

hey glenn i know my question has nothing to do with this script but i couldnt find your email anywhere

so i was wondering if you could create this script except for baseball it is a bench all players without a game script

http://userscripts.org/scripts/show/6716

that is the script link

and here is the actual script

// ==UserScript==
// @name Yahoo Fantasy NBA Bench All
// @namespace http://mattandchristy.net/benchall
// @description Provides a button to bench all players without a game
// @include http://basketball.fantasysports.yahoo.com/nba/*...=*
// @include http://basketball.fantasysports.yahoo.com/nba/*...
// ==/UserScript==
//
// Change log:
// 2006-12-10 Initial version of script; used Yahoo Fantasy NBA Game Log Link
// as a base to start developing

var doBench = function(event) {

var allElements;
var thisElement;
var playerLink = "http://sports.yahoo.com/nba/players/"
var gameLogLink;


allElements = document.evaluate(
"//*[contains(@class, 'player')]/..",
document,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null);

// burn the first two rows; they are headers, not players
for (var i = 2; i < allElements.snapshotLength; i++) {

thisElement = allElements.snapshotItem(i);

tds = thisElement.getElementsByTagName('td');
nameNode = tds[1];
if(nameNode) {
// td div a textnode value
name = nameNode.firstChild.firstChild.firstChild.nodeValue;

// get the opponent TD's innerHTML; text node won't work because
// the ? for 'no opponent' gets translated to a character =/
opp = tds[3].innerHTML;

if(opp == '?') {

newPosSelectNode = tds[2].firstChild;
// select the 'BN' node for these guys (last option)
newPosSelectNode.selectedIndex = newPosSelectNode.length-1;

GM_log("Benching " + name);
}
}
}

// stop event propagation, if this was a click
if(event) {
event.stopPropagation();
event.preventDefault();
}
}

/* gameLogLink = document.createElement('a'); */
/* gameLogLink.setAttribute("href",thisElement.href + "/gamelog") */
/* //gameLogLink.setAttribute("class","cellindent") */
/* gameLogLink.setAttribute("target","_blank") */
/* gameLogLink.setAttribute("title","game log link") */
/* gameLogLink.innerHTML = "" */
/* thisElement.parentNode.insertBefore(gameLogLink, thisElement.nextSibling.nextSibling); */

var BENCHBUTTON_ID = "bencherButton";
var BENCHBUTTON_TEXT = "[Bench players with no game]";

// create the bench button
var bencher = document.createElement("A");
bencher.addEventListener("click", doBench, true);
bencher.href = "#";
bencher.innerHTML = BENCHBUTTON_TEXT;
bencher.className = 'button';
/* bencher.style.backgroundColor = "#D8D9D5"; */
/* bencher.style.borderTopColor = "#A8A8A8"; */
/* bencher.style.borderBottomColor = "#A8A8A8"; */
/* bencher.style.borderLeftColor = "#A8A8A8"; */
/* bencher.style.borderRightColor = "#A8A8A8"; */
/* bencher.style.borderTopStyle = "outset"; */
/* bencher.style.borderBottomStyle = "outset"; */
/* bencher.style.borderLeftStyle = "outset"; */
/* bencher.style.borderRightStyle = "outset"; */
/* bencher.style.borderTopWidth = "1px"; */
/* bencher.style.borderBottomWidth = "1px"; */
/* bencher.style.borderLeftWidth = "1px"; */
/* bencher.style.borderRightWidth = "1px"; */
bencher.style.paddingTop = "2px";
bencher.style.paddingBottom = "5px";
bencher.style.paddingLeft = "5px";
bencher.style.paddingRight = "5px";
bencher.style.color = "#FFFFFF";
bencher.id = BENCHBUTTON_ID;

// attach the bench button right before the "submit changes" button
// at the bottom of the screen
var buttonBar = document.getElementById('buttonbar');
var inputs = buttonBar.getElementsByTagName('input');
var submitButton = inputs[inputs.length-1]
buttonBar.insertBefore(bencher, submitButton);

i tried to mess around with it a little bit but got no luck

please respond soon

i will post this on a couple other pages to ensure that you get the message

Aaron S

1 point
login to vote
Tim Wilson scriptwright
Posted Sep 20, 2007

Oh, and it didn't work for NBA. I changed the line where you are comparing for hockey to the following:

      if ( /^my team/i.test( atext ) && (/\/([a-z]\d|hockey)\/\d+\/\d+/i.test( a.href ) || /\/([a-z]\d|nba)\/\d+\/\d+/i.test( a.href ) ) )
      

1 point
login to vote
Tim Wilson scriptwright
Posted Sep 19, 2007

Ok, guess I gotta do this the hard way. One last time:

Add this line between the form and input tags:

      <label for="playersearchtext" accesskey="s"> </label>\
      

1 point
login to vote
Tim Wilson scriptwright
Posted Sep 19, 2007

I never can post code correctly in this system. (sure do wish there was a preview button!)

Let me try this again. Add this line between the form and input tags:

      <label> </label>\
      

1 point
login to vote
Tim Wilson scriptwright
Posted Sep 19, 2007

Hey Glenn, I added an accesskey to the original script, so you can hit Shift-Alt-S to go to player search. Maybe you could add it to this script too? Here's what you need:
Add this line between the form and input tags:

<label> </label>\

And add 'id="playersearchtext"' to the input box tag.

You might recall I created a script (http://userscripts.org/scripts/show/7938) to always focus the regular player search box. I found this annoying when I was trying to arrow down through the list, as it was arrowing down through my previous searches instead. So I added an accesskey to that script. Then I decided to add it to the original of this script. Now that I've found your consolidated script, I've added it to that one too!

1 point
login to vote
Glenn Carr script's author
Posted Sep 11, 2007

'salright. Buy my lunch and I'll forgive the 'genius' comment. ;)

1 point
login to vote
LooGie user
Posted Sep 10, 2007

and btw, nevermind my idea of having both boxes. it was stupid anyway :) i uninstalled the other one, and went w/ yours. works perfect too!

1 point
login to vote
LooGie user
Posted Sep 10, 2007

oh, haha, sorry, i see now that you are actually the author. didn't need any disrespect. i like you script. i thought you were someone just f'ing with me. sorry about the "genius" comment...

1 point
login to vote
LooGie user
Posted Sep 10, 2007

um, no genius, it doesn't add any functionality, my beef is with having to scroll up, or down to the scroll box. That's the same reason the author made this script, because he wanted it at the top, instead of having to scroll down...well, i dont want to scroll down, or up. if i'm at the bottom, i wanna search from the bottom, if the top..you get the idea..

1 point
login to vote
Glenn Carr script's author
Posted Sep 6, 2007

It purposely won't add a search box, if one already exists on the page. I'm not sure why I (or anyone) would want to use both? Does the other one provide something that this one doesn't?

1 point
login to vote
LooGie user
Posted Sep 6, 2007

Yah, works good, but it doesn't work with the other search player script. You should really add that script to your script, so both search boxes are there. Or at least make them work together...

1 point
login to vote
Glenn Carr script's author
Posted May 29, 2007

previous post: was == wasn't

1 point
login to vote
Glenn Carr script's author
Posted May 29, 2007

Cool. Actually, it was meant to be centered, it just shows up after the last link in the sub navigation area.

1 point
login to vote
jk- scriptwright
Posted May 26, 2007

cool, it was a little too small for me unfocused so I doubled the pixel widths and added some css to center it over the green row (it was off-center with 1440 res.).

You could comment on this script if you were logged in.