Skip to content

Commit 84499da

Browse files
committed
Finish types in achievements.js
1 parent 33bae4f commit 84499da

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

scripts/community/achievements.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ function InitAchievements( items, isPersonal )
209209
if( oldContainer.classList.contains( 'compare_view' ) )
210210
{
211211
isCompareView = true;
212-
leftAvatarUrl = document.querySelector( '.topAvatarsLeft img' ).src;
213-
rightAvatarUrl = document.querySelector( '.topAvatarsRight img' ).src;
212+
leftAvatarUrl = /** @type {HTMLImageElement} */ ( document.querySelector( '.topAvatarsLeft img' ) ).src;
213+
rightAvatarUrl = /** @type {HTMLImageElement} */ ( document.querySelector( '.topAvatarsRight img' ) ).src;
214214
}
215215
}
216216
else
@@ -435,7 +435,7 @@ function InitAchievements( items, isPersonal )
435435
progressText = progress.querySelector( '.progressText' ).textContent.trim();
436436
}
437437

438-
progressWidth = progress.querySelector( '.progress' ).style.width;
438+
progressWidth = /** @type {HTMLElement} */ ( progress.querySelector( '.progress' ) ).style.width;
439439
}
440440

441441
let foundAchievement = false;
@@ -800,7 +800,10 @@ function InitAchievements( items, isPersonal )
800800
{
801801
for( const group of achievementGroups )
802802
{
803-
for( const achievement of group.querySelectorAll( '.steamdb_achievement' ) )
803+
/** @type {NodeListOf<HTMLElement>} */
804+
const achievementElements = group.querySelectorAll( '.steamdb_achievement' );
805+
806+
for( const achievement of achievementElements )
804807
{
805808
achievement.hidden = false;
806809
}
@@ -815,7 +818,10 @@ function InitAchievements( items, isPersonal )
815818
{
816819
let count = 0;
817820

818-
for( const achievement of group.querySelectorAll( '.steamdb_achievement' ) )
821+
/** @type {NodeListOf<HTMLElement>} */
822+
const achievementElements = group.querySelectorAll( '.steamdb_achievement' );
823+
824+
for( const achievement of achievementElements )
819825
{
820826
const title = achievement.querySelector( 'h3' ).textContent;
821827
const description = achievement.querySelector( 'h5' ).textContent;
@@ -840,7 +846,7 @@ function InitAchievements( items, isPersonal )
840846
return;
841847
}
842848

843-
if( [ 'INPUT', 'TEXTAREA', 'SELECT', 'BUTTON' ].includes( e.target.tagName ) )
849+
if( e.target instanceof Element && [ 'INPUT', 'TEXTAREA', 'SELECT', 'BUTTON' ].includes( e.target.tagName ) )
844850
{
845851
return;
846852
}
@@ -1338,7 +1344,7 @@ function ParseApplicationConfig()
13381344
}
13391345

13401346
// Game logo cdn
1341-
const gameLogoUrl = document.querySelector( '.profile_small_header_additional .gameLogo img' ).src;
1347+
const gameLogoUrl = /** @type {HTMLImageElement} */ ( document.querySelector( '.profile_small_header_additional .gameLogo img' ) ).src;
13421348
const gameLogoUrlAppsIndex = gameLogoUrl.lastIndexOf( '/apps/' );
13431349

13441350
if( gameLogoUrlAppsIndex > 0 )
@@ -1414,7 +1420,7 @@ function HookSortButton( sortButton, achievementUpdates, oldAchievementRows, Cre
14141420
sortButton.setAttribute( 'disabled', 'true' );
14151421

14161422
// Request the same page in finnish because it has an easier date format to parse
1417-
const url = new URL( window.location );
1423+
const url = new URL( window.location.href );
14181424
url.searchParams.set( 'l', 'finnish' );
14191425

14201426
fetch( url, {
@@ -1503,7 +1509,15 @@ function HookSortButton( sortButton, achievementUpdates, oldAchievementRows, Cre
15031509
}
15041510

15051511
const c = parsedTime.groups;
1506-
const date = new Date( c.year || currentYear, c.month - 1, c.day, c.hour, c.minute, 0, 0 );
1512+
const date = new Date(
1513+
c.year ? Number.parseInt( c.year, 10 ) : currentYear,
1514+
Number.parseInt( c.month, 10 ) - 1,
1515+
Number.parseInt( c.day, 10 ),
1516+
Number.parseInt( c.hour, 10 ),
1517+
Number.parseInt( c.minute, 10 ),
1518+
0,
1519+
0
1520+
);
15071521

15081522
const achievement = achievementDataMap[ id ];
15091523
achievement.player.unlockTimestamp = date.getTime();

0 commit comments

Comments
 (0)