From 375b3b38266321e741e7dcbcdcb40b059d64d6d7 Mon Sep 17 00:00:00 2001 From: Ashish Kumar Singh Date: Fri, 2 Jul 2021 23:48:27 -0400 Subject: [PATCH 01/11] Veto Map Limit Feature. --- src/content/features/click-match-room-veto-maps.js | 13 +++++++++++-- src/popup/sections/veto-preferences.js | 14 +++++++++++++- src/shared/settings.js | 5 +++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/content/features/click-match-room-veto-maps.js b/src/content/features/click-match-room-veto-maps.js index 8b5ed74c..907981ee 100644 --- a/src/content/features/click-match-room-veto-maps.js +++ b/src/content/features/click-match-room-veto-maps.js @@ -48,7 +48,9 @@ export default async parentElement => { const { matchRoomAutoVetoMapItems, matchRoomAutoVetoMapsShuffle: shuffleMaps, - matchRoomAutoVetoMapsShuffleAmount: shuffleMapsAmount + matchRoomAutoVetoMapsShuffleAmount: shuffleMapsAmount, + matchRoomAutoVetoMapsLimit: vetoMapsLimit, + matchRoomAutoVetoMapsLimitAmount: vetoMapsLimitAmount } = await storage.getAll() let autoVetoItems = matchRoomAutoVetoMapItems.map(m => maps.csgo[m] || m) @@ -72,6 +74,8 @@ export default async parentElement => { setFeatureAttribute(FEATURE_ATTRIBUTE, votingListElement) + let vetoMapCounter = 0 + const autoVeto = () => { const isVetoTurn = select.exists('button', votingListElement) @@ -86,7 +90,12 @@ export default async parentElement => { ) if (vetoButtonElement) { setTimeout(() => { - vetoButtonElement.click() + if (vetoMapCounter < vetoMapsLimitAmount) { + vetoButtonElement.click() + if (vetoMapsLimit) { + vetoMapCounter += 1 + } + } }, VETO_DELAY) } return Boolean(vetoButtonElement) diff --git a/src/popup/sections/veto-preferences.js b/src/popup/sections/veto-preferences.js index 371319f2..6eef9e58 100644 --- a/src/popup/sections/veto-preferences.js +++ b/src/popup/sections/veto-preferences.js @@ -1,7 +1,8 @@ import React from 'react' import { MATCH_ROOM_VETO_LOCATION_REGIONS, - MATCH_ROOM_VETO_MAP_ITEMS + MATCH_ROOM_VETO_MAP_ITEMS, + MAX_VETO_OPTIONS } from '../../shared/settings' import ListSubheader from '../components/list-subheader' import ListItemMenu from '../components/list-item-menu' @@ -45,6 +46,17 @@ export default ({ getMenuProps, getSortableProps, getSwitchProps }) => ( mapOption={option => `First ${option}`} {...getMenuProps('matchRoomAutoVetoMapsShuffleAmount')} /> + + index + 1)} + mapOption={option => `First ${option}`} + {...getMenuProps('matchRoomAutoVetoMapsLimitAmount')} + /> diff --git a/src/shared/settings.js b/src/shared/settings.js index 627aa5ea..552e16dd 100644 --- a/src/shared/settings.js +++ b/src/shared/settings.js @@ -10,6 +10,9 @@ export const MATCH_ROOM_VETO_LOCATION_REGIONS = Object.keys( MATCH_ROOM_VETO_LOCATION_ITEMS ) +// I was not sure how to limit max veto picks to 4 in list-item-menu, so I added this to use it. +export const MAX_VETO_OPTIONS = ['MAP 1', 'MAP 3', 'MAP 5', 'MAP 7'] + export const MATCH_ROOM_VETO_MAP_ITEMS = [ 'de_dust2', 'de_mirage', @@ -38,6 +41,8 @@ export const DEFAULTS = { matchRoomAutoVetoMaps: false, matchRoomAutoVetoMapsShuffle: false, matchRoomAutoVetoMapsShuffleAmount: 3, + matchRoomAutoVetoMapsLimit: false, + matchRoomAutoVetoMapsLimitAmount: 4, matchRoomAutoVetoMapItems: MATCH_ROOM_VETO_MAP_ITEMS, matchRoomFocusMode: false, modalCloseMatchVictory: false, From ef960faecccefc112828d1d0372b7d4dd3d373d5 Mon Sep 17 00:00:00 2001 From: Ashish Kumar Singh Date: Wed, 25 Aug 2021 12:30:03 -0400 Subject: [PATCH 02/11] Fix #106 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hey, @poacher2k and @Morabotti. Fixed the issue I raised where the player with 0/1 matches has no stats shown on match page. Hope this code helps. 💯 --- .../features/add-match-room-player-stats.js | 12 ++++++++++-- src/content/helpers/faceit-api.js | 2 +- src/content/helpers/stats.js | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/content/features/add-match-room-player-stats.js b/src/content/features/add-match-room-player-stats.js index d8148d5e..c21fbb4d 100644 --- a/src/content/features/add-match-room-player-stats.js +++ b/src/content/features/add-match-room-player-stats.js @@ -60,10 +60,18 @@ export default async parent => { userId = player.id } - const stats = await getPlayerStats(userId, game) + let stats = await getPlayerStats(userId, game) if (!stats) { - return + //Set stats to default 0 instead of not loading the UI. + stats = { + matches: '--', + winRate: 0, + averageKDRatio: 0.0, + averageKRRatio: 0.0, + averageHeadshots: 0, + averageKills: 0 + } } const statsElement = createPlayerStatsElement({ diff --git a/src/content/helpers/faceit-api.js b/src/content/helpers/faceit-api.js index 98ac5920..9992350c 100644 --- a/src/content/helpers/faceit-api.js +++ b/src/content/helpers/faceit-api.js @@ -94,7 +94,7 @@ export const getPlayerStats = async (userId, game, size = 20) => { averageStats = averageStats.filter(stats => stats.gameMode.includes('5v5')) - if (averageStats.length <= 1) { + if (averageStats.length <= 0) { return null } diff --git a/src/content/helpers/stats.js b/src/content/helpers/stats.js index 2e778bb0..a5956053 100644 --- a/src/content/helpers/stats.js +++ b/src/content/helpers/stats.js @@ -39,6 +39,25 @@ export const mapAverageStats = stats => (acc, curr, i) => Object.keys(curr).reduce((acc2, curr2) => { let value + if (stats.length === 1) { + if (curr2 === 'winRate') { + const results = [curr[curr2]] + const wins = results.filter(x => x === 'win').length + value = Math.round((wins / results.length) * 100) + } else { + value = (curr[curr2] / stats.length).toFixed(2) / 1 + if ( + curr2 === AVERAGE_STATS_MAP.c4 || + curr2 === AVERAGE_STATS_MAP.i6 + ) { + value = Math.round(value) + } + } + return { + ...acc2, + [curr2]: value + } + } if (stats.length === i + 1) { if (curr2 === 'winRate') { From ba1dff7dab47efde2a72b148c159d14c3505c95c Mon Sep 17 00:00:00 2001 From: Ashish Kumar Singh Date: Wed, 25 Aug 2021 12:33:20 -0400 Subject: [PATCH 03/11] Fix #106 No stats being shown for player with 0/1 game --- src/content/features/add-match-room-player-stats.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/features/add-match-room-player-stats.js b/src/content/features/add-match-room-player-stats.js index c21fbb4d..d381a4f3 100644 --- a/src/content/features/add-match-room-player-stats.js +++ b/src/content/features/add-match-room-player-stats.js @@ -63,7 +63,7 @@ export default async parent => { let stats = await getPlayerStats(userId, game) if (!stats) { - //Set stats to default 0 instead of not loading the UI. + // Set stats to default 0 instead of not loading the UI. stats = { matches: '--', winRate: 0, From 4f7db378a0abb4b9f12754934476381dd420e761 Mon Sep 17 00:00:00 2001 From: Ashish Kumar Singh Date: Wed, 25 Aug 2021 13:03:52 -0400 Subject: [PATCH 04/11] Issue #110 Flag SVG was not found fix, should apply to all other flags aswell. --- src/content/components/flag.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/content/components/flag.js b/src/content/components/flag.js index 5b71c7fa..b01f862a 100644 --- a/src/content/components/flag.js +++ b/src/content/components/flag.js @@ -16,7 +16,9 @@ export default ({ country, alignedRight = false }) => { [`margin-${alignedRight ? 'left' : 'right'}`]: 6 }} title={countryName} - dangerouslySetInnerHTML={{ __html: reqFlag(`./${country}.svg`) }} + dangerouslySetInnerHTML={{ + __html: reqFlag(`./${country.toLowerCase()}.svg`) + }} /> ) } From 5bbd5450bf75820fce4ec179bcbf3f00b83ce429 Mon Sep 17 00:00:00 2001 From: Ashish Kumar Singh Date: Wed, 25 Aug 2021 16:28:57 -0400 Subject: [PATCH 05/11] enhancement added #9 Veto Maps Limit --- .../features/click-match-room-veto-maps.js | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/content/features/click-match-room-veto-maps.js b/src/content/features/click-match-room-veto-maps.js index 907981ee..453cd089 100644 --- a/src/content/features/click-match-room-veto-maps.js +++ b/src/content/features/click-match-room-veto-maps.js @@ -49,6 +49,8 @@ export default async parentElement => { matchRoomAutoVetoMapItems, matchRoomAutoVetoMapsShuffle: shuffleMaps, matchRoomAutoVetoMapsShuffleAmount: shuffleMapsAmount, + + // Auto veto limit variables. matchRoomAutoVetoMapsLimit: vetoMapsLimit, matchRoomAutoVetoMapsLimitAmount: vetoMapsLimitAmount } = await storage.getAll() @@ -90,11 +92,26 @@ export default async parentElement => { ) if (vetoButtonElement) { setTimeout(() => { - if (vetoMapCounter < vetoMapsLimitAmount) { - vetoButtonElement.click() - if (vetoMapsLimit) { + /* + * Added Auto Veto Limit: + * + * Default: vetoMapsLimit = false (No Limit on Veto) + * vetoMapsLimitAmount = 4 (Maximum a team can veto) + * vetoMapCounter = 1-4 (Keep a check on number of maps veteod) + * + * Logic: If vetoMapsLimit = false, auto veto maximum possible maps + * else check + * if counter <= set_value (default=4) + * auto veto and increment counter + * else just wait for player to veto. + */ + if (vetoMapsLimit) { + if (vetoMapCounter < vetoMapsLimitAmount) { + vetoButtonElement.click() vetoMapCounter += 1 } + } else { + vetoButtonElement.click() } }, VETO_DELAY) } From f9d0eb844a12eb51eefcc119d99d719770c1ef23 Mon Sep 17 00:00:00 2001 From: Ashish Kumar Singh Date: Wed, 1 Sep 2021 12:29:20 -0400 Subject: [PATCH 06/11] Lint error fix. --- src/content/features/add-match-room-player-stats.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/features/add-match-room-player-stats.js b/src/content/features/add-match-room-player-stats.js index a53ce194..7b9e4da2 100644 --- a/src/content/features/add-match-room-player-stats.js +++ b/src/content/features/add-match-room-player-stats.js @@ -62,7 +62,7 @@ export default async parent => { userId = player.id } - let stats = await getPlayerStats(userId, game) + const stats = await getPlayerStats(userId, game) if (stats === false) { return From 04afc8b5eb8fcc14374c2de0548ce84b12e36439 Mon Sep 17 00:00:00 2001 From: Ashish Kumar Singh Date: Wed, 1 Sep 2021 19:29:53 -0400 Subject: [PATCH 07/11] Issue #113 Change Loss to red on sidebar Match History. --- src/content/features/add-sidebar-matches-elo.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/content/features/add-sidebar-matches-elo.js b/src/content/features/add-sidebar-matches-elo.js index d1528bb5..63ac0c9d 100644 --- a/src/content/features/add-sidebar-matches-elo.js +++ b/src/content/features/add-sidebar-matches-elo.js @@ -57,6 +57,8 @@ export default async () => { const { eloDiff, newElo } = eloChange + resultElement.style.color = `${eloDiff < 0 ? '#e6194c' : ''}` + resultElement.textContent += ` (${eloDiff >= 0 ? '+' : ''}${eloDiff}${ isFreeMember ? '' : ` / ${newElo}` } Elo)` From 74334968a4d60dda6dd5e0e3803de272075df45a Mon Sep 17 00:00:00 2001 From: Ashish Kumar Singh Date: Wed, 1 Sep 2021 20:47:33 -0400 Subject: [PATCH 08/11] Match Room Veto Limit changes. --- src/content/helpers/faceit-api.js | 2 +- src/content/helpers/stats.js | 20 -------------------- src/popup/sections/veto-preferences.js | 5 ++--- src/shared/settings.js | 3 --- 4 files changed, 3 insertions(+), 27 deletions(-) diff --git a/src/content/helpers/faceit-api.js b/src/content/helpers/faceit-api.js index 2a3d7a31..f5dbcca2 100644 --- a/src/content/helpers/faceit-api.js +++ b/src/content/helpers/faceit-api.js @@ -94,7 +94,7 @@ export const getPlayerStats = async (userId, game, size = 20) => { averageStats = averageStats.filter(stats => stats.gameMode.includes('5v5')) - if (averageStats.length <= 0) { + if (averageStats.length <= 1) { return null } diff --git a/src/content/helpers/stats.js b/src/content/helpers/stats.js index a5956053..947c8202 100644 --- a/src/content/helpers/stats.js +++ b/src/content/helpers/stats.js @@ -39,26 +39,6 @@ export const mapAverageStats = stats => (acc, curr, i) => Object.keys(curr).reduce((acc2, curr2) => { let value - if (stats.length === 1) { - if (curr2 === 'winRate') { - const results = [curr[curr2]] - const wins = results.filter(x => x === 'win').length - value = Math.round((wins / results.length) * 100) - } else { - value = (curr[curr2] / stats.length).toFixed(2) / 1 - if ( - curr2 === AVERAGE_STATS_MAP.c4 || - curr2 === AVERAGE_STATS_MAP.i6 - ) { - value = Math.round(value) - } - } - return { - ...acc2, - [curr2]: value - } - } - if (stats.length === i + 1) { if (curr2 === 'winRate') { const results = [...acc[curr2], curr[curr2]] diff --git a/src/popup/sections/veto-preferences.js b/src/popup/sections/veto-preferences.js index 6eef9e58..a44580ee 100644 --- a/src/popup/sections/veto-preferences.js +++ b/src/popup/sections/veto-preferences.js @@ -1,8 +1,7 @@ import React from 'react' import { MATCH_ROOM_VETO_LOCATION_REGIONS, - MATCH_ROOM_VETO_MAP_ITEMS, - MAX_VETO_OPTIONS + MATCH_ROOM_VETO_MAP_ITEMS } from '../../shared/settings' import ListSubheader from '../components/list-subheader' import ListItemMenu from '../components/list-item-menu' @@ -53,7 +52,7 @@ export default ({ getMenuProps, getSortableProps, getSwitchProps }) => ( /> index + 1)} + options={[...Array(4).keys()].map((_, index) => index + 1)} mapOption={option => `First ${option}`} {...getMenuProps('matchRoomAutoVetoMapsLimitAmount')} /> diff --git a/src/shared/settings.js b/src/shared/settings.js index 1fdab90c..12f073aa 100644 --- a/src/shared/settings.js +++ b/src/shared/settings.js @@ -10,9 +10,6 @@ export const MATCH_ROOM_VETO_LOCATION_REGIONS = Object.keys( MATCH_ROOM_VETO_LOCATION_ITEMS ) -// I was not sure how to limit max veto picks to 4 in list-item-menu, so I added this to use it. -export const MAX_VETO_OPTIONS = ['MAP 1', 'MAP 3', 'MAP 5', 'MAP 7'] - export const MATCH_ROOM_VETO_MAP_ITEMS = [ 'de_dust2', 'de_mirage', From b3cf17b9edbc20f6988b3a393b0229de1283c2d7 Mon Sep 17 00:00:00 2001 From: Ashish Kumar Singh Date: Wed, 1 Sep 2021 21:07:21 -0400 Subject: [PATCH 09/11] #9 Fixes - Using match room veto items to create veto limit dropdown. - Linting fixes. --- src/content/helpers/stats.js | 1 + src/popup/sections/veto-preferences.js | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/content/helpers/stats.js b/src/content/helpers/stats.js index 947c8202..2e778bb0 100644 --- a/src/content/helpers/stats.js +++ b/src/content/helpers/stats.js @@ -39,6 +39,7 @@ export const mapAverageStats = stats => (acc, curr, i) => Object.keys(curr).reduce((acc2, curr2) => { let value + if (stats.length === i + 1) { if (curr2 === 'winRate') { const results = [...acc[curr2], curr[curr2]] diff --git a/src/popup/sections/veto-preferences.js b/src/popup/sections/veto-preferences.js index a44580ee..ab7a8482 100644 --- a/src/popup/sections/veto-preferences.js +++ b/src/popup/sections/veto-preferences.js @@ -52,7 +52,9 @@ export default ({ getMenuProps, getSortableProps, getSwitchProps }) => ( /> index + 1)} + options={MATCH_ROOM_VETO_MAP_ITEMS.filter( + (_, index) => index % 2 == 0 + ).map((_, index) => index + 1)} mapOption={option => `First ${option}`} {...getMenuProps('matchRoomAutoVetoMapsLimitAmount')} /> From 859588e9d2287b4a216ebcd7371f5660af51065a Mon Sep 17 00:00:00 2001 From: Ashish Kumar Singh Date: Wed, 1 Sep 2021 21:09:39 -0400 Subject: [PATCH 10/11] Lint fix changing == to === --- src/popup/sections/veto-preferences.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/popup/sections/veto-preferences.js b/src/popup/sections/veto-preferences.js index ab7a8482..a3d40c4c 100644 --- a/src/popup/sections/veto-preferences.js +++ b/src/popup/sections/veto-preferences.js @@ -53,7 +53,7 @@ export default ({ getMenuProps, getSortableProps, getSwitchProps }) => ( index % 2 == 0 + (_, index) => index % 2 === 0 ).map((_, index) => index + 1)} mapOption={option => `First ${option}`} {...getMenuProps('matchRoomAutoVetoMapsLimitAmount')} From 04987a20d472f371de67b0177d3b086d123d80f1 Mon Sep 17 00:00:00 2001 From: Ashish Kumar Singh Date: Thu, 2 Sep 2021 08:23:27 -0400 Subject: [PATCH 11/11] Undo Issue #113 --- src/content/features/add-sidebar-matches-elo.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/content/features/add-sidebar-matches-elo.js b/src/content/features/add-sidebar-matches-elo.js index 63ac0c9d..d1528bb5 100644 --- a/src/content/features/add-sidebar-matches-elo.js +++ b/src/content/features/add-sidebar-matches-elo.js @@ -57,8 +57,6 @@ export default async () => { const { eloDiff, newElo } = eloChange - resultElement.style.color = `${eloDiff < 0 ? '#e6194c' : ''}` - resultElement.textContent += ` (${eloDiff >= 0 ? '+' : ''}${eloDiff}${ isFreeMember ? '' : ` / ${newElo}` } Elo)`