Skip to content

Commit a8e1420

Browse files
committed
Add typescript and some jsdoc types
1 parent 9828c60 commit a8e1420

File tree

9 files changed

+169
-51
lines changed

9 files changed

+169
-51
lines changed

options/options.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/**
2-
* @typedef {import('../common')}
3-
*/
4-
51
'use strict';
62

73
( ( () =>

package-lock.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"version": "node version.js",
1212
"test": "eslint . && stylelint \"**/*.css\" && prettier \"**/*.css\" --check",
1313
"test:ext": "web-ext lint",
14+
"test:ts": "tsc",
1415
"fix": "eslint . --fix && stylelint \"**/*.css\" --fix && prettier \"**/*.css\" --write"
1516
},
1617
"devDependencies": {
@@ -21,6 +22,7 @@
2122
"prettier": "^3.3.2",
2223
"stylelint": "^16.5.0",
2324
"stylelint-config-standard": "^37.0.0",
25+
"typescript": "^5.7.3",
2426
"web-ext": "^8.0.0"
2527
},
2628
"repository": {

scripts/background.js

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
'use strict';
22

3+
/** @type {string|null} */
34
let storeSessionId = null;
5+
6+
/** @type {Record<string, any>|null} */
47
let userDataCache = null;
8+
9+
/** @type {Record<string, any>|null} */
510
let userFamilyDataCache = null;
11+
12+
/** @type {Promise<{data: Record<string, any>}|{error: string, data?: Record<string, any>}>|null} */
613
let userFamilySemaphore = null;
714
let nextAllowedRequest = 0;
815

@@ -77,7 +84,7 @@ function InvalidateCache()
7784
}
7885

7986
/**
80-
* @param {Function} callback
87+
* @param {(obj: {data: Record<string, any>}|{error: string, data?: Record<string, any>}) => void} callback
8188
*/
8289
async function FetchSteamUserData( callback )
8390
{
@@ -160,7 +167,7 @@ async function FetchSteamUserData( callback )
160167
}
161168

162169
/**
163-
* @param {Function} callback
170+
* @param {(obj: {data: Record<string, any>}|{error: string, data?: Record<string, any>}) => void} callback
164171
*/
165172
async function FetchSteamUserFamilyData( callback )
166173
{
@@ -326,7 +333,8 @@ function GetJsonWithStatusCheck( response )
326333
}
327334

328335
/**
329-
* @param {Function} callback
336+
* @param {string} appid
337+
* @param {(obj: {success: true}|{success: false, error: string}) => void} callback
330338
*/
331339
function GetApp( appid, callback )
332340
{
@@ -337,7 +345,7 @@ function GetApp( appid, callback )
337345
}
338346

339347
const params = new URLSearchParams();
340-
params.set( 'appid', Number.parseInt( appid, 10 ) );
348+
params.set( 'appid', Number.parseInt( appid, 10 ).toString() );
341349

342350
fetch( `https://steamdb.info/api/ExtensionApp/?${params.toString()}`, {
343351
headers: {
@@ -351,7 +359,10 @@ function GetApp( appid, callback )
351359
}
352360

353361
/**
354-
* @param {Function} callback
362+
* @param {Object} obj
363+
* @param {string} obj.appid
364+
* @param {string} obj.currency
365+
* @param {(obj: {success: true}|{success: false, error: string}) => void} callback
355366
*/
356367
function GetAppPrice( { appid, currency }, callback )
357368
{
@@ -362,7 +373,7 @@ function GetAppPrice( { appid, currency }, callback )
362373
}
363374

364375
const params = new URLSearchParams();
365-
params.set( 'appid', Number.parseInt( appid, 10 ) );
376+
params.set( 'appid', Number.parseInt( appid, 10 ).toString() );
366377
params.set( 'currency', currency );
367378

368379
fetch( `https://steamdb.info/api/ExtensionAppPrice/?${params.toString()}`, {
@@ -377,7 +388,8 @@ function GetAppPrice( { appid, currency }, callback )
377388
}
378389

379390
/**
380-
* @param {Function} callback
391+
* @param {string} appid
392+
* @param {(obj: {success: true}|{success: false, error: string}) => void} callback
381393
*/
382394
function GetAchievementsGroups( appid, callback )
383395
{
@@ -388,7 +400,7 @@ function GetAchievementsGroups( appid, callback )
388400
}
389401

390402
const params = new URLSearchParams();
391-
params.set( 'appid', Number.parseInt( appid, 10 ) );
403+
params.set( 'appid', Number.parseInt( appid, 10 ).toString() );
392404

393405
fetch( `https://steamdb.info/api/ExtensionGetAchievements/?${params.toString()}`, {
394406
headers: {
@@ -402,70 +414,77 @@ function GetAchievementsGroups( appid, callback )
402414
}
403415

404416
/**
405-
* @param {Function} callback
417+
* @param {string} appid
418+
* @param {(obj: {success: true}|{success: false, error: string}) => void} callback
406419
*/
407420
function StoreWishlistAdd( appid, callback )
408421
{
409422
const formData = new FormData();
410-
formData.set( 'appid', Number.parseInt( appid, 10 ) );
423+
formData.set( 'appid', Number.parseInt( appid, 10 ).toString() );
411424
ExecuteStoreApiCall( 'api/addtowishlist', formData, callback );
412425
}
413426

414427
/**
415-
* @param {Function} callback
428+
* @param {string} appid
429+
* @param {(obj: {success: true}|{success: false, error: string}) => void} callback
416430
*/
417431
function StoreWishlistRemove( appid, callback )
418432
{
419433
const formData = new FormData();
420-
formData.set( 'appid', Number.parseInt( appid, 10 ) );
434+
formData.set( 'appid', Number.parseInt( appid, 10 ).toString() );
421435
ExecuteStoreApiCall( 'api/removefromwishlist', formData, callback );
422436
}
423437

424438
/**
425-
* @param {Function} callback
439+
* @param {string} appid
440+
* @param {(obj: {success: true}|{success: false, error: string}) => void} callback
426441
*/
427442
function StoreFollow( appid, callback )
428443
{
429444
const formData = new FormData();
430-
formData.set( 'appid', Number.parseInt( appid, 10 ) );
445+
formData.set( 'appid', Number.parseInt( appid, 10 ).toString() );
431446
ExecuteStoreApiCall( 'explore/followgame/', formData, callback );
432447
}
433448

434449
/**
435-
* @param {Function} callback
450+
* @param {string} appid
451+
* @param {(obj: {success: true}|{success: false, error: string}) => void} callback
436452
*/
437453
function StoreUnfollow( appid, callback )
438454
{
439455
const formData = new FormData();
440-
formData.set( 'appid', Number.parseInt( appid, 10 ) );
441-
formData.set( 'unfollow', 1 );
456+
formData.set( 'appid', Number.parseInt( appid, 10 ).toString() );
457+
formData.set( 'unfollow', '1' );
442458
ExecuteStoreApiCall( 'explore/followgame/', formData, callback );
443459
}
444460

445461
/**
446-
* @param {Function} callback
462+
* @param {string} appid
463+
* @param {(obj: {success: true}|{success: false, error: string}) => void} callback
447464
*/
448465
function StoreIgnore( appid, callback )
449466
{
450467
const formData = new FormData();
451-
formData.set( 'appid', Number.parseInt( appid, 10 ) );
452-
formData.set( 'ignore_reason', 0 );
468+
formData.set( 'appid', Number.parseInt( appid, 10 ).toString() );
469+
formData.set( 'ignore_reason', '0' );
453470
ExecuteStoreApiCall( 'recommended/ignorerecommendation/', formData, callback );
454471
}
455472

456473
/**
457-
* @param {Function} callback
474+
* @param {string} appid
475+
* @param {(obj: {success: true}|{success: false, error: string}) => void} callback
458476
*/
459477
function StoreUnignore( appid, callback )
460478
{
461479
const formData = new FormData();
462-
formData.set( 'appid', Number.parseInt( appid, 10 ) );
463-
formData.set( 'remove', 1 );
480+
formData.set( 'appid', Number.parseInt( appid, 10 ).toString() );
481+
formData.set( 'remove', '1' );
464482
ExecuteStoreApiCall( 'recommended/ignorerecommendation/', formData, callback );
465483
}
466484

467485
/**
468-
* @param {Function} callback
486+
* @param {Record<string, string>} request
487+
* @param {(obj: {success: true}|{success: false, error: string}) => void} callback
469488
*/
470489
function StoreAddToCart( request, callback )
471490
{
@@ -474,11 +493,11 @@ function StoreAddToCart( request, callback )
474493

475494
if( request.subid )
476495
{
477-
formData.set( 'subid', Number.parseInt( request.subid, 10 ) );
496+
formData.set( 'subid', Number.parseInt( request.subid, 10 ).toString() );
478497
}
479498
else if( request.bundleid )
480499
{
481-
formData.set( 'bundleid', Number.parseInt( request.bundleid, 10 ) );
500+
formData.set( 'bundleid', Number.parseInt( request.bundleid, 10 ).toString() );
482501
}
483502
else
484503
{
@@ -489,7 +508,8 @@ function StoreAddToCart( request, callback )
489508
}
490509

491510
/**
492-
* @param {Function} callback
511+
* @param {Record<string, string>} request
512+
* @param {(obj: {success: true}|{success: false, error: string, resultCode: number}) => void} callback
493513
*/
494514
function StoreAddFreeLicense( request, callback )
495515
{
@@ -545,21 +565,23 @@ function StoreAddFreeLicense( request, callback )
545565
}
546566

547567
/**
548-
* @param {Function} callback
568+
* @param {Record<string, string>} request
569+
* @param {(obj: {success: true}|{success: false, error: string}) => void} callback
549570
*/
550571
function StoreRemoveFreeLicense( request, callback )
551572
{
552573
if( request.subid )
553574
{
554575
const subid = Number.parseInt( request.subid, 10 );
555576
const formData = new FormData();
556-
formData.set( 'packageid', subid );
577+
formData.set( 'packageid', subid.toString() );
557578
ExecuteStoreApiCall( 'account/removelicense', formData, callback );
558579
}
559580
}
560581

561582
/**
562-
* @param {Function} callback
583+
* @param {Record<string, string>} request
584+
* @param {(obj: {success: boolean, granted: boolean}) => void} callback
563585
*/
564586
function StoreRequestPlaytestAccess( request, callback )
565587
{
@@ -590,7 +612,9 @@ function StoreRequestPlaytestAccess( request, callback )
590612
}
591613

592614
/**
593-
* @param {Function} callback
615+
* @param {string} path
616+
* @param {FormData} formData
617+
* @param {(obj: {success: true}|{success: false, error: string}) => void} callback
594618
*/
595619
function ExecuteStoreApiCall( path, formData, callback, rawCallback = false )
596620
{
@@ -673,7 +697,7 @@ function ExecuteStoreApiCall( path, formData, callback, rawCallback = false )
673697
}
674698

675699
/**
676-
* @param {Function} callback
700+
* @param {(obj: {success: true, sessionID: string}|{success: false, error: string}) => void} callback
677701
*/
678702
function GetStoreSessionID( callback )
679703
{

scripts/common.d.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
declare var ExtensionApi: browser;
2+
3+
declare var CurrentAppID: number;
4+
5+
declare function GetCurrentAppID(): number;
6+
7+
declare function GetHomepage(): string;
8+
9+
declare function _t(message: string, substitutions?: string[]): string;
10+
11+
declare function GetLanguage(): string;
12+
13+
declare type GetOptionCallback = (items: { [key: string]: any }) => void;
14+
15+
declare function GetOption(items: { [key: string]: any }, callback: GetOptionCallback): void;
16+
17+
declare function SetOption(option: string, value: any): void;
18+
19+
declare function GetLocalResource(res: string): string;
20+
21+
declare type SendMessageToBackgroundScriptResponse = {
22+
success: boolean;
23+
error?: string;
24+
data?: any;
25+
};
26+
27+
declare type SendMessageToBackgroundScriptCallback = (data: SendMessageToBackgroundScriptResponse | undefined) => void;
28+
29+
declare function SendMessageToBackgroundScript(
30+
message: { contentScriptQuery: string, [key: string]: any },
31+
callback: SendMessageToBackgroundScriptCallback
32+
): void;
33+
34+
declare function WriteLog(...args: any[]): void;

scripts/common.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* exported _t, ExtensionApi, GetCurrentAppID, GetHomepage, GetOption, GetLocalResource, SendMessageToBackgroundScript, SetOption, WriteLog */
1+
/* exported _t, ExtensionApi, GetCurrentAppID, GetHomepage, GetOption, GetLanguage, GetLocalResource, SendMessageToBackgroundScript, SetOption, WriteLog */
22

33
'use strict';
44

@@ -19,6 +19,7 @@ var ExtensionApi = ( () =>
1919
} )();
2020

2121
// exported variable needs to be `var`
22+
/** @type {number|undefined} */
2223
// eslint-disable-next-line no-var
2324
var CurrentAppID;
2425

@@ -98,11 +99,11 @@ function GetLocalResource( res )
9899

99100
/**
100101
* @callback SendMessageToBackgroundScriptCallback
101-
* @param {{success: Boolean, error?: String}?} data
102+
* @param {{success: Boolean, error?: String, data?: any}?} data
102103
*/
103104

104105
/**
105-
* @param {String} message
106+
* @param {{contentScriptQuery: string, [key: string]: any}} message
106107
* @param {SendMessageToBackgroundScriptCallback} callback
107108
*/
108109
function SendMessageToBackgroundScript( message, callback )

scripts/steamdb/global.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/**
2-
* @typedef {import('../common')}
3-
*/
4-
51
'use strict';
62

73
const EXTENSION_INTEROP_VERSION = 2;

0 commit comments

Comments
 (0)