|
10 | 10 | DisableButtons: 3,
|
11 | 11 | };
|
12 | 12 |
|
| 13 | + /** @type {Record<string, string>} */ |
13 | 14 | const giftCache = {}; // TODO: Store this in indexeddb
|
14 | 15 |
|
15 | 16 | const scriptHook = document.getElementById( 'steamdb_inventory_hook' );
|
|
37 | 38 | {
|
38 | 39 | window.SellCurrentSelection();
|
39 | 40 |
|
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(); |
41 | 44 |
|
42 | 45 | window.SellItemDialog.OnInputKeyUp( null ); // Recalculate prices
|
43 | 46 |
|
44 | 47 | if( options[ 'enhancement-inventory-quick-sell-auto' ] )
|
45 | 48 | {
|
46 | 49 | // 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; |
48 | 53 |
|
49 | 54 | window.SellItemDialog.OnAccept( dummySellEvent );
|
50 | 55 | window.SellItemDialog.OnConfirmationAccept( dummySellEvent );
|
51 | 56 | }
|
52 | 57 | };
|
53 | 58 |
|
54 | 59 | const currencyCode = window.GetCurrencyCode( window.g_rgWalletInfo.wallet_currency );
|
| 60 | + |
| 61 | + /** |
| 62 | + * @param {number} valueInCents |
| 63 | + */ |
55 | 64 | const FormatCurrency = ( valueInCents ) =>
|
56 | 65 | window.v_currencyformat( valueInCents, currencyCode, window.g_rgWalletInfo.wallet_country );
|
57 | 66 |
|
|
61 | 70 | const originalOnSuccess = window.SellItemDialog.OnSuccess;
|
62 | 71 | const originalReloadInventory = window.CUserYou.prototype.ReloadInventory;
|
63 | 72 |
|
| 73 | + /** |
| 74 | + * @param {any} transport |
| 75 | + */ |
64 | 76 | window.SellItemDialog.OnSuccess = function( transport )
|
65 | 77 | {
|
66 | 78 | nextRefreshCausedBySell = true;
|
|
96 | 108 |
|
97 | 109 | const originalBuildHover = window.BuildHover;
|
98 | 110 |
|
| 111 | + /** |
| 112 | + * @param {string} prefix |
| 113 | + */ |
99 | 114 | window.BuildHover = function( prefix )
|
100 | 115 | {
|
101 | 116 | document.querySelector( `#${prefix} .steamdb_quick_sell` )?.remove();
|
|
106 | 121 |
|
107 | 122 | const originalPopulateMarketActions = window.PopulateMarketActions;
|
108 | 123 |
|
| 124 | + /** |
| 125 | + * @param {HTMLElement} elActions |
| 126 | + * @param {any} item |
| 127 | + */ |
109 | 128 | window.PopulateMarketActions = function( elActions, item )
|
110 | 129 | {
|
111 | 130 | const realIsTrading = window.g_bIsTrading;
|
|
134 | 153 | listNow.title = i18n.inventory_list_at_title;
|
135 | 154 | listNow.href = 'javascript:void(0)'; // eslint-disable-line no-script-url
|
136 | 155 | listNow.className = 'btn_small btn_darkblue_white_innerfade';
|
137 |
| - listNow.style.opacity = 0.5; |
| 156 | + listNow.style.opacity = '0.5'; |
138 | 157 | listNow.appendChild( listNowText );
|
139 | 158 |
|
140 | 159 | const sellNowText = document.createElement( 'span' );
|
|
144 | 163 | sellNow.title = i18n.inventory_sell_at_title;
|
145 | 164 | sellNow.href = 'javascript:void(0)'; // eslint-disable-line no-script-url
|
146 | 165 | sellNow.className = 'btn_small btn_darkblue_white_innerfade';
|
147 |
| - sellNow.style.opacity = 0.5; |
| 166 | + sellNow.style.opacity = '0.5'; |
148 | 167 | sellNow.appendChild( sellNowText );
|
149 | 168 |
|
150 | 169 | buttons.appendChild( listNow );
|
|
207 | 226 | const listNowPrice = data.lowest_sell_order - listNowFee.fees;
|
208 | 227 |
|
209 | 228 | listNow.style.removeProperty( 'opacity' );
|
210 |
| - listNow.dataset.price = listNowPrice; |
| 229 | + listNow.dataset.price = listNowPrice.toString(); |
211 | 230 | listNow.addEventListener( 'click', OnQuickSellButtonClick );
|
212 | 231 | listNowText.textContent = i18n.inventory_list_at.replace( '%price%', FormatCurrency( listNowPrice ) );
|
213 | 232 | }
|
|
222 | 241 | const sellNowPrice = data.highest_buy_order - sellNowFee.fees;
|
223 | 242 |
|
224 | 243 | sellNow.style.removeProperty( 'opacity' );
|
225 |
| - sellNow.dataset.price = sellNowPrice; |
| 244 | + sellNow.dataset.price = sellNowPrice.toString(); |
226 | 245 | sellNow.addEventListener( 'click', OnQuickSellButtonClick );
|
227 | 246 | sellNowText.textContent = i18n.inventory_sell_at.replace( '%price%', FormatCurrency( sellNowPrice ) );
|
228 | 247 | }
|
|
240 | 259 | };
|
241 | 260 |
|
242 | 261 | let badgesDataLoaded = false;
|
| 262 | + |
| 263 | + /** @type {any[]} */ |
243 | 264 | let badgesData = [];
|
244 | 265 |
|
| 266 | + /** |
| 267 | + * @param {HTMLElement} element |
| 268 | + * @param {any[]} rgActions |
| 269 | + * @param {any} item |
| 270 | + * @param {string} steamid |
| 271 | + */ |
245 | 272 | function AddBadgeInformation( element, rgActions, item, steamid )
|
246 | 273 | {
|
247 | 274 | if( !item.description.market_fee_app )
|
|
265 | 292 | }
|
266 | 293 | }
|
267 | 294 |
|
| 295 | + /** |
| 296 | + * @param {boolean} foil |
| 297 | + */ |
268 | 298 | const CreateLink = ( foil ) =>
|
269 | 299 | `https://steamcommunity.com/profiles/${steamid}/gamecards/${item.description.market_fee_app}${foil ? '?border=1' : ''}`;
|
270 | 300 |
|
|
321 | 351 | }
|
322 | 352 | }
|
323 | 353 |
|
| 354 | + /** |
| 355 | + * @param {HTMLElement} element |
| 356 | + * @param {any[]} rgActions |
| 357 | + * @param {any} item |
| 358 | + * @param {string} steamid |
| 359 | + */ |
324 | 360 | function LoadBadgeInformation( element, rgActions, item, steamid )
|
325 | 361 | {
|
326 | 362 | if( badgesDataLoaded )
|
|
374 | 410 |
|
375 | 411 | const originalPopulateActions = window.PopulateActions;
|
376 | 412 |
|
| 413 | + /** |
| 414 | + * @param {any} prefix |
| 415 | + * @param {HTMLElement} elActions |
| 416 | + * @param {any[]} rgActions |
| 417 | + * @param {any} item |
| 418 | + * @param {any} owner |
| 419 | + */ |
377 | 420 | window.PopulateActions = function( prefix, elActions, rgActions, item, owner )
|
378 | 421 | {
|
379 | 422 | let foundState = FoundState.None;
|
|
509 | 552 | {
|
510 | 553 | giftCache[ item.description.classid ] = xhr.response.packageid;
|
511 | 554 |
|
| 555 | + /** @type {HTMLAnchorElement} */ |
512 | 556 | const link = elActions.querySelector( '.item_actions a[href="#steamdb_' + item.assetid + '"]' );
|
513 | 557 |
|
514 | 558 | if( link )
|
|
610 | 654 | // We want our links to be open in new tab
|
611 | 655 | if( foundState === FoundState.Added )
|
612 | 656 | {
|
| 657 | + /** @type {NodeListOf<HTMLAnchorElement>} */ |
613 | 658 | const link = elActions.querySelectorAll( '.item_actions a[href^="' + homepage + '"]' );
|
614 | 659 |
|
615 | 660 | if( link )
|
|
622 | 667 | }
|
623 | 668 | else if( foundState === FoundState.DisableButtons )
|
624 | 669 | {
|
| 670 | + /** @type {NodeListOf<HTMLAnchorElement>} */ |
625 | 671 | const link = elActions.querySelectorAll( '.item_actions a[href^="#steamdb_"]' );
|
626 | 672 |
|
627 | 673 | if( link )
|
|
635 | 681 | }
|
636 | 682 | };
|
637 | 683 |
|
| 684 | + /** |
| 685 | + * @param {any} item |
| 686 | + * @param {(commodityID: string|null) => void} callback |
| 687 | + */ |
638 | 688 | function GetMarketItemNameId( item, callback )
|
639 | 689 | {
|
640 | 690 | const appid = item.description.appid;
|
|
709 | 759 | */
|
710 | 760 | const itemDatabase = CreateItemStore( 'steamdb_extension', 'itemid_name_cache' );
|
711 | 761 |
|
| 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 | + */ |
712 | 768 | function PromisifyDbRequest( request )
|
713 | 769 | {
|
714 | 770 | return new Promise( ( resolve, reject ) =>
|
715 | 771 | {
|
| 772 | + // @ts-ignore |
716 | 773 | request.oncomplete = request.onsuccess = () => resolve( request.result );
|
| 774 | + // @ts-ignore |
717 | 775 | request.onabort = request.onerror = () => reject( request.error );
|
718 | 776 | } );
|
719 | 777 | }
|
720 | 778 |
|
| 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 | + */ |
721 | 786 | function CreateItemStore( dbName, storeName )
|
722 | 787 | {
|
723 | 788 | const request = indexedDB.open( dbName );
|
|
728 | 793 |
|
729 | 794 | /**
|
730 | 795 | * 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 |
732 | 798 | */
|
733 | 799 | function GetCachedItemId( key )
|
734 | 800 | {
|
|
737 | 803 |
|
738 | 804 | /**
|
739 | 805 | * 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 |
742 | 809 | */
|
743 | 810 | function SetCachedItemId( key, value )
|
744 | 811 | {
|
|
0 commit comments