Skip to content

Instantly share code, notes, and snippets.

@jozsefs
Last active February 28, 2025 17:17
Show Gist options
  • Save jozsefs/4a5b8ba473470e752f5ef52b3856eabd to your computer and use it in GitHub Desktop.
Save jozsefs/4a5b8ba473470e752f5ef52b3856eabd to your computer and use it in GitHub Desktop.
Clean trade confirmation summary for Interactive Brokers / IBKR html
// Used on Account Management > Statement > Trade Confirmation (HTML)
// it hides the non-total rows while keeping the header rows
// I only trade stocks/options, so if you need e.g. futures the RegExp likely should be extended below
const styleId = 'styleforhidingrows';
const hideRowsClass = 'hide-rows-i-dont-need';
const summaryTableId = 'tblTradesBody';
// will check based on first cell text
const keepRowsRegExp = /^(Stocks|Equity and Index Options|Total|Total.+(Bought|Sold)\))$/;
const hideRows = () => {
// adds style once for a class that you can toggle from inspector or use resetRowsHiding() to clean up
if (!document.getElementById(styleId)) {
const style = document.createElement('style');
style.id = styleId;
style.innerText = `.${hideRowsClass} { display: none; }`;
document.body.appendChild(style);
}
document.querySelectorAll(`#${summaryTableId} tr`).forEach((row, index) => {
const isFirstRow = index === 0;
const name = row?.cells[0]?.innerText;
const shouldHide = !isFirstRow && !keepRowsRegExp.test(name);
row.classList.toggle(hideRowsClass, shouldHide);
});
};
// use to see all rows again
const resetRowsHiding = () => {
[...document.querySelectorAll(`.${hideRowsClass}`)].forEach(r => r.classList.remove(hideRowsClass))
};
hideRows();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment