|
| 1 | +{ |
| 2 | + var table = document.querySelector('.table-to-list.instruments-table > tbody'); |
| 3 | + let total_value = 0.0; |
| 4 | + let total_prev_value = 0.0; |
| 5 | + for (var i = 0, row; row = table.rows[i]; i++) { |
| 6 | + let v = ''; |
| 7 | + let price = row.querySelector('td[data-title=Price]'); |
| 8 | + let change = row.querySelector('td[data-title=Change]'); |
| 9 | + let quantity = row.querySelector('td[data-title=Quantity]'); |
| 10 | + let oldprice = price.textContent.trim().replace('$', '') - parseFloat(change.textContent.split('/')[0].trim().replace('$', '')); |
| 11 | + let oldquant = parseInt(quantity.textContent.trim()) * oldprice; |
| 12 | + |
| 13 | + total_prev_value += oldquant; |
| 14 | + total_value += parseFloat(price.textContent.trim().replace('$', '')) * parseInt(quantity.textContent.trim()); |
| 15 | + } |
| 16 | + let newrow = table.insertRow(-1); |
| 17 | + let cell = newrow.insertCell(-1); |
| 18 | + cell.setAttribute('class', 'text-center'); |
| 19 | + cell.innerHTML = "<strong>Total</strong>"; |
| 20 | + cell = newrow.insertCell(-1); |
| 21 | + cell = newrow.insertCell(-1); |
| 22 | + cell = newrow.insertCell(-1); |
| 23 | + cell = newrow.insertCell(-1); |
| 24 | + cell.classList.add('text-right'); |
| 25 | + if (total_value - total_prev_value > 0) { |
| 26 | + cell.classList.add('up'); |
| 27 | + } else { |
| 28 | + cell.classList.add('down'); |
| 29 | + }; |
| 30 | + cell.innerHTML = '$' + (total_value - total_prev_value).toFixed(3) + " / " + ((total_value - total_prev_value) * 100 / total_prev_value).toFixed(3) + '%'; |
| 31 | + cell = newrow.insertCell(-1); |
| 32 | + cell.setAttribute('class', 'text-right'); |
| 33 | + cell.innerHTML = '$' + total_value; |
| 34 | +} |
0 commit comments