1/* js/common/sportConfig.js 2 Central place for every value that is *different* per sport. 3 Each wrapper simply passes its sport key ("nba" | "nfl" | "mlb"). 4----------------------------------------------------------------*/ 5const PB_GREEN = "rgba(45,224,186,.4)"; // mint 6const PB_YELLOW = "rgba(255,211,106,.18)"; // warm yellow 7const PB_RED = "rgba(255,101,119,.28)"; // soft red 8 9export const SPORT_CFG = { 10 nba : { 11 apiPrefix : "/nba", 12 teamMappings: window.TeamMappingsNBA, // already global 13 statList : ["PTS", "TRB", "AST", "3P", "BLK", "STL", "MP"], 14 displayName : { // table / chart headers 15 PTS: "Points", TRB: "Rebounds", AST: "Assists", 16 STL: "Steals", BLK: "Blocks", "3P": "3PM", 17 PRA: "PTS+RBS+AST", PR: "PTS+RBS", PA: "PTS+AST", RA: "RBS+AST", 18 }, 19 derivedMetrics(game) { 20 return { 21 PRA: (+game.PTS||0)+(+game.TRB||0)+(+game.AST||0), 22 PR : (+game.PTS||0)+(+game.TRB||0), 23 PA : (+game.PTS||0)+(+game.AST||0), 24 RA : (+game.TRB||0)+(+game.AST||0), 25 }; 26 }, 27 cellColor(col,val){ // used by table heatâmap 28 if (col==="MP") return val>=30?"#09b05c":val>24?"#FFDD22":"red"; 29 if (col==="PTS") return val>=20?"#09b05c":val>11?"#FFDD22":"red"; 30 if (col==="TRB") return val>=8 ?"#09b05c":val>4 ?"#FFDD22":"red"; 31 if (col==="AST") return val>=5 ?"#09b05c":val>2 ?"#FFDD22":"red"; 32 if (col==="3P") return val>=4 ?"#09b05c":val>2 ?"#FFDD22":"red"; 33 if (col==="BLK"||col==="STL") 34 return val>=2?"#09b05c":val===1?"#FFDD22":"red"; 35 return ""; 36 }, 37 }, 38 39 40 41 nfl : { 42 apiPrefix : "/nfl", 43 teamMappings: window.TeamMappingsNFL, 44 statList: [ 45 "PassingYards", "Completions", "ThrowingAttempts", 46 "PassingTDs", "Interceptions", 47 "RushingAttempts", "RushingYards", "RushingTDs" 48 ], 49 50 /* Labels â keep *everything* we might ever show so 51 we donât have to mutate this object later */ 52 displayName: { 53 PassingYards: "Pass Yds", 54 Completions: "Comp", 55 ThrowingAttempts:"Att", 56 PassingTDs: "Pass TD", 57 Interceptions: "INT", 58 RushingAttempts: "Rush Att", 59 RushingYards: "Rush Yds", 60 RushingTDs: "Rush TD", 61 Targets: "Targets", 62 Receptions: "Receptions", 63 ReceivingYards: "Rec Yds", 64 LongestReception:"Long Rec", 65 ReceivingTDs: "Rec TD" 66 }, 67 68 /* No derived metrics for NFL any more */ 69 derivedMetrics() { 70 return {}; 71 }, 72 73 74 cellColor(col, val) { 75 const pos = (window.currentPlayerPosition || "").toUpperCase(); 76 77 if (pos === "WR") { 78 if (col === "Targets") return val >= 8 ? PB_GREEN : val > 4 ? PB_YELLOW : PB_RED; 79 if (col === "Receptions") return val >= 8 ? PB_GREEN : val > 4 ? PB_YELLOW : PB_RED; 80 if (col === "ReceivingYards") return val >= 70 ? PB_GREEN : val > 39 ? PB_YELLOW : PB_RED; 81 } 82 83 if (pos === "QB") { 84 if (col === "ThrowingAttempts") return val >= 35 ? PB_GREEN : val > 24 ? PB_YELLOW : PB_RED; 85 if (col === "Completions") return val >= 20 ? PB_GREEN : val > 14 ? PB_YELLOW : PB_RED; 86 if (col === "PassingYards") return val >= 270 ? PB_GREEN : val > 199 ? PB_YELLOW : PB_RED; 87 if (col === "PassingTDs") return val >= 2 ? PB_GREEN : val == 1 ? PB_YELLOW : PB_RED; 88 if (col === "Interceptions") return val === 0 ? PB_GREEN : val === 1 ? PB_YELLOW : PB_RED; 89 90 if (col === "RushingAttempts") return val >= 5 ? PB_GREEN : val > 3 ? PB_YELLOW : PB_RED; 91 if (col === "RushingYards") return val >= 21 ? PB_GREEN : val > 11 ? PB_YELLOW : PB_RED; 92 if (col === "RushingTDs") return val >= 1 ? PB_GREEN : PB_RED; 93 } 94 95 if (col === "RushingAttempts") return val >= 15 ? PB_GREEN : val > 9 ? PB_YELLOW : PB_RED; 96 if (col === "RushingYards") return val >= 62 ? PB_GREEN : val > 39 ? PB_YELLOW : PB_RED; 97 if (col === "RushingTDs") return val >= 1 ? PB_GREEN : PB_RED; 98 99 if (col === "Targets") return val >= 5 ? PB_GREEN : val > 2 ? PB_YELLOW : PB_RED; 100 if (col === "Receptions") return val >= 4 ? PB_GREEN : val > 1 ? PB_YELLOW : PB_RED; 101 if (col === "ReceivingYards") return val >= 30 ? PB_GREEN : val > 18 ? PB_YELLOW : PB_RED; 102 if (col === "TD") return val >= 1 ? PB_GREEN : PB_RED; 103 104 return ""; 105 }, 106 107 108 }, 109 110 mlb : { 111 apiPrefix : "/mlb", 112 teamMappings: window.TeamMappingsMLB, 113 statList : ["H", "TB", "HR", "RBI", "R", "BB", "K", "2B", "3B", "SB"], 114 displayName : { 115 H: "Hits", TB: "Total Bases", HR: "HR", 116 RBI:"RBIs", R: "Runs", BB: "Walks", 117 K: "Ks", "2B":"Doubles", "3B":"Triples", 118 SB: "Stolen Bases", 119 }, 120 derivedMetrics() { return {}; }, 121 cellColor(col, val) { 122 if (col === "H") return val >= 2 ? PB_GREEN : val === 1 ? PB_YELLOW : PB_RED; 123 if (col === "TB") return val >= 3 ? PB_GREEN : val >= 1 ? PB_YELLOW : PB_RED; 124 if (col === "HR") return val >= 1 ? PB_GREEN : PB_RED; 125 if (col === "RBI") return val >= 2 ? PB_GREEN : val === 1 ? PB_YELLOW : PB_RED; 126 if (col === "R") return val >= 2 ? PB_GREEN : val === 1 ? PB_YELLOW : PB_RED; 127 if (col === "BB") return val >= 1 ? PB_GREEN : PB_RED; 128 if (col === "K") return val === 0 ? PB_GREEN : val === 1 ? PB_YELLOW : PB_RED; 129 if (col === "SB") return val >= 1 ? PB_GREEN : PB_RED; 130 return ""; 131 }, 132 }, 133 134}; 135
136/* Canonical URL-path â sport resolution. Replaces the scattered 137 `path.includes('/nba') ? 'NBA' : 'NFL'` ternaries for code paths that 138 support MLB (legacy NBA/NFL call sites keep their ternaries untouched). 139 Returns the UPPERCASE sport key the backend expects, or null off-sport. */ 140export function getSportFromPath(pathname) { 141 const p = (pathname !== undefined && pathname !== null 142 ? pathname 143 : (typeof location !== "undefined" ? location.pathname : "")).toLowerCase(); 144 if (/^\/mlb(\/|$)/.test(p)) return "MLB"; 145 if (/^\/nba(\/|$)/.test(p)) return "NBA"; 146 if (/^\/nfl(\/|$)/.test(p)) return "NFL"; 147 return null; 148} 149 150if (typeof window !== "undefined") { 151 window.SPORT_CFG = window.SPORT_CFG || {}; 152 window.SPORT_CFG.nba = SPORT_CFG.nba; 153 window.SPORT_CFG.nfl = SPORT_CFG.nfl; 154 window.SPORT_CFG.mlb = SPORT_CFG.mlb; 155 window.getSportFromPath = getSportFromPath; 156}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.