2

The Backstory: I am looking to improve a Fantasy Football webpage by adding stats of the players in real-time. Let's assume we are using this page as a reference. For each player, it lists the position they play (i.e. QB, WR, etc) and also the team they play against.

My Current Code: @BrockAdams answered my question yesterday and was able to assemble a table that contained the team name, position, and the rank. Here is a sample of the table:

enter image description here

What I am looking to accomplish is lookup the rank in the table based on the opposing team and my players position and add it to the end of the string.

What I Have Done: The string that contains my players position can be found using document.querySelectorAll('span[class="Fz-xxs"]')[#].innerText.split(" - ").slice(-1)[0] where # is between 0 and 33

The string that contains the opponents team can be found using document.querySelectorAll('a[class="F-reset"]')[#].innerText.split(" ").slice(-1)[0] where # is once again between 0 and 33

The Problem: What my question is, how can I modify my script to append the rank # to the end of the string based on my players position and the opposing team?

A small issue I found is that anytime a user loads the fantasy page, my script will re-fetch all the teams position + ranks even though they only change once a week. Is there a good method to store the values in the browser and have it update only once a week?


Here is a picture of what the final result should look like. This was from a script created last year but because Yahoo modified their site, the old script no longer works.

enter image description here

Edit: Here is a portion of the existing HTML code.

<td class="Ta-start player Ta-start Bdrx">
    <div class="Ov-h Mx-a">
        <div>
            <div class="Grid-bind-end">
                <span class="player-status Grid-u Lh-xs">
                    <a id="playernote-25718" href="http://sports.yahoo.com/nfl/players/25718/news" target="sports" class="playernote Ta-start yfa-icon Z-1 playernote-recent"><span class="ysf-player-icon ysf-player-icon-notes yfa-icon playernote-recent" title="Player notes">Player Note</span></a>
                </span>
                <div class="ysf-player-name Nowrap Grid-u Relative Lh-xs Ta-start"><a class="Nowrap" href="http://sports.yahoo.com/nfl/players/25718" target="sports">R. Tannehill</a> <span class="Fz-xxs">Mia - QB</span> </div>
            </div>
            <div class="Grid-bind-end">
                <span class="ysf-player-status F-injury Fz-xxs Grid-u Lh-xs"></span>
                <div class="ysf-player-detail Nowrap Grid-u Fz-xxs Lh-xs Ta-start"><span class="ysf-game-status "><a class="F-reset" href=".../miami-dolphins-washington-redskins.../" target="sports" onclick="pop(this)">Sun 10:00 am @ Was</a></span></div>
            </div>
        </div>
    </div>
</td>

The only modification the code will make will be to change Sun 10:00 am @ Was to Sun 10:00 am @ Was - 1 for example. The screenshot above should make it clear. The page it will be modifying is This one.

Edit2: I made a small version in jsFiddle but I am having trouble appending this to the greasemonkey script Brock created.

Community
  • 1
  • 1
Bijan
  • 7,737
  • 18
  • 89
  • 149
  • That picture is not clear as to what was changed. Edit the Q to show the *current, relevant* HTML snippet and then the *desired* HTML snippet. Also add freehand circles to the image, around the modified bits. ... Keep in mind that Stack Overflow is not a script writing service and I don't yet see how to edit (most of) this question to make it of general use to future users. – Brock Adams Sep 02 '15 at 18:49
  • For the persistent data part, see questions like [*Store a persistent list between sessions?*](http://stackoverflow.com/questions/16682150/store-a-persistent-list-between-sessions). – Brock Adams Sep 02 '15 at 18:54
  • @BrockAdams: Screenshot was fixed to show change. I also added the relevant code and a link to the webpage it will be modifying. I am not sure how this specific question will apply to future users but essentially I am modifying an element on a page based on 2 conditions (players position and opposing team) – Bijan Sep 02 '15 at 18:59
  • @BrockAdams: Please see latest update. I was able to create a small version of the site and I showed what I did to append the rank # to end of string. – Bijan Sep 02 '15 at 22:12
  • Good, but that fiddle doesn't work for me (`.innerText` is undefined). Anyway, I'm not going to look at this project for the next many hours. But, If you can formulate the question more into something that looks to be of general use to future users, then you should get more people trying to answer it. – Brock Adams Sep 02 '15 at 22:35
  • Okay. I think the thing I am having most trouble with is the array. Could you give me a quick modification that has a single array in format of: `TeamName, #, #, #, #, #, 3`? Right now you have them separated and its confusing. – Bijan Sep 02 '15 at 22:41
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/88639/discussion-between-bijan-and-brock-adams). – Bijan Sep 03 '15 at 00:44
  • @BrockAdams: Please take a look at my [final code](http://codereview.stackexchange.com/questions/103735/greasemonkey-fantasy-football-script) – Bijan Sep 04 '15 at 02:07
  • Dude, [that's not how Stack Exchange sites work](http://meta.stackoverflow.com/a/258279). I'm happy to help but, like most answerers, I respond to questions in my spare time for my own reasons. Also, if an SE question is formulated well, it doesn't rely on any one user to answer it. Finally, it looks like you got the script fully operational. That's great! Instead of waiting for me, try using that same drive to experiment if you feel it can be better. PS: I might still take a look, but I'm currently swamped at work and at home, it may be a while, or never. Some Q's in my list are years old. – Brock Adams Sep 04 '15 at 04:38
  • Also, since you got the script working, try crystallization the lessons learned into an answer for this question that might help future users. You can answer your own Q and it seems you have found at least some kind of solution to this question. – Brock Adams Sep 04 '15 at 04:42
  • @BrockAdams: Sorry about that. I asked for your help because you were a big help in a similar project last year and your code worked very efficiently – Bijan Sep 04 '15 at 05:10
  • Glad I was helpful before too. Note that there is no need to ask for fresh help from me, or most people here, by name (and many take offense at such). If it's in one of the tags I watch, I get emailed about every question (unless it already has a negative score within about 20 minutes of it being created). If a Q interests me, I'll respond *IF* I have the time and an idea about how to answer. – Brock Adams Sep 04 '15 at 05:25
  • Understandable. Well thanks for the help! If you ever decide to look at the question, I am all ears :) The one last year yielded ~150K+ installs and this one is already at 5K – Bijan Sep 04 '15 at 05:43

0 Answers0