diff --git a/FL_enhancer.user.js b/FL_enhancer.user.js index 2a409ee..4b532b4 100644 --- a/FL_enhancer.user.js +++ b/FL_enhancer.user.js @@ -22,26 +22,24 @@ $(document).ready(fl_enhancer); let items_total_value_displayed = false; function display_items_total_value() { - // If anyone spams the "bazaar" link + // Prevents multiple display if spamming the "bazaar" link if (items_total_value_displayed) { return; } + // Only computing the sum if all items are displayed - let shop = document.getElementsByClassName('menu-item--active'); - if ( shop.length && shop[0].textContent != "Sell my things") { + let shop = $('button.menu-item--active') + if (shop.length && shop.text() != "Sell my things") { return; } let total_price = 0; - for (let item of window.document.getElementsByClassName('shop__item')) { - let num_object = item.getElementsByClassName('js-item-value'); - let price_object = item.getElementsByClassName('item__price'); - if (price_object.length && num_object.length) { - let num = num_object[0].textContent; - let price = price_object[0].textContent; - total_price += ( num * price); - } - } + $('li.shop__item').each( function( index, element ){ + total_price = ( + $( this ).find('span.js-item-value').text() * // Number of items + $( this ).find('div.item__price').text() // Price + ); + }); $('.input--item-search').after('
  • Total value:
    ' + total_price + '
  • '); items_total_value_displayed = true; }