From 6157e9df3d502225088df39b6eeda34643a179fd Mon Sep 17 00:00:00 2001 From: Jesse Batman Date: Mon, 9 Nov 2020 15:39:33 +0200 Subject: [PATCH 1/4] Fixed column sizes on smaller devices --- src/content/features/add-player-profile-level-progress.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/content/features/add-player-profile-level-progress.js b/src/content/features/add-player-profile-level-progress.js index 8788d6c4..c24aa90d 100644 --- a/src/content/features/add-player-profile-level-progress.js +++ b/src/content/features/add-player-profile-level-progress.js @@ -80,16 +80,16 @@ export default async parentElement => {

Level Progress

-
+
{keyStatElement({ key: 'Level', stat: createSkillLevelElement({ level: currentLevel }) })}
-
+
{keyStatElement({ key: 'Elo', stat: faceitElo })}
-
+
{currentLevel === 10 ? keyStatElement({ key: `Maximum level reached`, stat: '🔥' }) : keyStatElement({ From 6c0bdefedce43f5a0b9b4e16a0a1ffec64bc9985 Mon Sep 17 00:00:00 2001 From: Jesse Batman Date: Mon, 9 Nov 2020 17:17:05 +0200 Subject: [PATCH 2/4] Added teams rosters player elo's and extra info --- src/content/components/elo.js | 8 +- .../features/add-match-room-player-stats.js | 6 +- src/content/features/add-team-player-info.js | 98 +++++++++++++++++++ src/content/helpers/faceit-api.js | 2 + src/content/helpers/pages.js | 3 + src/content/helpers/team-page.js | 16 +++ src/content/index.js | 3 + 7 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 src/content/features/add-team-player-info.js create mode 100644 src/content/helpers/team-page.js diff --git a/src/content/components/elo.js b/src/content/components/elo.js index 6f211a10..18e762de 100644 --- a/src/content/components/elo.js +++ b/src/content/components/elo.js @@ -2,9 +2,15 @@ import { h } from 'dom-chef' import createIconElement from './icon' -export default ({ elo, alignRight = false, style = {} }) => { +export default ({ + elo, + alignRight = false, + style = {}, + className = undefined +}) => { const eloElement = ( { if (!stats) { return } - const statsElement = createPlayerStatsElement(stats, !isFaction1) + + const statsElement = createPlayerStatsElement({ + ...stats, + alignRight: !isFaction1 + }) const memberDetailsElement = select( '.match-team-member__details', diff --git a/src/content/features/add-team-player-info.js b/src/content/features/add-team-player-info.js new file mode 100644 index 00000000..a562c77c --- /dev/null +++ b/src/content/features/add-team-player-info.js @@ -0,0 +1,98 @@ +/** @jsx h */ +import { h } from 'dom-chef' +import select from 'select-dom' +import { + hasFeatureAttribute, + setFeatureAttribute +} from '../helpers/dom-element' +import { getPlayer, getTeam } from '../helpers/faceit-api' +import { + getTeamMemberPlayerElements, + getTeamMemberNicknameElement, + getTeamId +} from '../helpers/team-page' +import createFlagElement from '../components/flag' +import { getPlayerBadges } from '../helpers/player-badges' +import createFeaturedPlayerBadgeElement from '../components/player-badge' +import createEloElement from '../components/elo' +import createSkillLevelElement from '../components/skill-level' + +const FEATURE_ATTRIBUTE = 'team-player-stats' + +export default async parentElement => { + const teamId = getTeamId() + + const team = await getTeam(teamId) + + if (!team) { + return + } + + const memberElements = getTeamMemberPlayerElements(parentElement) + + const badges = await getPlayerBadges(team.members.map(({ guid }) => guid)) + + memberElements.forEach(async memberElement => { + if (hasFeatureAttribute(FEATURE_ATTRIBUTE, memberElement)) { + return + } + + setFeatureAttribute(FEATURE_ATTRIBUTE, memberElement) + + const nicknameElement = getTeamMemberNicknameElement(memberElement) + const nickname = nicknameElement.textContent + + const player = await getPlayer(nickname) + + if (!player) { + return + } + + const { country, guid, csgoName, games, csgoSkillLevel } = player + + const memberDetailsElement = select('.users-list__details', memberElement) + + if (badges[guid]) { + const featuredPlayerBadgeElement = createFeaturedPlayerBadgeElement( + badges[guid] + ) + + memberDetailsElement.insertAdjacentElement( + 'afterbegin', +
{featuredPlayerBadgeElement}
+ ) + } + + if (csgoName) { + memberDetailsElement.appendChild( + + {csgoName} + + ) + } + + if (games && games.csgo) { + const elo = games.csgo.faceitElo || '–' + + memberElement.children[0].appendChild( +
+ {createEloElement({ + elo, + className: 'text-muted text-md', + alignRight: true, + style: { 'margin-right': 4 } + })} + {createSkillLevelElement({ level: csgoSkillLevel || 0 })} +
+ ) + } + + const flagElement = createFlagElement({ country }) + nicknameElement.prepend(flagElement) + }) +} diff --git a/src/content/helpers/faceit-api.js b/src/content/helpers/faceit-api.js index 1e545998..98ac5920 100644 --- a/src/content/helpers/faceit-api.js +++ b/src/content/helpers/faceit-api.js @@ -112,6 +112,8 @@ export const getQuickMatch = matchId => export const getMatch = matchId => fetchApiMemoized(`/match/v2/match/${matchId}`) +export const getTeam = teamId => fetchApiMemoized(`/core/v1/teams/${teamId}`) + export const getSelf = () => fetchApiMemoized('/core/v1/sessions/me') export const getQuickMatchPlayers = async (game, region, matchType) => diff --git a/src/content/helpers/pages.js b/src/content/helpers/pages.js index f4171e1c..5c5ebf2d 100644 --- a/src/content/helpers/pages.js +++ b/src/content/helpers/pages.js @@ -9,3 +9,6 @@ export const isPlayerProfileStats = path => export const isPlayerProfile = path => /players\/.*$/.test(path || getCurrentPath()) + +export const isTeamsOverview = path => + /teams\/.+-.+-.+-.+$/.test(path || getCurrentPath()) diff --git a/src/content/helpers/team-page.js b/src/content/helpers/team-page.js new file mode 100644 index 00000000..1d465a7d --- /dev/null +++ b/src/content/helpers/team-page.js @@ -0,0 +1,16 @@ +import select from 'select-dom' +import { getCurrentPath } from './location' + +export const getTeamId = path => { + const match = /teams\/([0-9a-z]+-[0-9a-z]+-[0-9a-z]+-[0-9a-z]+-[0-9a-z]+(?:-[0-9a-z]+)?)/.exec( + path || getCurrentPath() + ) + + return match && match[1] +} + +export const getTeamMemberPlayerElements = parent => + select.all('ul.users-list > li', parent) + +export const getTeamMemberNicknameElement = parent => + select('strong[ng-bind="member.nickname"]', parent) diff --git a/src/content/index.js b/src/content/index.js index 8c6609f4..fd74798d 100755 --- a/src/content/index.js +++ b/src/content/index.js @@ -40,6 +40,7 @@ import addMatchRoomEloSelfResult from './features/add-match-room-elo-self-result import applyMatchRoomFocusMode from './features/apply-match-room-focus-mode' import addMatchRoomPlayerLinks from './features/add-match-room-player-links' import addPlayerProfileLinks from './features/add-player-profile-links' +import addTeamPlayerInfo from './features/add-team-player-info' let checkedBan = false @@ -180,6 +181,8 @@ function observeBody() { addPlayerProfileDownloadDemo(mainContentElement) addPlayerProfileExtendedStats(mainContentElement) } + } else if (pages.isTeamsOverview()) { + addTeamPlayerInfo(mainContentElement) } } }) From 623f0cff2e38fb95cdb9b7f2a849b5f757f02acc Mon Sep 17 00:00:00 2001 From: Jesse Batman Date: Mon, 9 Nov 2020 17:56:52 +0200 Subject: [PATCH 3/4] Added option to opt out --- src/content/index.js | 6 +++++- src/popup/sections/appearance.js | 6 ++++++ src/shared/settings.js | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/content/index.js b/src/content/index.js index fd74798d..12f51b6b 100755 --- a/src/content/index.js +++ b/src/content/index.js @@ -182,7 +182,11 @@ function observeBody() { addPlayerProfileExtendedStats(mainContentElement) } } else if (pages.isTeamsOverview()) { - addTeamPlayerInfo(mainContentElement) + runFeatureIf( + 'teamRosterPlayersInfo', + addTeamPlayerInfo, + mainContentElement + ) } } }) diff --git a/src/popup/sections/appearance.js b/src/popup/sections/appearance.js index ddb179db..9d1d911b 100644 --- a/src/popup/sections/appearance.js +++ b/src/popup/sections/appearance.js @@ -41,6 +41,12 @@ export default ({ getSwitchProps }) => ( } {...getSwitchProps('matchRoomHidePlayerControls')} /> + Team page + Other page elements Date: Sun, 27 Jun 2021 15:06:05 +0300 Subject: [PATCH 4/4] Removed useless setting of className to undefined --- src/content/components/elo.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/content/components/elo.js b/src/content/components/elo.js index 18e762de..a41d5825 100644 --- a/src/content/components/elo.js +++ b/src/content/components/elo.js @@ -2,12 +2,7 @@ import { h } from 'dom-chef' import createIconElement from './icon' -export default ({ - elo, - alignRight = false, - style = {}, - className = undefined -}) => { +export default ({ elo, className, alignRight = false, style = {} }) => { const eloElement = (