|
function enhance(){{ |
|
// made by Qwerty https://gist.github.com/ackvf/c5fe6ad0663b82ad5dca6d16da727e84 |
|
// calculation based on https://www.etoro.com/posts/0__entry__c1253723-6eaa-4f3e-a1d6-475078a152c9?utm_medium=Direct&utm_source=55714&utm_content=0&utm_serial=SocialSharePostcopyLink_5522996&utm_campaign=SocialSharePostcopyLink_5522996&utm_term= |
|
const format = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format |
|
const parse = (_, el) => parseFloat(el.innerText.replaceAll(/[$,]/g, '')) |
|
const cell = (value, title = '', valueSpecial = '') => |
|
`<div class="ui-table-cell${value < 0 ? ' negative' : ''}">${ |
|
value !== undefined || title |
|
? ` <div class="rate-value">${value !== undefined ? format(value) : valueSpecial}</div> |
|
<div class="rate-subvalue">${title}</div>` |
|
: '' |
|
}</div>` |
|
const message = 'Report errors to https://gist.github.com/ackvf/c5fe6ad0663b82ad5dca6d16da727e84' |
|
const thrower = (name) => { throw TypeError(`Expected value for "${name}" is missing. ${message}`) } |
|
const check = ({rest, ...args}) => { |
|
Object.entries(args).forEach(([n, v]) => (v === undefined) && thrower(n)) |
|
if (rest && rest.length) throw TypeError(`Too many parameters. ${message}`) |
|
} |
|
|
|
const th = $('div.w-portfolio-table-hat') |
|
const tb = $('ui-table-body') |
|
const tr = $('.ui-table-row.trade-row') |
|
|
|
|
|
const [initial, inout, _pl_usd, value, ...rest1] = th.find('.i-portfolio-table-header-cell-value').map(parse) |
|
check({initial, inout, _pl_usd, value, rest: rest1}) |
|
const [invested, pl_usd, pl_percent, refunds, pl_usd_closed, ...rest2] = tr.find('.rate-value').map(parse) |
|
check({invested, pl_usd, pl_percent, refunds, pl_usd_closed, rest: rest2}) |
|
|
|
const deposit = initial + inout |
|
const allocated = deposit + refunds + pl_usd_closed |
|
const available = allocated - invested |
|
const available_percent = available / allocated |
|
|
|
|
|
const t = tr.clone() // trade row |
|
const b = $(tr[0]).clone() // balance row |
|
th.css('display', 'block') |
|
tb.css('padding-bottom', 270) |
|
th.parent().append(b, t) |
|
|
|
b.find('.table-first-name').text('BALANCE') |
|
b.find('.ui-table-body-slot') |
|
.empty() |
|
.append( |
|
cell(), |
|
cell(deposit, 'DEPOSIT'), |
|
cell(allocated, 'ALLOCATED'), |
|
cell(available, 'AVAILABLE ($)'), |
|
cell(undefined, 'AVAILABLE (%)', `${Math.round(available_percent * 10000) / 100}%`) |
|
) |
|
}} |