From c6a87b2aed9f4df31ee3b3b89079d98342ec4fab Mon Sep 17 00:00:00 2001 From: Andrii Lavrenko Date: Tue, 20 Aug 2024 13:24:32 +0300 Subject: [PATCH] Fix issue #222 Make it more elegant --- code.user.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/code.user.js b/code.user.js index 25f3b5c..cea3229 100644 --- a/code.user.js +++ b/code.user.js @@ -2566,16 +2566,11 @@ } } - function getPriceValueAsInt(listing) { - // Match number part from any currency format - const results = listing.match(/\d[0-9 .,]*(\.|,\d{0,2})?/gm); - - if (results == null) { - return 0; - } - - return unsafeWindow.GetPriceValueAsInt(results[0]); - } + // Match number part from any currency format + const getPriceValueAsInt = listing => + unsafeWindow.GetPriceValueAsInt( + listing.match(/(?[0-9][0-9 .,]*)/)?.groups?.price ?? 0 + ); const marketListingsQueue = async.queue((listing, next) => { marketListingsQueueWorker(