Skip to content

Commit

Permalink
Assign away kits based on the next fixture to be played
Browse files Browse the repository at this point in the history
  • Loading branch information
paudsu01 committed Feb 18, 2024
1 parent 8f42361 commit dcff847
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
2 changes: 1 addition & 1 deletion extension/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "FPL 360",
"version": "1.2.3",
"version": "1.2.4",
"description": "Complete FPL chrome extension",
"icons": {
"16": "img/icons/16x16.png",
Expand Down
9 changes: 2 additions & 7 deletions extension/scripts/draft-content-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,16 +420,11 @@ function get_url_code_for_transactions(url){
}
}


function create_team_name_away_fixture_dict_and_modify_DOM(fixtures){

if (!(ALL_SETTINGS["away-home-jersey"] == false)){
TEAM_AWAY_DICT = {};
for (let fixture of fixtures){
let home_team = ID_TEAM_DICT[fixture["team_h"]];
let away_team = ID_TEAM_DICT[fixture["team_a"]];
if (!(home_team in TEAM_AWAY_DICT)) TEAM_AWAY_DICT[home_team] = false;
if (!(away_team in TEAM_AWAY_DICT)) TEAM_AWAY_DICT[away_team] = true;
}
create_team_away_dict(fixtures, "started");
}
let selector = SELECTOR_OBJECT[URL_CODE];
// Swap kits if needed after element discovered
Expand Down
10 changes: 2 additions & 8 deletions extension/scripts/fantasy-content-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,14 +550,8 @@ async function fetch_team_name_away_fixture_dict_and_modify_DOM(){

let response = await fetch(`https://fantasy.premierleague.com/api/fixtures/?event=${CHOSEN_GAMEWEEK}`)
let fixtures = await response.json();
TEAM_AWAY_DICT = {};
for (let fixture of fixtures){
let home_team = ID_TEAM_DICT[fixture["team_h"]];
let away_team = ID_TEAM_DICT[fixture["team_a"]];
if (!(home_team in TEAM_AWAY_DICT)) TEAM_AWAY_DICT[home_team] = false;
if (!(away_team in TEAM_AWAY_DICT)) TEAM_AWAY_DICT[away_team] = true;
}

create_team_away_dict(fixtures, "finished");

// Swap kits if needed after element discovered
waitForElement(document.body, "[data-testid='pitch']").then(()=>{
modifyDOM();
Expand Down
33 changes: 33 additions & 0 deletions extension/scripts/helper-content-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,39 @@ function waitForElement(parentElement, selector){
)
}

function create_team_away_dict(fixtures, object_key){

// Reset team-away-dict
TEAM_AWAY_DICT = {};
// let team_fixture_info be a mapping from team name to a list which contains two booleans(first one being a true/false(away being true)
// and the second one whether or not the game has finished)
// Only store the first game they played and swap with their next name if the first game is finished
let team_fixture_info = {};
for (let fixture of fixtures){
let home_team = ID_TEAM_DICT[fixture["team_h"]];
let away_team = ID_TEAM_DICT[fixture["team_a"]];

assign_value_to_team_key(home_team, false, fixture, team_fixture_info, object_key);
assign_value_to_team_key(away_team, true, fixture, team_fixture_info, object_key);
}
}

function assign_value_to_team_key(team_code, is_away, fixture, team_fixture_info, object_key){

if (!(team_code in team_fixture_info)) {
team_fixture_info[team_code] = [is_away, fixture[object_key]];
TEAM_AWAY_DICT[team_code] = is_away;
} else {

// only take the current fixture if the previous fixture hasn't finished
if (team_fixture_info[team_code][1]){
team_fixture_info[team_code] = [is_away, fixture[object_key]];
TEAM_AWAY_DICT[team_code] = is_away;
}
}
}


async function check_if_away_jersey_needed(playerButtonElement, teamCode, use_regex, dict, querySelectorParameter){

let awayJerseyNeeded = false;
Expand Down

0 comments on commit dcff847

Please sign in to comment.