@@ -29,14 +29,7 @@ if( !accessToken || !applicationConfig )
2929let exploreButton ;
3030/** @type {HTMLElement } */
3131let exploreStatus ;
32- /** @type {HTMLElement } */
33- let itemButton ;
34- /** @type {HTMLElement } */
35- let itemStatus ;
36- /** @type {HTMLImageElement } */
37- let itemImage ;
3832
39- CreateSaleItemContainer ( ) ;
4033CreateExploreContainer ( ) ;
4134
4235function CreateExploreContainer ( )
@@ -81,50 +74,6 @@ function CreateExploreContainer()
8174 } , false ) ;
8275}
8376
84- function CreateSaleItemContainer ( )
85- {
86- const buttonContainer = document . createElement ( 'div' ) ;
87- buttonContainer . className = 'steamdb_saleitem_claim discovery_queue_customize_ctn' ;
88-
89- itemButton = document . createElement ( 'div' ) ;
90- itemButton . className = 'btnv6_blue_hoverfade btn_medium btn_disabled' ;
91- const span = document . createElement ( 'span' ) ;
92- span . textContent = _t ( 'explore_saleitem_claim' ) ;
93- itemButton . append ( span ) ;
94- buttonContainer . append ( itemButton ) ;
95-
96- itemStatus = document . createElement ( 'div' ) ;
97- itemStatus . className = 'steamdb_cheat_queue_text' ;
98- itemStatus . textContent = _t ( 'explore_saleitem_cant_claim' ) ;
99- buttonContainer . append ( itemStatus ) ;
100-
101- itemImage = document . createElement ( 'img' ) ;
102- itemImage . src = GetLocalResource ( 'icons/white.svg' ) ;
103- itemImage . width = 32 ;
104- itemImage . height = 32 ;
105- itemImage . style . opacity = '0' ;
106- buttonContainer . append ( itemImage ) ;
107-
108- const container = document . querySelector ( '.discovery_queue_customize_ctn' ) ;
109- container . parentNode . insertBefore ( buttonContainer , container ) ;
110-
111- itemButton . addEventListener ( 'click' , ( ) =>
112- {
113- if ( itemButton . classList . contains ( 'btn_disabled' ) )
114- {
115- return ;
116- }
117-
118- StartViewTransition ( ( ) =>
119- {
120- itemButton . classList . add ( 'btn_disabled' ) ;
121- ClaimSaleItem ( ) ;
122- } ) ;
123- } , false ) ;
124-
125- CheckClaimSaleItem ( ) ;
126- }
127-
12877function GenerateQueue ( generateFails = 0 )
12978{
13079 const valveQueueEl = document . getElementById ( 'discovery_queue_ctn' ) ;
@@ -258,152 +207,6 @@ function GenerateQueue( generateFails = 0 )
258207 } ) ;
259208}
260209
261- /**
262- * @param {Record<string, any> } response
263- */
264- function HandleSaleItemResponse ( response )
265- {
266- if ( response . next_claim_time )
267- {
268- const dateFormatter = new Intl . DateTimeFormat ( GetLanguage ( ) , {
269- dateStyle : 'medium' ,
270- timeStyle : 'short' ,
271- } ) ;
272- const nextClaimTime = dateFormatter . format ( response . next_claim_time * 1000 ) ;
273-
274- itemStatus . textContent += ' ' + _t ( 'explore_saleitem_next_item_time' , [ nextClaimTime . toLocaleString ( ) ] ) ;
275-
276- const timer = ( response . next_claim_time * 1000 ) - Date . now ( ) ;
277-
278- setTimeout ( ( ) =>
279- {
280- itemStatus . textContent = _t ( 'explore_saleitem_claim_description' ) ;
281- itemButton . classList . remove ( 'btn_disabled' ) ;
282- } , timer ) ;
283- }
284-
285- if ( response . reward_item ?. community_item_data )
286- {
287- const item = response . reward_item . community_item_data ;
288- const file = item . item_image_small || item . item_image_large ;
289- itemImage . src = `${ applicationConfig . MEDIA_CDN_COMMUNITY_URL } images/items/${ response . reward_item . appid } /${ file } ` ;
290- itemImage . title = item . item_title ;
291- itemImage . style . opacity = '1' ;
292- }
293- }
294-
295- function CheckClaimSaleItem ( fails = 0 )
296- {
297- const params = new URLSearchParams ( ) ;
298- params . set ( 'origin' , location . origin ) ;
299- params . set ( 'access_token' , accessToken ) ;
300- params . set ( 'language' , applicationConfig . LANGUAGE ) ;
301-
302- fetch ( `${ applicationConfig . WEBAPI_BASE_URL } ISaleItemRewardsService/CanClaimItem/v1/?${ params . toString ( ) } ` )
303- . then ( ( response ) =>
304- {
305- if ( ! response . ok )
306- {
307- throw new Error ( `HTTP ${ response . status } ` ) ;
308- }
309-
310- return response . json ( ) ;
311- } )
312- . then ( ( data ) =>
313- {
314- const response = data . response ;
315-
316- StartViewTransition ( ( ) =>
317- {
318- if ( response . can_claim )
319- {
320- itemStatus . textContent = _t ( 'explore_saleitem_claim_description' ) ;
321- itemButton . classList . remove ( 'btn_disabled' ) ;
322- return ;
323- }
324-
325- itemStatus . textContent = _t ( 'explore_saleitem_cant_claim' ) ;
326-
327- HandleSaleItemResponse ( response ) ;
328- } ) ;
329- } )
330- . catch ( ( error ) =>
331- {
332- WriteLog ( 'Failed to find out if a sale item can be claimed' , error ) ;
333-
334- if ( ++ fails >= 5 )
335- {
336- itemStatus . textContent = _t ( 'explore_saleitem_cant_claim' ) ;
337- return ;
338- }
339-
340- setTimeout ( ( ) =>
341- {
342- CheckClaimSaleItem ( fails ) ;
343- } , RandomInt ( 5000 , 10000 ) ) ;
344- } ) ;
345- }
346-
347- function ClaimSaleItem ( fails = 0 )
348- {
349- itemStatus . textContent = _t ( 'explore_saleitem_trying_to_claim' ) ;
350-
351- const params = new URLSearchParams ( ) ;
352- params . set ( 'origin' , location . origin ) ;
353- params . set ( 'access_token' , accessToken ) ;
354- params . set ( 'language' , applicationConfig . LANGUAGE ) ;
355-
356- fetch (
357- `${ applicationConfig . WEBAPI_BASE_URL } ISaleItemRewardsService/ClaimItem/v1/?${ params . toString ( ) } ` ,
358- {
359- method : 'POST' ,
360- } ,
361- )
362- . then ( ( response ) =>
363- {
364- if ( ! response . ok )
365- {
366- throw new Error ( `HTTP ${ response . status } ` ) ;
367- }
368-
369- return response . json ( ) ;
370- } )
371- . then ( ( data ) =>
372- {
373- const response = data . response ;
374-
375- if ( ! response || ! response . communityitemid )
376- {
377- fails = 10 ; // If there is no item to claim the response is just empty
378- throw new Error ( 'Unexpected response' ) ;
379- }
380-
381- StartViewTransition ( ( ) =>
382- {
383- const itemTitle = response . reward_item ?. community_item_data ?. item_title ;
384- itemStatus . textContent = _t ( 'explore_saleitem_success' , [ itemTitle || `ID #${ response . communityitemid } ` ] ) ;
385-
386- HandleSaleItemResponse ( response ) ;
387- } ) ;
388- } )
389- . catch ( ( error ) =>
390- {
391- WriteLog ( 'Failed to get a sale item' , error ) ;
392-
393- if ( ++ fails >= 5 )
394- {
395- itemButton . classList . remove ( 'btn_disabled' ) ;
396- itemStatus . textContent = _t ( 'explore_saleitem_claim_failed' ) ;
397- return ;
398- }
399-
400- setTimeout ( ( ) =>
401- {
402- ClaimSaleItem ( fails ) ;
403- } , RandomInt ( 5000 , 10000 ) ) ;
404- } ) ;
405- }
406-
407210/**
408211 * @param {number } min
409212 * @param {number } max
0 commit comments