-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding modules to show clubmates and script Patreon supporters on lea…
…derboards (league, contests, season, pantheon, pov, pog)
- Loading branch information
Numbers
committed
Jan 21, 2023
1 parent
1e51b7d
commit 02a75a2
Showing
20 changed files
with
387 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import CoreModule from '../CoreModule' | ||
import Helpers from '../../common/Helpers' | ||
import I18n from '../../i18n' | ||
|
||
import styles from './styles.lazy.scss' | ||
import { lsKeys } from '../../common/Constants' | ||
|
||
const MODULE_KEY = 'leaderboardClubmateIndicators' | ||
|
||
class LeaderboardClubmateIndicatorsModule extends CoreModule { | ||
constructor () { | ||
super({ | ||
baseKey: MODULE_KEY, | ||
label: I18n.getModuleLabel('config', MODULE_KEY), | ||
default: true | ||
}) | ||
this.label = I18n.getModuleLabel.bind(this, MODULE_KEY) | ||
} | ||
|
||
shouldRun () { | ||
return ['activities', 'tower-of-fame', 'pantheon', 'season.html', 'path-of-valor', 'path-of-glory'].some(page => Helpers.isCurrentPage(page)) | ||
} | ||
|
||
run () { | ||
if (this.hasRun || !this.shouldRun()) {return} | ||
|
||
styles.use() | ||
|
||
Helpers.defer(() => { | ||
if (['activities', 'tower-of-fame'].some(page => Helpers.isCurrentPage(page))) { | ||
this.addClubmateAnnotations() | ||
} | ||
}) | ||
|
||
$(document).on('leaderboard-annotated', (event, data) => this.addClubmateAnnotations(data)) | ||
|
||
this.hasRun = true | ||
} | ||
|
||
async addClubmateAnnotations (data) { | ||
const selector = (data && data.selector) || '' | ||
const clubStatus = Helpers.lsGet(lsKeys.CLUB_STATUS) | ||
const nameColumnSelector = this.getNameColumnSelector() | ||
|
||
if (clubStatus && clubStatus.memberIds) { | ||
clubStatus.memberIds.forEach((id) => { | ||
if (id === `${window.Hero.infos.id}`) {return} | ||
$(`${selector} [sorting_id='${id}']`).find(nameColumnSelector).append(`<div class="script-flair script-clubmate"><span class="globalClubs_mix_icn" tooltip="${this.label('clubmate')}"/></div>`) | ||
}) | ||
} | ||
} | ||
|
||
getNameColumnSelector () { | ||
if (Helpers.isCurrentPage('activities')) { | ||
return 'td:nth-of-type(2)' | ||
} else if (Helpers.isCurrentPage('tower-of-fame')) { | ||
return '.nickname' | ||
} | ||
return '> div:nth-of-type(2)' | ||
} | ||
} | ||
|
||
export default LeaderboardClubmateIndicatorsModule |
9 changes: 9 additions & 0 deletions
9
src/modules/LeaderboardClubmateIndicatorsModule/styles.lazy.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.script-flair.script-clubmate { | ||
.globalClubs_mix_icn { | ||
margin: 0; | ||
margin-left: 5px; | ||
height: 21px; | ||
width: 21px; | ||
background-size: contain; | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/modules/LeaderboardSupportersIndicatorsModule/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import CoreModule from '../CoreModule' | ||
import Helpers from '../../common/Helpers' | ||
import I18n from '../../i18n' | ||
|
||
import tierIconGold from '../../assets/hh-plus-plus-gold.svg' | ||
import tierIconSilver from '../../assets/hh-plus-plus-silver.svg' | ||
|
||
import styles from './styles.lazy.scss' | ||
import Supporters from '../../data/Supporters' | ||
|
||
const MODULE_KEY = 'leaderboardSupportersIndicators' | ||
|
||
const TIER_ICONS = { | ||
gold: tierIconGold, | ||
silver: tierIconSilver, | ||
} | ||
|
||
class LeaderboardSupportersIndicatorsModule extends CoreModule { | ||
constructor () { | ||
super({ | ||
baseKey: MODULE_KEY, | ||
default: true | ||
}) | ||
this.label = I18n.getModuleLabel.bind(this, MODULE_KEY) | ||
} | ||
|
||
shouldRun () { | ||
return ['activities', 'tower-of-fame', 'pantheon', 'season.html', 'path-of-valor', 'path-of-glory'].some(page => Helpers.isCurrentPage(page)) | ||
} | ||
|
||
run () { | ||
if (this.hasRun || !this.shouldRun()) {return} | ||
|
||
styles.use() | ||
|
||
Helpers.defer(() => { | ||
if (['activities', 'tower-of-fame'].some(page => Helpers.isCurrentPage(page))) { | ||
this.addSupporterAnnotations() | ||
} | ||
}) | ||
|
||
$(document).on('leaderboard-annotated', (event, data) => this.addSupporterAnnotations(data)) | ||
|
||
this.hasRun = true | ||
} | ||
|
||
async addSupporterAnnotations (data) { | ||
const selector = (data && data.selector) || '' | ||
const supporters = await Supporters.getSupporters() | ||
const filteredSupporters = supporters.filter(({flairs}) => flairs) | ||
|
||
const gameKey = Helpers.getGameKey() | ||
const gamePlatform = Helpers.getPlatform() | ||
|
||
const nameColumnSelector = this.getNameColumnSelector() | ||
|
||
filteredSupporters.forEach(({tier, flairs}) => { | ||
flairs.forEach(({game, platform, id}) => { | ||
if (game === gameKey && platform === gamePlatform) { | ||
$(`${selector} [sorting_id='${id}']`).find(nameColumnSelector).append(`<div class="script-flair script-supporter"><img class="tier-icon" src="${TIER_ICONS[tier]}" tooltip="HH++ ${tier.substring(0,1).toUpperCase()}${tier.substring(1)} Tier Supporter"/></div>`) | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
getNameColumnSelector () { | ||
if (Helpers.isCurrentPage('activities')) { | ||
return 'td:nth-of-type(2)' | ||
} else if (Helpers.isCurrentPage('tower-of-fame')) { | ||
return '.nickname' | ||
} | ||
return '> div:nth-of-type(2)' | ||
} | ||
} | ||
|
||
export default LeaderboardSupportersIndicatorsModule |
12 changes: 12 additions & 0 deletions
12
src/modules/LeaderboardSupportersIndicatorsModule/styles.lazy.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.script-flair { | ||
display: inline-flex; | ||
height: 100%; | ||
flex-direction: column; | ||
justify-content: center; | ||
|
||
.tier-icon { | ||
display: inline-block; | ||
margin-left: 5px; | ||
height: 21px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters