Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Teams page roster information #84

Merged
merged 4 commits into from
Jun 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/content/components/elo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import { h } from 'dom-chef'
import createIconElement from './icon'

export default ({ elo, alignRight = false, style = {} }) => {
export default ({ elo, className, alignRight = false, style = {} }) => {
const eloElement = (
<span
className={className}
style={{
display: 'flex',
'align-items': 'center',
Expand Down
6 changes: 5 additions & 1 deletion src/content/features/add-match-room-player-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ export default async parent => {
if (!stats) {
return
}
const statsElement = createPlayerStatsElement(stats, !isFaction1)

const statsElement = createPlayerStatsElement({
...stats,
alignRight: !isFaction1
})

const memberDetailsElement = select(
'.match-team-member__details',
Expand Down
6 changes: 3 additions & 3 deletions src/content/features/add-player-profile-level-progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ export default async parentElement => {
<section>
<h2 className="header-text-3 heading-border">Level Progress</h2>
<div className="row flex flex-stretch">
<div className="col-lg-4 flex-column-stretch">
<div className="col-sm-4 flex-column-stretch">
{keyStatElement({
key: 'Level',
stat: createSkillLevelElement({ level: currentLevel })
})}
</div>
<div className="col-lg-4 flex-column-stretch">
<div className="col-sm-4 flex-column-stretch">
{keyStatElement({ key: 'Elo', stat: faceitElo })}
</div>
<div className="col-lg-4 flex-column-stretch">
<div className="col-sm-4 flex-column-stretch">
{currentLevel === 10
? keyStatElement({ key: `Maximum level reached`, stat: '🔥' })
: keyStatElement({
Expand Down
98 changes: 98 additions & 0 deletions src/content/features/add-team-player-info.js
Original file line number Diff line number Diff line change
@@ -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',
<div style={{ 'margin-bottom': 2 }}>{featuredPlayerBadgeElement}</div>
)
}

if (csgoName) {
memberDetailsElement.appendChild(
<span className="text-muted" style={{ display: 'block' }}>
{csgoName}
</span>
)
}

if (games && games.csgo) {
const elo = games.csgo.faceitElo || '–'

memberElement.children[0].appendChild(
<div
style={{
display: 'flex',
flexShrink: 0
}}
>
{createEloElement({
elo,
className: 'text-muted text-md',
alignRight: true,
style: { 'margin-right': 4 }
})}
{createSkillLevelElement({ level: csgoSkillLevel || 0 })}
</div>
)
}

const flagElement = createFlagElement({ country })
nicknameElement.prepend(flagElement)
})
}
2 changes: 2 additions & 0 deletions src/content/helpers/faceit-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
3 changes: 3 additions & 0 deletions src/content/helpers/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ export const isPlayerProfileStats = path =>

export const isPlayerProfile = path =>
/players\/.*$/.test(path || getCurrentPath())

export const isTeamsOverview = path =>
/teams\/.+-.+-.+-.+$/.test(path || getCurrentPath())
16 changes: 16 additions & 0 deletions src/content/helpers/team-page.js
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions src/content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -180,6 +181,12 @@ function observeBody() {
addPlayerProfileDownloadDemo(mainContentElement)
addPlayerProfileExtendedStats(mainContentElement)
}
} else if (pages.isTeamsOverview()) {
runFeatureIf(
'teamRosterPlayersInfo',
addTeamPlayerInfo,
mainContentElement
)
}
}
})
Expand Down
6 changes: 6 additions & 0 deletions src/popup/sections/appearance.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ export default ({ getSwitchProps }) => (
}
{...getSwitchProps('matchRoomHidePlayerControls')}
/>
<ListSubheader divider>Team page</ListSubheader>
<ListItemSwitch
primary="Detailed Team Information"
secondary="Show detailed roster information about team."
{...getSwitchProps('teamRosterPlayersInfo')}
/>
<ListSubheader divider>Other page elements</ListSubheader>
<ListItemSwitch
primary="Hide FACEIT Client download banner"
Expand Down
3 changes: 2 additions & 1 deletion src/shared/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ export const DEFAULTS = {
notifyMatchRoomAutoVetoLocations: true,
notifyMatchRoomAutoVetoMaps: true,
updateNotificationType: 'tab',
updateNotifications: []
updateNotifications: [],
teamRosterPlayersInfo: true
}