jQuery rewrite

This commit is contained in:
Audrey 2021-09-06 20:20:28 +02:00
parent cfeca13484
commit 094c189d23
1 changed files with 10 additions and 12 deletions

View File

@ -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('<li class="shop__item js-item item "><div class="item__desc"><span class="js-item-name item__name">Total value:</span> <div class="price item__price">' + total_price + '</div></div></li>');
items_total_value_displayed = true;
}