From b0a9c28d93b764a54382046e5073e664602c233f Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Thu, 25 Jul 2024 16:06:45 +0300 Subject: [PATCH 01/20] add delay-between-market-actions ui elements --- code.user.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/code.user.js b/code.user.js index 077562e..ede36b1 100644 --- a/code.user.js +++ b/code.user.js @@ -148,6 +148,7 @@ const SETTING_LAST_CACHE = 'SETTING_LAST_CACHE'; const SETTING_RELIST_AUTOMATICALLY = 'SETTING_RELIST_AUTOMATICALLY'; const SETTING_MARKET_PAGE_COUNT = 'SETTING_MARKET_PAGE_COUNT'; + const SETTING_DELAY_BETWEEN_MARKET_ACTIONS = 'SETTING_DELAY_BETWEEN_MARKET_ACTIONS'; const settingDefaults = { SETTING_MIN_NORMAL_PRICE: 0.05, @@ -166,7 +167,8 @@ SETTING_QUICK_SELL_BUTTONS: 1, SETTING_LAST_CACHE: 0, SETTING_RELIST_AUTOMATICALLY: 0, - SETTING_MARKET_PAGE_COUNT: 100 + SETTING_MARKET_PAGE_COUNT: 100, + SETTING_DELAY_BETWEEN_MARKET_ACTIONS: 0 }; function getSettingWithDefault(name) { @@ -3810,6 +3812,10 @@ Market items per page:  +
+ Delay in seconds between market actions:  + +
Automatically relist overpriced market listings (slow on large inventories):  @@ -3829,6 +3835,7 @@ setSetting(SETTING_PRICE_IGNORE_LOWEST_Q, $(`#${SETTING_PRICE_IGNORE_LOWEST_Q}`, price_options).prop('checked') ? 1 : 0); setSetting(SETTING_PRICE_HISTORY_HOURS, $(`#${SETTING_PRICE_HISTORY_HOURS}`, price_options).val()); setSetting(SETTING_MARKET_PAGE_COUNT, $(`#${SETTING_MARKET_PAGE_COUNT}`, price_options).val()); + setSetting(SETTING_DELAY_BETWEEN_MARKET_ACTIONS, $(`#${SETTING_DELAY_BETWEEN_MARKET_ACTIONS}`, price_options).val()); setSetting(SETTING_RELIST_AUTOMATICALLY, $(`#${SETTING_RELIST_AUTOMATICALLY}`, price_options).prop('checked') ? 1 : 0); setSetting(SETTING_INVENTORY_PRICE_LABELS, $(`#${SETTING_INVENTORY_PRICE_LABELS}`, price_options).prop('checked') ? 1 : 0); setSetting(SETTING_TRADEOFFER_PRICE_LABELS, $(`#${SETTING_TRADEOFFER_PRICE_LABELS}`, price_options).prop('checked') ? 1 : 0); From 7b5c503a37ac1ef47935afdce8bf5daff5f775e2 Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Thu, 25 Jul 2024 19:49:53 +0300 Subject: [PATCH 02/20] add delay-between-market-actions logic --- code.user.js | 171 ++++++++++++++++++++------------------------------- 1 file changed, 67 insertions(+), 104 deletions(-) diff --git a/code.user.js b/code.user.js index ede36b1..1a491cf 100644 --- a/code.user.js +++ b/code.user.js @@ -1252,7 +1252,11 @@ css('background', COLOR_ERROR); } - next(); + const delay = sellQueue.length() > 0 + ? Math.max(parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000, 0) + : 0; + + setTimeout(() => next(), delay); } ); }, @@ -1724,33 +1728,22 @@ item, item.ignoreErrors, (success, cached) => { + let delay = parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000; + if (success) { - setTimeout( - () => { - next(); - }, - cached ? 0 : getRandomInt(1000, 1500) - ); + delay = Math.max(delay, getRandomInt(1000, 1500)); + setTimeout(() => next(), cached ? 0 : delay); } else { if (!item.ignoreErrors) { item.ignoreErrors = true; itemQueue.push(item); } - const delay = numberOfFailedRequests > 1 - ? getRandomInt(30000, 45000) - : getRandomInt(1000, 1500); + delay = Math.max(delay, numberOfFailedRequests > 1 ? getRandomInt(30000, 45000) : getRandomInt(1000, 1500)); - if (numberOfFailedRequests > 3) { - numberOfFailedRequests = 0; - } + numberOfFailedRequests = numberOfFailedRequests > 3 ? 0 : numberOfFailedRequests; - setTimeout( - () => { - next(); - }, - cached ? 0 : delay - ); + setTimeout(() => next(), cached ? 0 : delay); } } ); @@ -2412,13 +2405,11 @@ item, false, (success, cached) => { + let delay = parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000; + if (success) { - setTimeout( - () => { - next(); - }, - cached ? 0 : getRandomInt(1000, 1500) - ); + delay = Math.max(delay, getRandomInt(1000, 1500)); + setTimeout(() => next(), cached ? 0 : delay); } else { if (!item.ignoreErrors) { item.ignoreErrors = true; @@ -2427,17 +2418,11 @@ numberOfFailedRequests++; - const delay = numberOfFailedRequests > 1 - ? getRandomInt(30000, 45000) - : getRandomInt(1000, 1500); + delay = Math.max(delay, numberOfFailedRequests > 1 ? getRandomInt(30000, 45000) : getRandomInt(1000, 1500)); - if (numberOfFailedRequests > 3) { - numberOfFailedRequests = 0; - } + numberOfFailedRequests = numberOfFailedRequests > 3 ? 0 : numberOfFailedRequests; - setTimeout(() => { - next(); - }, cached ? 0 : delay); + setTimeout(() => next(), cached ? 0 : delay); } } ); @@ -2516,28 +2501,19 @@ listing, false, (success, cached) => { + let delay = parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000; + + const callback = () => { + increaseMarketProgress(); + next(); + } + if (success) { - setTimeout( - () => { - increaseMarketProgress(); - next(); - }, - cached ? 0 : getRandomInt(1000, 1500) - ); + delay = marketListingsQueue.length() > 0 ? Math.max(delay, getRandomInt(1000, 1500)) : 0; + setTimeout(callback, cached ? 0 : delay); } else { - setTimeout( - () => { - marketListingsQueueWorker( - listing, - true, - () => { - increaseMarketProgress(); - next(); // Go to the next queue item, regardless of success. - } - ); - }, - cached ? 0 : getRandomInt(30000, 45000) - ); + delay = marketListingsQueue.length() > 0 ? Math.max(delay, getRandomInt(30000, 45000)) : 0; + setTimeout(() => marketListingsQueueWorker(listing, true, callback), cached ? 0 : delay); } } ); @@ -2722,28 +2698,19 @@ item, false, (success) => { + let delay = parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000; + + const callback = () => { + increaseMarketProgress(); + next(); + }; + if (success) { - setTimeout( - () => { - increaseMarketProgress(); - next(); - }, - getRandomInt(1000, 1500) - ); + delay = marketOverpricedQueue.length() > 0 ? Math.max(delay, getRandomInt(1000, 1500)) : 0; + setTimeout(callback, delay); } else { - setTimeout( - () => { - marketOverpricedQueueWorker( - item, - true, - () => { - increaseMarketProgress(); - next(); // Go to the next queue item, regardless of success. - } - ); - }, - getRandomInt(30000, 45000) - ); + delay = Math.max(delay, getRandomInt(30000, 45000)); + setTimeout(marketOverpricedQueueWorker(item, true, callback), delay); } } ); @@ -2850,33 +2817,24 @@ listingid, false, (success) => { + let delay = parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000; + + const callback = () => { + increaseMarketProgress(); + next(); + }; + if (success) { - setTimeout( - () => { - increaseMarketProgress(); - next(); - }, - getRandomInt(50, 100) - ); + delay = marketRemoveQueue.length() > 0 ? Math.max(delay, getRandomInt(50, 100)) : 0; + setTimeout(callback, delay); } else { - setTimeout( - () => { - marketRemoveQueueWorker( - listingid, - true, - () => { - increaseMarketProgress(); - next(); // Go to the next queue item, regardless of success. - } - ); - }, - getRandomInt(30000, 45000) - ); + delay = Math.max(delay, getRandomInt(30000, 45000)); + setTimeout(() => marketRemoveQueueWorker(listingid, true, callback), delay); } } ); }, - 10 + 1 ); function marketRemoveQueueWorker(listingid, ignoreErrors, callback) { @@ -2916,12 +2874,20 @@ const marketListingsItemsQueue = async.queue( (listing, next) => { + const callback = () => { + const delay = marketListingsItemsQueue.length() > 0 + ? parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000 + : 0; + + increaseMarketProgress(); + setTimeout(() => next(), delay); + }; + $.get( `${window.location.origin}/market/mylistings?count=100&start=${listing}`, (data) => { if (!data || !data.success) { - increaseMarketProgress(); - next(); + callback(); return; } @@ -2934,16 +2900,13 @@ // g_rgAssets unsafeWindow.MergeWithAssetArray(data.assets); // This is a method from Steam. - increaseMarketProgress(); - next(); + callback() }, 'json' - ). - fail(() => { - increaseMarketProgress(); - next(); + ).fail(() => { + callback(); return; - }); + }); }, 1 ); From a4bfcb6a555144dacf4414e5037f28243627714a Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Thu, 25 Jul 2024 20:24:47 +0300 Subject: [PATCH 03/20] tweaks --- code.user.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/code.user.js b/code.user.js index 1a491cf..cf4c832 100644 --- a/code.user.js +++ b/code.user.js @@ -1728,7 +1728,7 @@ item, item.ignoreErrors, (success, cached) => { - let delay = parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000; + let delay = 0; if (success) { delay = Math.max(delay, getRandomInt(1000, 1500)); @@ -2405,7 +2405,7 @@ item, false, (success, cached) => { - let delay = parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000; + let delay = 0; if (success) { delay = Math.max(delay, getRandomInt(1000, 1500)); @@ -2501,7 +2501,7 @@ listing, false, (success, cached) => { - let delay = parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000; + let delay = 0; const callback = () => { increaseMarketProgress(); @@ -2875,9 +2875,7 @@ const marketListingsItemsQueue = async.queue( (listing, next) => { const callback = () => { - const delay = marketListingsItemsQueue.length() > 0 - ? parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000 - : 0; + let delay = 0; increaseMarketProgress(); setTimeout(() => next(), delay); From 59e54a261fc41ccd9eecc7816f9d9fe923d10ce2 Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Thu, 25 Jul 2024 20:28:27 +0300 Subject: [PATCH 04/20] tweaks --- code.user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code.user.js b/code.user.js index cf4c832..3564b87 100644 --- a/code.user.js +++ b/code.user.js @@ -1253,7 +1253,7 @@ } const delay = sellQueue.length() > 0 - ? Math.max(parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000, 0) + ? parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000 : 0; setTimeout(() => next(), delay); From 69c7f0f23e681cb7213a5d7afe6b5b2a46eb124d Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Fri, 26 Jul 2024 11:04:49 +0300 Subject: [PATCH 05/20] tweaks --- code.user.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code.user.js b/code.user.js index 3564b87..e89d31b 100644 --- a/code.user.js +++ b/code.user.js @@ -1253,7 +1253,7 @@ } const delay = sellQueue.length() > 0 - ? parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000 + ? (parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000 || 0) : 0; setTimeout(() => next(), delay); @@ -2698,7 +2698,7 @@ item, false, (success) => { - let delay = parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000; + let delay = (parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000 || 0); const callback = () => { increaseMarketProgress(); @@ -2817,7 +2817,7 @@ listingid, false, (success) => { - let delay = parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000; + let delay = (parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000 || 0); const callback = () => { increaseMarketProgress(); From da1a11e4569b95b95f31d92eb9e9a4659242c433 Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Fri, 26 Jul 2024 11:41:19 +0300 Subject: [PATCH 06/20] tweaks --- code.user.js | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/code.user.js b/code.user.js index e89d31b..a56c87d 100644 --- a/code.user.js +++ b/code.user.js @@ -61,6 +61,7 @@ const spinnerBlock = '
 
 
 
 
 
'; let numberOfFailedRequests = 0; + let marketRateLimitReached = false; const enableConsoleLog = false; @@ -467,6 +468,13 @@ error: function(data) { return callback(ERROR_FAILED, data); }, + statusCode: { + 200: () => (marketRateLimitReached = false), + 429: () => (marketRateLimitReached = true), + 500: () => (marketRateLimitReached = false), + 501: () => (marketRateLimitReached = false), + 502: () => (marketRateLimitReached = false) + }, dataType: 'json' }); }; @@ -490,6 +498,13 @@ error: function() { return callback(ERROR_FAILED); }, + statusCode: { + 200: () => (marketRateLimitReached = false), + 429: () => (marketRateLimitReached = true), + 500: () => (marketRateLimitReached = false), + 501: () => (marketRateLimitReached = false), + 502: () => (marketRateLimitReached = false) + }, dataType: 'json' }); return; @@ -507,6 +522,13 @@ error: function() { return callback(ERROR_FAILED); }, + statusCode: { + 200: () => (marketRateLimitReached = false), + 429: () => (marketRateLimitReached = true), + 500: () => (marketRateLimitReached = false), + 501: () => (marketRateLimitReached = false), + 502: () => (marketRateLimitReached = false) + }, dataType: 'json' }); }; @@ -1252,9 +1274,9 @@ css('background', COLOR_ERROR); } - const delay = sellQueue.length() > 0 - ? (parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000 || 0) - : 0; + let delay = parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000 || 0; + delay = marketRateLimitReached ? Math.max(delay, getRandomInt(90000, 150000)) : delay; + delay = sellQueue.length() > 0 ? delay : 0; setTimeout(() => next(), delay); } @@ -2698,7 +2720,10 @@ item, false, (success) => { - let delay = (parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000 || 0); + let delay = parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000 || 0; + delay = delay || getRandomInt(1000, 1500); + delay = marketRateLimitReached ? Math.max(delay, getRandomInt(90000, 150000)) : delay; + delay = marketOverpricedQueue.length() > 0 ? delay : 0 const callback = () => { increaseMarketProgress(); @@ -2706,7 +2731,6 @@ }; if (success) { - delay = marketOverpricedQueue.length() > 0 ? Math.max(delay, getRandomInt(1000, 1500)) : 0; setTimeout(callback, delay); } else { delay = Math.max(delay, getRandomInt(30000, 45000)); @@ -2817,7 +2841,10 @@ listingid, false, (success) => { - let delay = (parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000 || 0); + let delay = parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000 || 0; + delay = delay || getRandomInt(50, 100); + delay = marketRateLimitReached ? Math.max(delay, getRandomInt(90000, 150000)) : delay; + delay = marketRemoveQueue.length() > 0 ? delay : 0 const callback = () => { increaseMarketProgress(); @@ -2825,7 +2852,6 @@ }; if (success) { - delay = marketRemoveQueue.length() > 0 ? Math.max(delay, getRandomInt(50, 100)) : 0; setTimeout(callback, delay); } else { delay = Math.max(delay, getRandomInt(30000, 45000)); From ab67c2dd973f07608b551862711ae1de1e98bb96 Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Fri, 26 Jul 2024 11:46:24 +0300 Subject: [PATCH 07/20] lint --- code.user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code.user.js b/code.user.js index a56c87d..51289a6 100644 --- a/code.user.js +++ b/code.user.js @@ -2901,7 +2901,7 @@ const marketListingsItemsQueue = async.queue( (listing, next) => { const callback = () => { - let delay = 0; + const delay = 0; increaseMarketProgress(); setTimeout(() => next(), delay); From abfda653bf274f30f3d228668c6f5a1c4892a585 Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Fri, 26 Jul 2024 13:36:00 +0300 Subject: [PATCH 08/20] tweaks --- code.user.js | 151 +++++++++++++++++++++++---------------------------- 1 file changed, 68 insertions(+), 83 deletions(-) diff --git a/code.user.js b/code.user.js index 51289a6..8560251 100644 --- a/code.user.js +++ b/code.user.js @@ -458,22 +458,18 @@ amount: 1, price: price }, - success: function(data) { - if (data.success === false && isRetryMessage(data.message)) { + success: function(data, status, xhr) { + marketRateLimitReached = xhr.status === 429; + + if (data && data.success === false && isRetryMessage(data.message)) { callback(ERROR_FAILED, data); } else { callback(ERROR_SUCCESS, data); } }, - error: function(data) { - return callback(ERROR_FAILED, data); - }, - statusCode: { - 200: () => (marketRateLimitReached = false), - 429: () => (marketRateLimitReached = true), - 500: () => (marketRateLimitReached = false), - 501: () => (marketRateLimitReached = false), - 502: () => (marketRateLimitReached = false) + error: function(xhr) { + marketRateLimitReached = xhr.status === 429; + return callback(ERROR_FAILED, xhr); }, dataType: 'json' }); @@ -482,53 +478,28 @@ // Removes an item. // Item is the unique item id. SteamMarket.prototype.removeListing = function(item, isBuyOrder, callback /*err, data*/) { - const sessionId = readCookie('sessionid'); + const url = isBuyOrder + ? `${window.location.origin}/market/cancelbuyorder/` + : `${window.location.origin}/market/removelisting/${item}`; - if (isBuyOrder) { - $.ajax({ - type: 'POST', - url: `${window.location.origin}/market/cancelbuyorder/`, - data: { - sessionid: sessionId, - buy_orderid: item - }, - success: function(data) { - callback(ERROR_SUCCESS, data); - }, - error: function() { - return callback(ERROR_FAILED); - }, - statusCode: { - 200: () => (marketRateLimitReached = false), - 429: () => (marketRateLimitReached = true), - 500: () => (marketRateLimitReached = false), - 501: () => (marketRateLimitReached = false), - 502: () => (marketRateLimitReached = false) - }, - dataType: 'json' - }); - return; + const data = { sessionid: readCookie('sessionid') }; + + if (isBuyOrder) { + data.buy_orderid = item; } $.ajax({ type: 'POST', - url: `${window.location.origin}/market/removelisting/${item}`, - data: { - sessionid: sessionId - }, - success: function(data) { + url: url, + data: data, + success: function(data, status, xhr) { + marketRateLimitReached = xhr.status === 429; callback(ERROR_SUCCESS, data); }, - error: function() { + error: function(xhr) { + marketRateLimitReached = xhr.status === 429; return callback(ERROR_FAILED); }, - statusCode: { - 200: () => (marketRateLimitReached = false), - 429: () => (marketRateLimitReached = true), - 500: () => (marketRateLimitReached = false), - 501: () => (marketRateLimitReached = false), - 502: () => (marketRateLimitReached = false) - }, dataType: 'json' }); }; @@ -688,11 +659,12 @@ // Get the current price history for an item. SteamMarket.prototype.getCurrentPriceHistory = function(appid, market_name, callback) { - const url = `${window.location.origin}/market/pricehistory/?appid=${appid}&market_hash_name=${market_name}`; - - $.get( - url, - (data) => { + $.ajax({ + type: 'GET', + url: `${window.location.origin}/market/pricehistory/?appid=${appid}&market_hash_name=${market_name}`, + success: function(data, status, xhr) { + marketRateLimitReached = xhr.status === 429; + if (!data || !data.success || !data.prices) { callback(ERROR_DATA); return; @@ -710,18 +682,20 @@ callback(ERROR_SUCCESS, data.prices, false); }, - 'json' - ). - fail((data) => { - if (!data || !data.responseJSON) { + error: function(xhr) { + marketRateLimitReached = xhr.status === 429; + + if (!xhr || !xhr.responseJSON) { return callback(ERROR_FAILED); } - if (!data.responseJSON.success) { + if (!xhr.responseJSON.success) { callback(ERROR_DATA); return; } return callback(ERROR_FAILED); - }); + }, + dataType: 'json' + }); }; // Get the item name id from a market item. @@ -756,11 +730,13 @@ // Get the item name id from a market item. SteamMarket.prototype.getCurrentMarketItemNameId = function(appid, market_name, callback) { - const url = `${window.location.origin}/market/listings/${appid}/${market_name}`; - $.get( - url, - (page) => { - const matches = (/Market_LoadOrderSpread\( (\d+) \);/).exec(page); + $.ajax({ + type: 'GET', + url: `${window.location.origin}/market/listings/${appid}/${market_name}`, + success: function(page, status, xhr) { + marketRateLimitReached = xhr.status === 429; + + const matches = (/Market_LoadOrderSpread\( (\d+) \);/).exec(page || ''); if (matches == null) { callback(ERROR_DATA); return; @@ -773,11 +749,12 @@ storagePersistent.setItem(storage_hash, item_nameid); callback(ERROR_SUCCESS, item_nameid); + }, + error: function(xhr) { + marketRateLimitReached = xhr.status === 429; + return callback(ERROR_FAILED, xhr.status); } - ). - fail((e) => { - return callback(ERROR_FAILED, e.status); - }); + }); }; // Get the sales listings for this item in the market, with more information. @@ -845,19 +822,23 @@ } const url = `${window.location.origin}/market/itemordershistogram?country=${country}&language=english¤cy=${currencyId}&item_nameid=${item_nameid}&two_factor=0`; - $.get( - url, - (histogram) => { + $.ajax({ + type: 'GET', + url: url, + success: function(histogram, status, xhr) { + marketRateLimitReached = xhr.status === 429; + // Store the histogram in the session storage. const storage_hash = `itemordershistogram_${item.appid}+${market_name}`; storageSession.setItem(storage_hash, histogram); callback(ERROR_SUCCESS, histogram, false); - } - ). - fail(() => { + }, + error: function(xhr) { + marketRateLimitReached = xhr.status === 429; return callback(ERROR_FAILED, null); - }); + } + }); } ); }; @@ -2907,9 +2888,12 @@ setTimeout(() => next(), delay); }; - $.get( - `${window.location.origin}/market/mylistings?count=100&start=${listing}`, - (data) => { + $.ajax({ + type: 'GET', + url: `${window.location.origin}/market/mylistings?count=100&start=${listing}`, + success: function(data, status, xhr) { + marketRateLimitReached = xhr.status === 429; + if (!data || !data.success) { callback(); return; @@ -2926,10 +2910,11 @@ callback() }, - 'json' - ).fail(() => { - callback(); - return; + error: function(xhr) { + marketRateLimitReached = xhr.status === 429; + return callback(); + }, + dataType: 'json' }); }, 1 From c6f31433495f678a91ba0f4235b1477b078239ed Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Fri, 26 Jul 2024 13:58:01 +0300 Subject: [PATCH 09/20] tweaks --- code.user.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/code.user.js b/code.user.js index 8560251..e5f6218 100644 --- a/code.user.js +++ b/code.user.js @@ -1731,10 +1731,11 @@ item, item.ignoreErrors, (success, cached) => { - let delay = 0; + let delay = parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000 || 0; + delay = delay || getRandomInt(1000, 1500); + delay = marketRateLimitReached ? Math.max(delay, getRandomInt(90000, 150000)) : delay; if (success) { - delay = Math.max(delay, getRandomInt(1000, 1500)); setTimeout(() => next(), cached ? 0 : delay); } else { if (!item.ignoreErrors) { @@ -1742,7 +1743,7 @@ itemQueue.push(item); } - delay = Math.max(delay, numberOfFailedRequests > 1 ? getRandomInt(30000, 45000) : getRandomInt(1000, 1500)); + delay = Math.max(delay, numberOfFailedRequests > 1 ? getRandomInt(30000, 45000) : delay); numberOfFailedRequests = numberOfFailedRequests > 3 ? 0 : numberOfFailedRequests; @@ -2408,10 +2409,11 @@ item, false, (success, cached) => { - let delay = 0; + let delay = parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000 || 0; + delay = delay || getRandomInt(1000, 1500); + delay = marketRateLimitReached ? Math.max(delay, getRandomInt(90000, 150000)) : delay; if (success) { - delay = Math.max(delay, getRandomInt(1000, 1500)); setTimeout(() => next(), cached ? 0 : delay); } else { if (!item.ignoreErrors) { @@ -2421,7 +2423,7 @@ numberOfFailedRequests++; - delay = Math.max(delay, numberOfFailedRequests > 1 ? getRandomInt(30000, 45000) : getRandomInt(1000, 1500)); + delay = Math.max(delay, numberOfFailedRequests > 1 ? getRandomInt(30000, 45000) : delay); numberOfFailedRequests = numberOfFailedRequests > 3 ? 0 : numberOfFailedRequests; @@ -2504,7 +2506,10 @@ listing, false, (success, cached) => { - let delay = 0; + let delay = parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000 || 0; + delay = delay || getRandomInt(1000, 1500); + delay = marketRateLimitReached ? Math.max(delay, getRandomInt(90000, 150000)) : delay; + delay = marketListingsQueue.length() > 0 ? delay : 0 const callback = () => { increaseMarketProgress(); @@ -2512,10 +2517,9 @@ } if (success) { - delay = marketListingsQueue.length() > 0 ? Math.max(delay, getRandomInt(1000, 1500)) : 0; setTimeout(callback, cached ? 0 : delay); } else { - delay = marketListingsQueue.length() > 0 ? Math.max(delay, getRandomInt(30000, 45000)) : 0; + delay = Math.max(delay, getRandomInt(30000, 45000)); setTimeout(() => marketListingsQueueWorker(listing, true, callback), cached ? 0 : delay); } } @@ -2882,7 +2886,9 @@ const marketListingsItemsQueue = async.queue( (listing, next) => { const callback = () => { - const delay = 0; + let delay = parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000 || 0; + delay = marketRateLimitReached ? Math.max(delay, getRandomInt(90000, 150000)) : delay; + delay = marketListingsItemsQueue.length() > 0 ? delay : 0 increaseMarketProgress(); setTimeout(() => next(), delay); From 0bb6399f2cb06200ff939d0a848fd58d055ffcba Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Sun, 28 Jul 2024 19:51:38 +0300 Subject: [PATCH 10/20] tweaks --- code.user.js | 477 ++++++++++++++++++++++++++++----------------------- 1 file changed, 263 insertions(+), 214 deletions(-) diff --git a/code.user.js b/code.user.js index e5f6218..1fac53d 100644 --- a/code.user.js +++ b/code.user.js @@ -61,7 +61,6 @@ const spinnerBlock = '
 
 
 
 
 
'; let numberOfFailedRequests = 0; - let marketRateLimitReached = false; const enableConsoleLog = false; @@ -110,6 +109,63 @@ } } + function request(url, options, callback) { + let delayBetweenRequests = 300; + let requestStorageHash = 'request:last'; + + if (url.startsWith('https://steamcommunity.com/market/')) { + requestStorageHash = 'request:last:steamcommunity.com/market'; + delayBetweenRequests = Math.max(delayBetweenRequests, parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000 || 0); + }; + + const lastRequest = JSON.parse(getLocalStorageItem(requestStorageHash) || JSON.stringify({ time: new Date(0), limited: false })); + const timeSinceLastRequest = Date.now() - lastRequest.time.getTime(); + + delayBetweenRequests = lastRequest.request.limited ? 2.5 * 60 * 1000 : delayBetweenRequests; + + if (timeSinceLastRequest < delayBetweenRequests) { + setTimeout(() => request(...arguments), delayBetweenRequests - timeSinceLastRequest); + return; + }; + + lastRequest.time = new Date(); + lastRequest.limited = false; + + setLocalStorageItem(requestStorageHash, JSON.stringify(lastRequest)); + + $.ajax({ + url: url, + type: options.method, + data: options.data, + success: function(data, statusMessage, xhr) { + if (xhr.status === 429) { + lastRequest.limited = true; + setLocalStorageItem(requestStorageHash, JSON.stringify(lastRequest)); + }; + + if (xhr.status <= 400) { + const error = new Error('Http error'); + error.statusCode = xhr.status; + + callback(error, data); + } else { + callback(null, data) + } + }, + error: (xhr) => { + if (xhr.status === 429) { + lastRequest.limited = true; + setLocalStorageItem(requestStorageHash, JSON.stringify(lastRequest)); + }; + + const error = new Error('Request failed'); + error.statusCode = xhr.status; + + callback(error); + }, + dataType: options.responseType + }); + }; function getInventoryUrl() { if (unsafeWindow.g_strInventoryLoadURL) { @@ -445,34 +501,22 @@ // Sell an item with a price in cents. // Price is before fees. SteamMarket.prototype.sellItem = function(item, price, callback /*err, data*/) { - const sessionId = readCookie('sessionid'); - const itemId = item.assetid || item.id; - $.ajax({ - type: 'POST', - url: `${window.location.origin}/market/sellitem/`, + const url = `${window.location.origin}/market/sellitem/`; + + const options = { + method: 'POST', data: { - sessionid: sessionId, + sessionid: readCookie('sessionid'), appid: item.appid, contextid: item.contextid, - assetid: itemId, + assetid: item.assetid || item.id, amount: 1, price: price }, - success: function(data, status, xhr) { - marketRateLimitReached = xhr.status === 429; + responseType: 'json' + }; - if (data && data.success === false && isRetryMessage(data.message)) { - callback(ERROR_FAILED, data); - } else { - callback(ERROR_SUCCESS, data); - } - }, - error: function(xhr) { - marketRateLimitReached = xhr.status === 429; - return callback(ERROR_FAILED, xhr); - }, - dataType: 'json' - }); + request(url, options, callback); }; // Removes an item. @@ -482,26 +526,27 @@ ? `${window.location.origin}/market/cancelbuyorder/` : `${window.location.origin}/market/removelisting/${item}`; - const data = { sessionid: readCookie('sessionid') }; + const options = { + method: 'POST', + data: { + sessionid: readCookie('sessionid'), + ...(isBuyOrder ? { buy_orderid: item } : {}) + }, + responseType: 'json' + }; - if (isBuyOrder) { - data.buy_orderid = item; - } + request( + url, + options, + (error, data) => { + if (error) { + callback(ERROR_FAILED); + return; + }; - $.ajax({ - type: 'POST', - url: url, - data: data, - success: function(data, status, xhr) { - marketRateLimitReached = xhr.status === 429; callback(ERROR_SUCCESS, data); - }, - error: function(xhr) { - marketRateLimitReached = xhr.status === 429; - return callback(ERROR_FAILED); - }, - dataType: 'json' - }); + } + ); }; // Get the price history for an item. @@ -561,24 +606,31 @@ break; } - const sessionId = readCookie('sessionid'); - $.ajax({ - type: 'GET', - url: `${this.inventoryUrlBase}ajaxgetgoovalue/`, + const url = `${this.inventoryUrlBase}ajaxgetgoovalue/`; + + const options = { + method: 'GET', data: { - sessionid: sessionId, + sessionid: readCookie('sessionid'), appid: appid, assetid: item.assetid, contextid: item.contextid }, - success: function(data) { + responseType: 'json' + }; + + request( + url, + options, + (error, data) => { + if (error) { + callback(ERROR_FAILED, data); + return; + }; + callback(ERROR_SUCCESS, data); - }, - error: function(data) { - return callback(ERROR_FAILED, data); - }, - dataType: 'json' - }); + } + ); } catch { return callback(ERROR_FAILED); } @@ -595,25 +647,32 @@ // Grinds the item into gems. SteamMarket.prototype.grindIntoGoo = function(item, callback) { try { - const sessionId = readCookie('sessionid'); - $.ajax({ - type: 'POST', - url: `${this.inventoryUrlBase}ajaxgrindintogoo/`, + const url = `${this.inventoryUrlBase}ajaxgrindintogoo/`; + + const options = { + method: 'POST', data: { - sessionid: sessionId, + sessionid: readCookie('sessionid'), appid: item.market_fee_app, assetid: item.assetid, contextid: item.contextid, goo_value_expected: item.goo_value_expected }, - success: function(data) { + responseType: 'json' + }; + + request( + url, + options, + (error, data) => { + if (error) { + callback(ERROR_FAILED, data); + return; + }; + callback(ERROR_SUCCESS, data); - }, - error: function(data) { - return callback(ERROR_FAILED, data); - }, - dataType: 'json' - }); + } + ); } catch { return callback(ERROR_FAILED); } @@ -630,23 +689,30 @@ // Unpacks the booster pack. SteamMarket.prototype.unpackBoosterPack = function(item, callback) { try { - const sessionId = readCookie('sessionid'); - $.ajax({ - type: 'POST', - url: `${this.inventoryUrlBase}ajaxunpackbooster/`, + const url = `${this.inventoryUrlBase}ajaxunpackbooster/`; + + const options = { + method: 'POST', data: { - sessionid: sessionId, + sessionid: readCookie('sessionid'), appid: item.market_fee_app, communityitemid: item.assetid }, - success: function(data) { + responseType: 'json' + }; + + request( + url, + options, + (error, data) => { + if (error) { + callback(ERROR_FAILED, data); + return; + }; + callback(ERROR_SUCCESS, data); - }, - error: function(data) { - return callback(ERROR_FAILED, data); - }, - dataType: 'json' - }); + } + ); } catch { return callback(ERROR_FAILED); } @@ -659,16 +725,30 @@ // Get the current price history for an item. SteamMarket.prototype.getCurrentPriceHistory = function(appid, market_name, callback) { - $.ajax({ - type: 'GET', - url: `${window.location.origin}/market/pricehistory/?appid=${appid}&market_hash_name=${market_name}`, - success: function(data, status, xhr) { - marketRateLimitReached = xhr.status === 429; - - if (!data || !data.success || !data.prices) { + const url = `${window.location.origin}/market/pricehistory/`; + + const options = { + method: 'GET', + data: { + appid: appid, + market_hash_name: market_name + }, + responseType: 'json' + }; + + request( + url, + options, + (error, data) => { + if (data && (!data.success || !data.prices)) { callback(ERROR_DATA); return; - } + }; + + if (error) { + callback(ERROR_FAILED); + return; + }; // Multiply prices so they're in pennies. for (let i = 0; i < data.prices.length; i++) { @@ -681,21 +761,8 @@ storageSession.setItem(storage_hash, data.prices); callback(ERROR_SUCCESS, data.prices, false); - }, - error: function(xhr) { - marketRateLimitReached = xhr.status === 429; - - if (!xhr || !xhr.responseJSON) { - return callback(ERROR_FAILED); - } - if (!xhr.responseJSON.success) { - callback(ERROR_DATA); - return; - } - return callback(ERROR_FAILED); - }, - dataType: 'json' - }); + } + ); }; // Get the item name id from a market item. @@ -730,13 +797,20 @@ // Get the item name id from a market item. SteamMarket.prototype.getCurrentMarketItemNameId = function(appid, market_name, callback) { - $.ajax({ - type: 'GET', - url: `${window.location.origin}/market/listings/${appid}/${market_name}`, - success: function(page, status, xhr) { - marketRateLimitReached = xhr.status === 429; - - const matches = (/Market_LoadOrderSpread\( (\d+) \);/).exec(page || ''); + const url = `${window.location.origin}/market/listings/${appid}/${market_name}`; + + const options = { method: 'GET' }; + + request( + url, + options, + (error, data) => { + if (error) { + callback(ERROR_FAILED); + return; + }; + + const matches = (/Market_LoadOrderSpread\( (\d+) \);/).exec(data || ''); if (matches == null) { callback(ERROR_DATA); return; @@ -749,12 +823,8 @@ storagePersistent.setItem(storage_hash, item_nameid); callback(ERROR_SUCCESS, item_nameid); - }, - error: function(xhr) { - marketRateLimitReached = xhr.status === 429; - return callback(ERROR_FAILED, xhr.status); } - }); + ); }; // Get the sales listings for this item in the market, with more information. @@ -813,32 +883,39 @@ item, (error, item_nameid) => { if (error) { - if (item_nameid != 429) { // 429 = Too many requests made. - callback(ERROR_DATA); - } else { - callback(ERROR_FAILED); - } + callback(ERROR_FAILED); return; - } - const url = `${window.location.origin}/market/itemordershistogram?country=${country}&language=english¤cy=${currencyId}&item_nameid=${item_nameid}&two_factor=0`; + }; + + const url = `${window.location.origin}/market/itemordershistogram`; + + const options = { + method: 'GET', + data: { + country: country, + language: 'english', + currency: currencyId, + item_nameid: item_nameid, + two_factor: 0 + } + }; + + request( + url, + options, + (error, data) => { + if (error) { + callback(ERROR_FAILED, null); + return; + }; - $.ajax({ - type: 'GET', - url: url, - success: function(histogram, status, xhr) { - marketRateLimitReached = xhr.status === 429; - // Store the histogram in the session storage. const storage_hash = `itemordershistogram_${item.appid}+${market_name}`; storageSession.setItem(storage_hash, histogram); - callback(ERROR_SUCCESS, histogram, false); - }, - error: function(xhr) { - marketRateLimitReached = xhr.status === 429; - return callback(ERROR_FAILED, null); + callback(ERROR_SUCCESS, histogram, false); } - }); + ) } ); }; @@ -1217,7 +1294,7 @@ market.sellItem( task.item, task.sellPrice, - (err, data) => { + (error, data) => { totalNumberOfProcessedQueueItems++; const digits = getNumberOfDigits(totalNumberOfQueuedItems); @@ -1225,41 +1302,41 @@ const itemName = task.item.name || task.item.description.name; const padLeft = `${padLeftZero(`${totalNumberOfProcessedQueueItems}`, digits)} / ${totalNumberOfQueuedItems}`; - if (!err) { - logDOM(`${padLeft} - ${itemName} listed for ${formatPrice(market.getPriceIncludingFees(task.sellPrice))}, you will receive ${formatPrice(task.sellPrice)}.`); + const success = Boolean(data?.success); + const message = data?.message || ''; + + const callback = () => setTimeout(() => next(), getRandomInt(1000, 1500)); - $(`#${task.item.appid}_${task.item.contextid}_${itemId}`). - css('background', COLOR_SUCCESS); + if (success) { + logDOM(`${padLeft} - ${itemName} listed for ${formatPrice(market.getPriceIncludingFees(task.sellPrice))}, you will receive ${formatPrice(task.sellPrice)}.`); + $(`#${task.item.appid}_${task.item.contextid}_${itemId}`).css('background', COLOR_SUCCESS); totalPriceWithoutFeesOnMarket += task.sellPrice; totalPriceWithFeesOnMarket += market.getPriceIncludingFees(task.sellPrice); + updateTotals(); - } else if (data != null && isRetryMessage(data.message)) { - logDOM(`${padLeft} - ${itemName} retrying listing because ${data.message[0].toLowerCase()}${data.message.slice(1)}`); + callback() + + return; + }; + + if (message && isRetryMessage(message)) { + logDOM(`${padLeft} - ${itemName} retrying listing because ${message.charAt(0).toLowerCase()}${message.slice(1)}`); totalNumberOfProcessedQueueItems--; sellQueue.unshift(task); sellQueue.pause(); - setTimeout(() => { - sellQueue.resume(); - }, getRandomInt(30000, 45000)); - } else { - if (data != null && data.responseJSON != null && data.responseJSON.message != null) { - logDOM(`${padLeft} - ${itemName} not added to market because ${data.responseJSON.message[0].toLowerCase()}${data.responseJSON.message.slice(1)}`); - } else { - logDOM(`${padLeft} - ${itemName} not added to market.`); - } - - $(`#${task.item.appid}_${task.item.contextid}_${itemId}`). - css('background', COLOR_ERROR); - } + setTimeout(() => sellQueue.resume(), getRandomInt(30000, 45000)); + callback(); - let delay = parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000 || 0; - delay = marketRateLimitReached ? Math.max(delay, getRandomInt(90000, 150000)) : delay; - delay = sellQueue.length() > 0 ? delay : 0; + return; + }; - setTimeout(() => next(), delay); + logDOM(`${padLeft} - ${itemName} not added to market${message ? `because ${message.charAt(0).toLowerCase()}${message.slice(1)}` : ''}`); + $(`#${task.item.appid}_${task.item.contextid}_${itemId}`).css('background', COLOR_ERROR); + + callback(); } ); }, @@ -1731,20 +1808,15 @@ item, item.ignoreErrors, (success, cached) => { - let delay = parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000 || 0; - delay = delay || getRandomInt(1000, 1500); - delay = marketRateLimitReached ? Math.max(delay, getRandomInt(90000, 150000)) : delay; - if (success) { - setTimeout(() => next(), cached ? 0 : delay); + setTimeout(() => next(), cached ? 0 : getRandomInt(1000, 1500)); } else { if (!item.ignoreErrors) { item.ignoreErrors = true; itemQueue.push(item); - } - - delay = Math.max(delay, numberOfFailedRequests > 1 ? getRandomInt(30000, 45000) : delay); + }; + const delay = numberOfFailedRequests > 1 ? getRandomInt(30000, 45000) : getRandomInt(1000, 1500); numberOfFailedRequests = numberOfFailedRequests > 3 ? 0 : numberOfFailedRequests; setTimeout(() => next(), cached ? 0 : delay); @@ -2409,22 +2481,17 @@ item, false, (success, cached) => { - let delay = parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000 || 0; - delay = delay || getRandomInt(1000, 1500); - delay = marketRateLimitReached ? Math.max(delay, getRandomInt(90000, 150000)) : delay; - if (success) { - setTimeout(() => next(), cached ? 0 : delay); + setTimeout(() => next(), cached ? 0 : getRandomInt(1000, 1500)); } else { if (!item.ignoreErrors) { item.ignoreErrors = true; inventoryPriceQueue.push(item); - } + }; numberOfFailedRequests++; - delay = Math.max(delay, numberOfFailedRequests > 1 ? getRandomInt(30000, 45000) : delay); - + const delay = numberOfFailedRequests > 1 ? getRandomInt(30000, 45000) : getRandomInt(1000, 1500); numberOfFailedRequests = numberOfFailedRequests > 3 ? 0 : numberOfFailedRequests; setTimeout(() => next(), cached ? 0 : delay); @@ -2506,21 +2573,15 @@ listing, false, (success, cached) => { - let delay = parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000 || 0; - delay = delay || getRandomInt(1000, 1500); - delay = marketRateLimitReached ? Math.max(delay, getRandomInt(90000, 150000)) : delay; - delay = marketListingsQueue.length() > 0 ? delay : 0 - const callback = () => { increaseMarketProgress(); next(); - } + }; if (success) { - setTimeout(callback, cached ? 0 : delay); + setTimeout(callback, cached ? 0 : getRandomInt(1000, 1500)); } else { - delay = Math.max(delay, getRandomInt(30000, 45000)); - setTimeout(() => marketListingsQueueWorker(listing, true, callback), cached ? 0 : delay); + setTimeout(() => marketListingsQueueWorker(listing, true, callback), cached ? 0 : getRandomInt(30000, 45000)); } } ); @@ -2705,21 +2766,15 @@ item, false, (success) => { - let delay = parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000 || 0; - delay = delay || getRandomInt(1000, 1500); - delay = marketRateLimitReached ? Math.max(delay, getRandomInt(90000, 150000)) : delay; - delay = marketOverpricedQueue.length() > 0 ? delay : 0 - const callback = () => { increaseMarketProgress(); next(); }; if (success) { - setTimeout(callback, delay); + setTimeout(callback, getRandomInt(1000, 1500)); } else { - delay = Math.max(delay, getRandomInt(30000, 45000)); - setTimeout(marketOverpricedQueueWorker(item, true, callback), delay); + setTimeout(() => marketOverpricedQueueWorker(item, true, callback), getRandomInt(30000, 45000)); } } ); @@ -2826,21 +2881,15 @@ listingid, false, (success) => { - let delay = parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000 || 0; - delay = delay || getRandomInt(50, 100); - delay = marketRateLimitReached ? Math.max(delay, getRandomInt(90000, 150000)) : delay; - delay = marketRemoveQueue.length() > 0 ? delay : 0 - const callback = () => { increaseMarketProgress(); next(); }; if (success) { - setTimeout(callback, delay); + setTimeout(callback, getRandomInt(50, 100)); } else { - delay = Math.max(delay, getRandomInt(30000, 45000)); - setTimeout(() => marketRemoveQueueWorker(listingid, true, callback), delay); + setTimeout(() => marketRemoveQueueWorker(listingid, true, callback), getRandomInt(30000, 45000)); } } ); @@ -2886,24 +2935,29 @@ const marketListingsItemsQueue = async.queue( (listing, next) => { const callback = () => { - let delay = parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000 || 0; - delay = marketRateLimitReached ? Math.max(delay, getRandomInt(90000, 150000)) : delay; - delay = marketListingsItemsQueue.length() > 0 ? delay : 0 - increaseMarketProgress(); - setTimeout(() => next(), delay); + setTimeout(() => next(), getRandomInt(1000, 1500)); }; - $.ajax({ - type: 'GET', - url: `${window.location.origin}/market/mylistings?count=100&start=${listing}`, - success: function(data, status, xhr) { - marketRateLimitReached = xhr.status === 429; - - if (!data || !data.success) { + const url = `${window.location.origin}/market/mylistings` + + const options = { + method: 'GET', + data: { + count: 100, + start: listing + }, + responseType: 'json' + }; + + request( + url, + options, + (error, data) => { + if (error || !data?.success) { callback(); return; - } + }; const myMarketListings = $('#tabContentsMyActiveMarketListingsRows'); @@ -2915,13 +2969,8 @@ unsafeWindow.MergeWithAssetArray(data.assets); // This is a method from Steam. callback() - }, - error: function(xhr) { - marketRateLimitReached = xhr.status === 429; - return callback(); - }, - dataType: 'json' - }); + } + ) }, 1 ); From 2bc2f1e1f7d7f2e9c8c164c87c3e93bcfe6d7dc8 Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Sun, 28 Jul 2024 20:07:32 +0300 Subject: [PATCH 11/20] tweaks --- code.user.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code.user.js b/code.user.js index 1fac53d..ace9881 100644 --- a/code.user.js +++ b/code.user.js @@ -119,9 +119,9 @@ }; const lastRequest = JSON.parse(getLocalStorageItem(requestStorageHash) || JSON.stringify({ time: new Date(0), limited: false })); - const timeSinceLastRequest = Date.now() - lastRequest.time.getTime(); + const timeSinceLastRequest = Date.now() - new Date(lastRequest.time).getTime(); - delayBetweenRequests = lastRequest.request.limited ? 2.5 * 60 * 1000 : delayBetweenRequests; + delayBetweenRequests = lastRequest.limited ? 2.5 * 60 * 1000 : delayBetweenRequests; if (timeSinceLastRequest < delayBetweenRequests) { setTimeout(() => request(...arguments), delayBetweenRequests - timeSinceLastRequest); From 22040c7786e7e0a07b60c12b537056f6defb397e Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Mon, 29 Jul 2024 16:01:12 +0300 Subject: [PATCH 12/20] tweaks --- code.user.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/code.user.js b/code.user.js index ace9881..d9dc8f7 100644 --- a/code.user.js +++ b/code.user.js @@ -143,7 +143,7 @@ setLocalStorageItem(requestStorageHash, JSON.stringify(lastRequest)); }; - if (xhr.status <= 400) { + if (xhr.status >= 400) { const error = new Error('Http error'); error.statusCode = xhr.status; @@ -911,9 +911,9 @@ // Store the histogram in the session storage. const storage_hash = `itemordershistogram_${item.appid}+${market_name}`; - storageSession.setItem(storage_hash, histogram); + storageSession.setItem(storage_hash, data); - callback(ERROR_SUCCESS, histogram, false); + callback(ERROR_SUCCESS, data, false); } ) } @@ -1321,7 +1321,7 @@ }; if (message && isRetryMessage(message)) { - logDOM(`${padLeft} - ${itemName} retrying listing because ${message.charAt(0).toLowerCase()}${message.slice(1)}`); + logDOM(`${padLeft} - ${itemName} retrying listing because: ${message.charAt(0).toLowerCase()}${message.slice(1)}`); totalNumberOfProcessedQueueItems--; sellQueue.unshift(task); @@ -1333,7 +1333,7 @@ return; }; - logDOM(`${padLeft} - ${itemName} not added to market${message ? `because ${message.charAt(0).toLowerCase()}${message.slice(1)}` : ''}`); + logDOM(`${padLeft} - ${itemName} not added to market ${message ? `because: ${message.charAt(0).toLowerCase()}${message.slice(1)}` : ''}`); $(`#${task.item.appid}_${task.item.contextid}_${itemId}`).css('background', COLOR_ERROR); callback(); From 3b5099b631529c698d49b21416aa6a8c3bc6fef1 Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Mon, 29 Jul 2024 16:06:18 +0300 Subject: [PATCH 13/20] tweaks --- code.user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code.user.js b/code.user.js index d9dc8f7..522a83a 100644 --- a/code.user.js +++ b/code.user.js @@ -913,7 +913,7 @@ const storage_hash = `itemordershistogram_${item.appid}+${market_name}`; storageSession.setItem(storage_hash, data); - callback(ERROR_SUCCESS, data, false); + callback(ERROR_SUCCESS, data, false); } ) } From 5b73242070cbdc388963a4bf77452bfc64ad2ffd Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Mon, 29 Jul 2024 16:40:02 +0300 Subject: [PATCH 14/20] tweaks --- code.user.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code.user.js b/code.user.js index 522a83a..addc796 100644 --- a/code.user.js +++ b/code.user.js @@ -740,13 +740,13 @@ url, options, (error, data) => { - if (data && (!data.success || !data.prices)) { - callback(ERROR_DATA); + if (error) { + callback(ERROR_FAILED); return; }; - if (error) { - callback(ERROR_FAILED); + if (data && (!data.success || !data.prices)) { + callback(ERROR_DATA); return; }; From bfeac3fad4012fb08e504e4f541b74edba562887 Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Mon, 29 Jul 2024 16:42:09 +0300 Subject: [PATCH 15/20] tweaks --- code.user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code.user.js b/code.user.js index addc796..e441a28 100644 --- a/code.user.js +++ b/code.user.js @@ -1333,7 +1333,7 @@ return; }; - logDOM(`${padLeft} - ${itemName} not added to market ${message ? `because: ${message.charAt(0).toLowerCase()}${message.slice(1)}` : ''}`); + logDOM(`${padLeft} - ${itemName} not added to market${message ? ` because: ${message.charAt(0).toLowerCase()}${message.slice(1)}` : '.'}`); $(`#${task.item.appid}_${task.item.contextid}_${itemId}`).css('background', COLOR_ERROR); callback(); From 4d0e002ee08318bdf26e86c8bbc0cc1ed473862f Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Thu, 1 Aug 2024 18:13:25 +0300 Subject: [PATCH 16/20] tweaks --- code.user.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/code.user.js b/code.user.js index e441a28..e46ec8a 100644 --- a/code.user.js +++ b/code.user.js @@ -115,7 +115,7 @@ if (url.startsWith('https://steamcommunity.com/market/')) { requestStorageHash = 'request:last:steamcommunity.com/market'; - delayBetweenRequests = Math.max(delayBetweenRequests, parseInt(getSettingWithDefault(SETTING_DELAY_BETWEEN_MARKET_ACTIONS), 10) * 1000 || 0); + delayBetweenRequests = 1000; }; const lastRequest = JSON.parse(getLocalStorageItem(requestStorageHash) || JSON.stringify({ time: new Date(0), limited: false })); @@ -205,7 +205,6 @@ const SETTING_LAST_CACHE = 'SETTING_LAST_CACHE'; const SETTING_RELIST_AUTOMATICALLY = 'SETTING_RELIST_AUTOMATICALLY'; const SETTING_MARKET_PAGE_COUNT = 'SETTING_MARKET_PAGE_COUNT'; - const SETTING_DELAY_BETWEEN_MARKET_ACTIONS = 'SETTING_DELAY_BETWEEN_MARKET_ACTIONS'; const settingDefaults = { SETTING_MIN_NORMAL_PRICE: 0.05, @@ -224,8 +223,7 @@ SETTING_QUICK_SELL_BUTTONS: 1, SETTING_LAST_CACHE: 0, SETTING_RELIST_AUTOMATICALLY: 0, - SETTING_MARKET_PAGE_COUNT: 100, - SETTING_DELAY_BETWEEN_MARKET_ACTIONS: 0 + SETTING_MARKET_PAGE_COUNT: 100 }; function getSettingWithDefault(name) { @@ -3839,10 +3837,6 @@ Market items per page: 
-
- Delay in seconds between market actions:  - -
Automatically relist overpriced market listings (slow on large inventories):  @@ -3862,7 +3856,6 @@ setSetting(SETTING_PRICE_IGNORE_LOWEST_Q, $(`#${SETTING_PRICE_IGNORE_LOWEST_Q}`, price_options).prop('checked') ? 1 : 0); setSetting(SETTING_PRICE_HISTORY_HOURS, $(`#${SETTING_PRICE_HISTORY_HOURS}`, price_options).val()); setSetting(SETTING_MARKET_PAGE_COUNT, $(`#${SETTING_MARKET_PAGE_COUNT}`, price_options).val()); - setSetting(SETTING_DELAY_BETWEEN_MARKET_ACTIONS, $(`#${SETTING_DELAY_BETWEEN_MARKET_ACTIONS}`, price_options).val()); setSetting(SETTING_RELIST_AUTOMATICALLY, $(`#${SETTING_RELIST_AUTOMATICALLY}`, price_options).prop('checked') ? 1 : 0); setSetting(SETTING_INVENTORY_PRICE_LABELS, $(`#${SETTING_INVENTORY_PRICE_LABELS}`, price_options).prop('checked') ? 1 : 0); setSetting(SETTING_TRADEOFFER_PRICE_LABELS, $(`#${SETTING_TRADEOFFER_PRICE_LABELS}`, price_options).prop('checked') ? 1 : 0); From 6bd842a5de8a16f87c72431676f9c672512206db Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Thu, 1 Aug 2024 18:31:16 +0300 Subject: [PATCH 17/20] update request's storage and hash --- code.user.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code.user.js b/code.user.js index e46ec8a..56047af 100644 --- a/code.user.js +++ b/code.user.js @@ -111,10 +111,10 @@ function request(url, options, callback) { let delayBetweenRequests = 300; - let requestStorageHash = 'request:last'; + let requestStorageHash = 'see:request:last'; if (url.startsWith('https://steamcommunity.com/market/')) { - requestStorageHash = 'request:last:steamcommunity.com/market'; + requestStorageHash = `${requestStorageHash}:steamcommunity.com/market`; delayBetweenRequests = 1000; }; @@ -131,7 +131,7 @@ lastRequest.time = new Date(); lastRequest.limited = false; - setLocalStorageItem(requestStorageHash, JSON.stringify(lastRequest)); + setSessionStorageItem(requestStorageHash, JSON.stringify(lastRequest)); $.ajax({ url: url, @@ -140,7 +140,7 @@ success: function(data, statusMessage, xhr) { if (xhr.status === 429) { lastRequest.limited = true; - setLocalStorageItem(requestStorageHash, JSON.stringify(lastRequest)); + setSessionStorageItem(requestStorageHash, JSON.stringify(lastRequest)); }; if (xhr.status >= 400) { From 1dcd7d00a151147c40608e3531edd8e56dc21de4 Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Sat, 3 Aug 2024 19:41:10 +0300 Subject: [PATCH 18/20] return localStorage instead of sessionStorage to request func --- code.user.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code.user.js b/code.user.js index 56047af..76de84f 100644 --- a/code.user.js +++ b/code.user.js @@ -131,7 +131,7 @@ lastRequest.time = new Date(); lastRequest.limited = false; - setSessionStorageItem(requestStorageHash, JSON.stringify(lastRequest)); + setLocalStorageItem(requestStorageHash, JSON.stringify(lastRequest)); $.ajax({ url: url, @@ -140,7 +140,7 @@ success: function(data, statusMessage, xhr) { if (xhr.status === 429) { lastRequest.limited = true; - setSessionStorageItem(requestStorageHash, JSON.stringify(lastRequest)); + setLocalStorageItem(requestStorageHash, JSON.stringify(lastRequest)); }; if (xhr.status >= 400) { From 5287b0752b5adc6964a7390f085f6bb59317c846 Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Mon, 12 Aug 2024 19:22:02 +0300 Subject: [PATCH 19/20] remove semicolon after 'if' statement --- code.user.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/code.user.js b/code.user.js index 76de84f..b4ede01 100644 --- a/code.user.js +++ b/code.user.js @@ -116,7 +116,7 @@ if (url.startsWith('https://steamcommunity.com/market/')) { requestStorageHash = `${requestStorageHash}:steamcommunity.com/market`; delayBetweenRequests = 1000; - }; + } const lastRequest = JSON.parse(getLocalStorageItem(requestStorageHash) || JSON.stringify({ time: new Date(0), limited: false })); const timeSinceLastRequest = Date.now() - new Date(lastRequest.time).getTime(); @@ -126,7 +126,7 @@ if (timeSinceLastRequest < delayBetweenRequests) { setTimeout(() => request(...arguments), delayBetweenRequests - timeSinceLastRequest); return; - }; + } lastRequest.time = new Date(); lastRequest.limited = false; @@ -141,7 +141,7 @@ if (xhr.status === 429) { lastRequest.limited = true; setLocalStorageItem(requestStorageHash, JSON.stringify(lastRequest)); - }; + } if (xhr.status >= 400) { const error = new Error('Http error'); @@ -156,7 +156,7 @@ if (xhr.status === 429) { lastRequest.limited = true; setLocalStorageItem(requestStorageHash, JSON.stringify(lastRequest)); - }; + } const error = new Error('Request failed'); error.statusCode = xhr.status; @@ -540,7 +540,7 @@ if (error) { callback(ERROR_FAILED); return; - }; + } callback(ERROR_SUCCESS, data); } @@ -624,7 +624,7 @@ if (error) { callback(ERROR_FAILED, data); return; - }; + } callback(ERROR_SUCCESS, data); } @@ -666,7 +666,7 @@ if (error) { callback(ERROR_FAILED, data); return; - }; + } callback(ERROR_SUCCESS, data); } @@ -706,7 +706,7 @@ if (error) { callback(ERROR_FAILED, data); return; - }; + } callback(ERROR_SUCCESS, data); } @@ -741,12 +741,12 @@ if (error) { callback(ERROR_FAILED); return; - }; + } if (data && (!data.success || !data.prices)) { callback(ERROR_DATA); return; - }; + } // Multiply prices so they're in pennies. for (let i = 0; i < data.prices.length; i++) { @@ -806,7 +806,7 @@ if (error) { callback(ERROR_FAILED); return; - }; + } const matches = (/Market_LoadOrderSpread\( (\d+) \);/).exec(data || ''); if (matches == null) { @@ -883,7 +883,7 @@ if (error) { callback(ERROR_FAILED); return; - }; + } const url = `${window.location.origin}/market/itemordershistogram`; @@ -905,7 +905,7 @@ if (error) { callback(ERROR_FAILED, null); return; - }; + } // Store the histogram in the session storage. const storage_hash = `itemordershistogram_${item.appid}+${market_name}`; @@ -1316,7 +1316,7 @@ callback() return; - }; + } if (message && isRetryMessage(message)) { logDOM(`${padLeft} - ${itemName} retrying listing because: ${message.charAt(0).toLowerCase()}${message.slice(1)}`); @@ -1329,7 +1329,7 @@ callback(); return; - }; + } logDOM(`${padLeft} - ${itemName} not added to market${message ? ` because: ${message.charAt(0).toLowerCase()}${message.slice(1)}` : '.'}`); $(`#${task.item.appid}_${task.item.contextid}_${itemId}`).css('background', COLOR_ERROR); @@ -1812,7 +1812,7 @@ if (!item.ignoreErrors) { item.ignoreErrors = true; itemQueue.push(item); - }; + } const delay = numberOfFailedRequests > 1 ? getRandomInt(30000, 45000) : getRandomInt(1000, 1500); numberOfFailedRequests = numberOfFailedRequests > 3 ? 0 : numberOfFailedRequests; @@ -2485,7 +2485,7 @@ if (!item.ignoreErrors) { item.ignoreErrors = true; inventoryPriceQueue.push(item); - }; + } numberOfFailedRequests++; @@ -2955,7 +2955,7 @@ if (error || !data?.success) { callback(); return; - }; + } const myMarketListings = $('#tabContentsMyActiveMarketListingsRows'); From e09c061eb247c0cda5181bcd1ca5fbb38f845c4e Mon Sep 17 00:00:00 2001 From: Nuklon Date: Mon, 12 Aug 2024 18:42:19 +0200 Subject: [PATCH 20/20] Update code.user.js --- code.user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code.user.js b/code.user.js index b4ede01..1d100d2 100644 --- a/code.user.js +++ b/code.user.js @@ -2966,7 +2966,7 @@ // g_rgAssets unsafeWindow.MergeWithAssetArray(data.assets); // This is a method from Steam. - callback() + callback(); } ) },