NFL.com BorisChenTiers

This script adds a row to the team and player page in NFL.com Football Fantasy website with the boris chen tier

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name     NFL.com BorisChenTiers
// @description This script adds a row to the team and player page in NFL.com Football Fantasy website with the boris chen tier
// @version  1.5
// @grant         GM.xmlHttpRequest
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js 
// @require https://greasyfork.org/scripts/31940-waitforkeyelements/code/waitForKeyElements.js?version=209282
// @require https://greasyfork.org/scripts/431916-borischentiers/code/BorisChenTiers.js?version=968797
// @include https://*fantasy.nfl.com/league/*/team/*
// @exclude https://*fantasy.nfl.com/league/*/team/*/gamecenter*
// @include https://*fantasy.nfl.com/league/*/players
// @namespace https://greasyfork.org/users/812226
// ==/UserScript==

(async () => {  
  const tierMap = await generateTiers(scoring.Standard);
  
  console.log(tierMap);

  waitForKeyElements (
    ".tableType-player", 
    (jNode) => {
      appendDataToTable(jNode, tierMap, true);
    }
  );  
})();

const appendDataToTable = (jNode, data, addHeader) => {  
  const rows = jNode.children().find('tr');
    
  
  rows.each((index, obj) => {
    if (index == 0) {
      
    } else if (index == 1) {
      if (addHeader) {
				$($($(obj).children()).eq(1)).after(createNFLStyledHeaderWithSelect('BorisChen Tier'));
      
        $('#Tier-ScoringSelect').on('change', async function() {
          const tierMap = await generateTiers(scoring[this.value]);

          appendDataToTable($(".tableType-player"), tierMap, false);
        });
      }
    } else {
      let tier = '-';
      const name = getName(obj);
      
      if (data[name] !== null && data[name] !== undefined) {
        tier = data[name] + 1;
      } else {
        console.log("could not match this player: " + name);
      }
      
      if ($(obj).find("#BorisChenTier").length > 0) {
        $(obj).find("#BorisChenTier").text(tier);
      } else {
        $($($(obj).children()).eq(1)).after(createTierCol(tier));
      }
    }
  });
};

const createNFLStyledHeaderWithSelect = (title) => {
 return `<th class="BorisChenTierHeader">
          ${title}
          <select name="Tier-ScoringSelect" id="Tier-ScoringSelect">
            <option value="Standard">Std</option>
            <option value="PPR">PPR</option>
            <option value="Half">Half</option>
          </select>
				</th>`
};

const createNFLStyledHeader = (title) => {
 return `<th class="BorisChenTierHeader">
					${title}
				</th>`
};

const createTierCol = (tier) => {
	return `<td id="BorisChenTier"
							class="playerOpponent">
						<span>${tier}</span>
					</td>`; 
};

const getName = (jQueryNode) => {  
  const name = $($(jQueryNode).find('.playerNameFull')).text();
    
  return santizeString(name);
};