Skip to content

Commit a99d859

Browse files
committed
Add remaining types
1 parent 84499da commit a99d859

14 files changed

+144
-31
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"start:firefoxdev": "web-ext run --firefox=firefoxdeveloperedition --source-dir ./",
1010
"build": "node build.js",
1111
"version": "node version.js",
12-
"test": "eslint . && stylelint \"**/*.css\" && prettier \"**/*.css\" --check",
12+
"test": "eslint . && stylelint \"**/*.css\" && prettier \"**/*.css\" --check && tsc",
1313
"test:ext": "web-ext lint",
1414
"test:ts": "tsc",
1515
"fix": "eslint . --fix && stylelint \"**/*.css\" --fix && prettier \"**/*.css\" --write"

scripts/background.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,11 @@ async function FetchSteamUserData( callback )
152152
InvalidateCache();
153153

154154
const data = await GetLocalOption( { 'userdata.stored': false } );
155+
156+
/** @type {{error: string, data?: any}} */
155157
const response =
156158
{
157-
error: error.message,
159+
error: error instanceof Error ? error.message : String( error ),
158160
};
159161

160162
if( data[ 'userdata.stored' ] )
@@ -193,6 +195,7 @@ async function FetchSteamUserFamilyData( callback )
193195
return;
194196
}
195197

198+
/** @type {{data: Record<string, any>}|{error: string, data?: Record<string, any>}} */
196199
let callbackResponse = null;
197200
let semaphoreResolve = null;
198201
userFamilySemaphore = new Promise( resolve =>
@@ -244,7 +247,7 @@ async function FetchSteamUserFamilyData( callback )
244247
throw new Error( 'Is Steam okay?' );
245248
}
246249

247-
const reduced = response.response.apps.reduce( ( data, app ) =>
250+
const reduced = response.response.apps.reduce( ( /** @type {any} */ data, /** @type {any} */ app ) =>
248251
{
249252
if( !app.owner_steamids.includes( response.response.owner_steamid ) )
250253
{
@@ -286,7 +289,7 @@ async function FetchSteamUserFamilyData( callback )
286289
{
287290
callbackResponse =
288291
{
289-
error: error.message,
292+
error: error instanceof Error ? error.message : String( error ),
290293
};
291294

292295
if( cache && cache.data )
@@ -298,6 +301,7 @@ async function FetchSteamUserFamilyData( callback )
298301
}
299302
finally
300303
{
304+
// @ts-ignore - this is assigned inside of a promise
301305
semaphoreResolve( callbackResponse );
302306
userFamilySemaphore = null;
303307
}
@@ -513,6 +517,9 @@ function StoreAddToCart( request, callback )
513517
*/
514518
function StoreAddFreeLicense( request, callback )
515519
{
520+
/**
521+
* @param {any} response
522+
*/
516523
const freeLicenseResponse = ( response ) =>
517524
{
518525
if( Array.isArray( response ) )
@@ -585,6 +592,9 @@ function StoreRemoveFreeLicense( request, callback )
585592
*/
586593
function StoreRequestPlaytestAccess( request, callback )
587594
{
595+
/**
596+
* @param {any} response
597+
*/
588598
const playtestResponse = ( response ) =>
589599
{
590600
if( response?.success )
@@ -757,6 +767,7 @@ function GetLocalOption( items )
757767
*/
758768
function SetLocalOption( option, value )
759769
{
770+
/** @type {{ [key: string]: any }} */
760771
const obj = {};
761772
obj[ option ] = value;
762773

scripts/common.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ function GetOption( items, callback )
8484
*/
8585
function SetOption( option, value )
8686
{
87+
/** @type {{ [key: string]: any }} */
8788
const obj = {};
8889
obj[ option ] = value;
8990

@@ -115,13 +116,21 @@ function SendMessageToBackgroundScript( message, callback )
115116
try
116117
{
117118
ExtensionApi.runtime
119+
// @ts-ignore - janky type definitions
118120
.sendMessage( message )
119121
.then( callback )
120122
.catch( errorCallback );
121123
}
122124
catch( error )
123125
{
124-
errorCallback( error );
126+
if( error instanceof Error )
127+
{
128+
errorCallback( error );
129+
}
130+
else
131+
{
132+
errorCallback( new Error( String( error ) ) );
133+
}
125134
}
126135
}
127136

scripts/community/achievements.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare function DoAchievements(isPersonal: boolean): void;
2+
declare function StartViewTransition(callback: ViewTransitionUpdateCallback): void;

scripts/community/achievements_cs2.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ const InitChart = ( container, initialData ) =>
6666
const maxLengthInput = document.createElement( 'input' );
6767
maxLengthInput.className = 'steamdb_achievements_csrating_graph_slider';
6868
maxLengthInput.type = 'range';
69-
maxLengthInput.min = 2;
70-
maxLengthInput.max = initialData.length;
71-
maxLengthInput.value = maxLength;
69+
maxLengthInput.min = '2';
70+
maxLengthInput.max = initialData.length.toString();
71+
maxLengthInput.value = maxLength.toString();
7272
maxLengthInput.addEventListener( 'input', () =>
7373
{
74-
maxLength = maxLengthInput.value;
74+
maxLength = Number.parseInt( maxLengthInput.value, 10 );
7575
DrawChart( initialData, -1, canvas, tooltip, maxLength );
7676
} );
7777
canvas.insertAdjacentElement( 'afterend', maxLengthInput );
@@ -390,8 +390,8 @@ const FetchCSRating = async( profileUrl ) =>
390390
*/
391391
const removeTrailingSlash = ( str ) => str.endsWith( '/' ) ? str.slice( 0, -1 ) : str;
392392

393-
const viewingProfile = removeTrailingSlash( document.querySelector( '.pagecontent .persona_name_text_content' )?.pathname ?? '' );
394-
const myProfile = removeTrailingSlash( document.querySelector( '#global_actions .user_avatar' )?.pathname ?? '' );
393+
const viewingProfile = removeTrailingSlash( /** @type {HTMLAnchorElement} */ ( document.querySelector( '.pagecontent .persona_name_text_content' ) )?.pathname ?? '' );
394+
const myProfile = removeTrailingSlash( /** @type {HTMLAnchorElement} */ ( document.querySelector( '#global_actions .user_avatar' ) )?.pathname ?? '' );
395395

396396
if( viewingProfile === myProfile )
397397
{

scripts/community/inventory.js

Lines changed: 76 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
DisableButtons: 3,
1111
};
1212

13+
/** @type {Record<string, string>} */
1314
const giftCache = {}; // TODO: Store this in indexeddb
1415

1516
const scriptHook = document.getElementById( 'steamdb_inventory_hook' );
@@ -37,21 +38,29 @@
3738
{
3839
window.SellCurrentSelection();
3940

40-
document.getElementById( 'market_sell_currency_input' ).value = this.dataset.price / 100;
41+
/** @type {HTMLInputElement} */
42+
const currencyInput = document.querySelector( '#market_sell_currency_input' );
43+
currencyInput.value = ( Number.parseFloat( this.dataset.price ) / 100.0 ).toString();
4144

4245
window.SellItemDialog.OnInputKeyUp( null ); // Recalculate prices
4346

4447
if( options[ 'enhancement-inventory-quick-sell-auto' ] )
4548
{
4649
// SSA must be accepted before OnAccept call, as it has a check for it
47-
document.getElementById( 'market_sell_dialog_accept_ssa' ).checked = true;
50+
/** @type {HTMLInputElement} */
51+
const ssa = document.querySelector( '#market_sell_dialog_accept_ssa' );
52+
ssa.checked = true;
4853

4954
window.SellItemDialog.OnAccept( dummySellEvent );
5055
window.SellItemDialog.OnConfirmationAccept( dummySellEvent );
5156
}
5257
};
5358

5459
const currencyCode = window.GetCurrencyCode( window.g_rgWalletInfo.wallet_currency );
60+
61+
/**
62+
* @param {number} valueInCents
63+
*/
5564
const FormatCurrency = ( valueInCents ) =>
5665
window.v_currencyformat( valueInCents, currencyCode, window.g_rgWalletInfo.wallet_country );
5766

@@ -61,6 +70,9 @@
6170
const originalOnSuccess = window.SellItemDialog.OnSuccess;
6271
const originalReloadInventory = window.CUserYou.prototype.ReloadInventory;
6372

73+
/**
74+
* @param {any} transport
75+
*/
6476
window.SellItemDialog.OnSuccess = function( transport )
6577
{
6678
nextRefreshCausedBySell = true;
@@ -96,6 +108,9 @@
96108

97109
const originalBuildHover = window.BuildHover;
98110

111+
/**
112+
* @param {string} prefix
113+
*/
99114
window.BuildHover = function( prefix )
100115
{
101116
document.querySelector( `#${prefix} .steamdb_quick_sell` )?.remove();
@@ -106,6 +121,10 @@
106121

107122
const originalPopulateMarketActions = window.PopulateMarketActions;
108123

124+
/**
125+
* @param {HTMLElement} elActions
126+
* @param {any} item
127+
*/
109128
window.PopulateMarketActions = function( elActions, item )
110129
{
111130
const realIsTrading = window.g_bIsTrading;
@@ -134,7 +153,7 @@
134153
listNow.title = i18n.inventory_list_at_title;
135154
listNow.href = 'javascript:void(0)'; // eslint-disable-line no-script-url
136155
listNow.className = 'btn_small btn_darkblue_white_innerfade';
137-
listNow.style.opacity = 0.5;
156+
listNow.style.opacity = '0.5';
138157
listNow.appendChild( listNowText );
139158

140159
const sellNowText = document.createElement( 'span' );
@@ -144,7 +163,7 @@
144163
sellNow.title = i18n.inventory_sell_at_title;
145164
sellNow.href = 'javascript:void(0)'; // eslint-disable-line no-script-url
146165
sellNow.className = 'btn_small btn_darkblue_white_innerfade';
147-
sellNow.style.opacity = 0.5;
166+
sellNow.style.opacity = '0.5';
148167
sellNow.appendChild( sellNowText );
149168

150169
buttons.appendChild( listNow );
@@ -207,7 +226,7 @@
207226
const listNowPrice = data.lowest_sell_order - listNowFee.fees;
208227

209228
listNow.style.removeProperty( 'opacity' );
210-
listNow.dataset.price = listNowPrice;
229+
listNow.dataset.price = listNowPrice.toString();
211230
listNow.addEventListener( 'click', OnQuickSellButtonClick );
212231
listNowText.textContent = i18n.inventory_list_at.replace( '%price%', FormatCurrency( listNowPrice ) );
213232
}
@@ -222,7 +241,7 @@
222241
const sellNowPrice = data.highest_buy_order - sellNowFee.fees;
223242

224243
sellNow.style.removeProperty( 'opacity' );
225-
sellNow.dataset.price = sellNowPrice;
244+
sellNow.dataset.price = sellNowPrice.toString();
226245
sellNow.addEventListener( 'click', OnQuickSellButtonClick );
227246
sellNowText.textContent = i18n.inventory_sell_at.replace( '%price%', FormatCurrency( sellNowPrice ) );
228247
}
@@ -240,8 +259,16 @@
240259
};
241260

242261
let badgesDataLoaded = false;
262+
263+
/** @type {any[]} */
243264
let badgesData = [];
244265

266+
/**
267+
* @param {HTMLElement} element
268+
* @param {any[]} rgActions
269+
* @param {any} item
270+
* @param {string} steamid
271+
*/
245272
function AddBadgeInformation( element, rgActions, item, steamid )
246273
{
247274
if( !item.description.market_fee_app )
@@ -265,6 +292,9 @@
265292
}
266293
}
267294

295+
/**
296+
* @param {boolean} foil
297+
*/
268298
const CreateLink = ( foil ) =>
269299
`https://steamcommunity.com/profiles/${steamid}/gamecards/${item.description.market_fee_app}${foil ? '?border=1' : ''}`;
270300

@@ -321,6 +351,12 @@
321351
}
322352
}
323353

354+
/**
355+
* @param {HTMLElement} element
356+
* @param {any[]} rgActions
357+
* @param {any} item
358+
* @param {string} steamid
359+
*/
324360
function LoadBadgeInformation( element, rgActions, item, steamid )
325361
{
326362
if( badgesDataLoaded )
@@ -374,6 +410,13 @@
374410

375411
const originalPopulateActions = window.PopulateActions;
376412

413+
/**
414+
* @param {any} prefix
415+
* @param {HTMLElement} elActions
416+
* @param {any[]} rgActions
417+
* @param {any} item
418+
* @param {any} owner
419+
*/
377420
window.PopulateActions = function( prefix, elActions, rgActions, item, owner )
378421
{
379422
let foundState = FoundState.None;
@@ -509,6 +552,7 @@
509552
{
510553
giftCache[ item.description.classid ] = xhr.response.packageid;
511554

555+
/** @type {HTMLAnchorElement} */
512556
const link = elActions.querySelector( '.item_actions a[href="#steamdb_' + item.assetid + '"]' );
513557

514558
if( link )
@@ -610,6 +654,7 @@
610654
// We want our links to be open in new tab
611655
if( foundState === FoundState.Added )
612656
{
657+
/** @type {NodeListOf<HTMLAnchorElement>} */
613658
const link = elActions.querySelectorAll( '.item_actions a[href^="' + homepage + '"]' );
614659

615660
if( link )
@@ -622,6 +667,7 @@
622667
}
623668
else if( foundState === FoundState.DisableButtons )
624669
{
670+
/** @type {NodeListOf<HTMLAnchorElement>} */
625671
const link = elActions.querySelectorAll( '.item_actions a[href^="#steamdb_"]' );
626672

627673
if( link )
@@ -635,6 +681,10 @@
635681
}
636682
};
637683

684+
/**
685+
* @param {any} item
686+
* @param {(commodityID: string|null) => void} callback
687+
*/
638688
function GetMarketItemNameId( item, callback )
639689
{
640690
const appid = item.description.appid;
@@ -709,15 +759,30 @@
709759
*/
710760
const itemDatabase = CreateItemStore( 'steamdb_extension', 'itemid_name_cache' );
711761

762+
/**
763+
* Promisifies an IndexedDB request
764+
* @param {IDBRequest<T>|IDBTransaction} request - The IndexedDB request to promisify
765+
* @returns {Promise<T>} A promise that resolves with the request result
766+
* @template T
767+
*/
712768
function PromisifyDbRequest( request )
713769
{
714770
return new Promise( ( resolve, reject ) =>
715771
{
772+
// @ts-ignore
716773
request.oncomplete = request.onsuccess = () => resolve( request.result );
774+
// @ts-ignore
717775
request.onabort = request.onerror = () => reject( request.error );
718776
} );
719777
}
720778

779+
/**
780+
* Creates an IndexedDB store with the specified name
781+
* @param {string} dbName - The name of the database
782+
* @param {string} storeName - The name of the object store
783+
* @returns {function(IDBTransactionMode, function(IDBObjectStore): T|PromiseLike<T>): Promise<T>} A function that executes callbacks against the store
784+
* @template T
785+
*/
721786
function CreateItemStore( dbName, storeName )
722787
{
723788
const request = indexedDB.open( dbName );
@@ -728,7 +793,8 @@
728793

729794
/**
730795
* Get a value by its key.
731-
* @param {string} key
796+
* @param {IDBValidKey} key - The key to look up
797+
* @returns {Promise<string|undefined>} A promise that resolves with the stored value or undefined if not found
732798
*/
733799
function GetCachedItemId( key )
734800
{
@@ -737,8 +803,9 @@
737803

738804
/**
739805
* Set a value with a key.
740-
* @param {string} key
741-
* @param {string} value
806+
* @param {IDBValidKey} key - The key to store the value under
807+
* @param {string} value - The value to store
808+
* @returns {Promise<void>} A promise that resolves when the transaction completes
742809
*/
743810
function SetCachedItemId( key, value )
744811
{

0 commit comments

Comments
 (0)