From a9fa5afb45d12fa6d6c582272aa0820b592bc66b Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Wed, 17 Jul 2024 14:47:50 +0300 Subject: [PATCH 1/2] Add progress bar for market operations --- code.user.js | 103 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 70 insertions(+), 33 deletions(-) diff --git a/code.user.js b/code.user.js index 07df220..acb3826 100644 --- a/code.user.js +++ b/code.user.js @@ -2405,6 +2405,20 @@ //#region Market if (currentPage == PAGE_MARKET || currentPage == PAGE_MARKET_LISTING) { var marketListingsRelistedAssets = []; + let marketProgressBar; + + function increaseMarketProgressMax() { + marketProgressBar.max += 1; + marketProgressBar.removeAttribute('hidden'); + } + + function increaseMarketProgress() { + marketProgressBar.value += 1; + + if (marketProgressBar.value === marketProgressBar.max) { + marketProgressBar.setAttribute('hidden', 'true'); + } + } var marketListingsQueue = async.queue(function(listing, next) { marketListingsQueueWorker(listing, @@ -2412,18 +2426,20 @@ function(success, cached) { if (success) { setTimeout(function() { - next(); - }, - cached ? 0 : getRandomInt(1000, 1500)); + increaseMarketProgress(); + next(); + }, + cached ? 0 : getRandomInt(1000, 1500)); } else { setTimeout(function() { - marketListingsQueueWorker(listing, - true, - function(success, cached) { - next(); // Go to the next queue item, regardless of success. - }); - }, - cached ? 0 : getRandomInt(30000, 45000)); + marketListingsQueueWorker(listing, + true, + function(success, cached) { + increaseMarketProgress(); + next(); // Go to the next queue item, regardless of success. + }); + }, + cached ? 0 : getRandomInt(30000, 45000)); } }); }, 1); @@ -2613,18 +2629,20 @@ function(success) { if (success) { setTimeout(function() { - next(); - }, - getRandomInt(1000, 1500)); + increaseMarketProgress(); + next(); + }, + getRandomInt(1000, 1500)); } else { setTimeout(function() { - marketOverpricedQueueWorker(item, - true, - function(success) { - next(); // Go to the next queue item, regardless of success. - }); - }, - getRandomInt(30000, 45000)); + marketOverpricedQueueWorker(item, + true, + function(success) { + increaseMarketProgress(); + next(); // Go to the next queue item, regardless of success. + }); + }, + getRandomInt(30000, 45000)); } }); }, @@ -2714,6 +2732,7 @@ appid: assetInfo.appid, sellPrice: price }); + increaseMarketProgressMax(); } } @@ -2723,18 +2742,20 @@ function(success) { if (success) { setTimeout(function() { - next(); - }, - getRandomInt(50, 100)); + increaseMarketProgress(); + next(); + }, + getRandomInt(50, 100)); } else { setTimeout(function() { - marketRemoveQueueWorker(listingid, - true, - function(success) { - next(); // Go to the next queue item, regardless of success. - }); - }, - getRandomInt(30000, 45000)); + marketRemoveQueueWorker(listingid, + true, + function(success) { + increaseMarketProgress(); + next(); // Go to the next queue item, regardless of success. + }); + }, + getRandomInt(30000, 45000)); } }); }, @@ -2775,6 +2796,7 @@ $.get(window.location.origin + '/market/mylistings?count=100&start=' + listing, function(data) { if (!data || !data.success) { + increaseMarketProgress(); next(); return; } @@ -2788,10 +2810,12 @@ // g_rgAssets unsafeWindow.MergeWithAssetArray(data.assets); // This is a method from Steam. + increaseMarketProgress(); next(); }, 'json') .fail(function(data) { + increaseMarketProgress(); next(); return; }); @@ -2873,6 +2897,7 @@ contextid: assetInfo.contextid, assetid: assetInfo.assetid }); + increaseMarketProgressMax(); } } @@ -2949,9 +2974,13 @@ page: pageSize, }; - var list = new List(market_listing_see.parent().attr('id'), options); - list.on('searchComplete', updateMarketSelectAllButton); - marketLists.push(list); + try { + var list = new List(market_listing_see.parent().get(0), options); + list.on('searchComplete', updateMarketSelectAllButton); + marketLists.push(list); + } catch (e) { + console.error(e); + } } // Adds checkboxes to market listings. @@ -3005,6 +3034,7 @@ while (currentCount < totalCount) { marketListingsItemsQueue.push(currentCount); + increaseMarketProgressMax(); currentCount += 100; } } else { @@ -3043,6 +3073,7 @@ contextid: assetInfo.contextid, assetid: assetInfo.assetid }); + increaseMarketProgressMax(); }) } } @@ -3190,6 +3221,9 @@ // Initialize the market UI. function initializeMarketUI() { + $('.market_header_text').append('