Last active
February 28, 2025 17:17
-
-
Save jozsefs/4a5b8ba473470e752f5ef52b3856eabd to your computer and use it in GitHub Desktop.
Clean trade confirmation summary for Interactive Brokers / IBKR html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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