Zerodha Tradebook Add Total Amount Column
Install latest with possible future updates OR Install fixed script with no updates
// ==UserScript==
// @name Zerodha Tradebook Add Total Amount Column
// @version 0.1
// @description Zerodha Tradebook Add Total Amount Column
// @author https://github.com/z-aki
// @namespace https://github.com/z-aki
// @match https://console.zerodha.com/reports/tradebook*
// @icon https://external-content.duckduckgo.com/ip3/www.zerodha.com.ico
// @grant none
// @require https://gist.githubusercontent.com/adamhotep/7c9068f2196326ab79145ae308b68f9e/raw/373f5e8405b98781001aea9a9e74585367344960/waitForKeyElements.js
Warning
Malicious scripts can violate your privacy and act on your behalf!
You should only install scripts from sources that you trust.
All scripts in this repo are provided in two versions: updates and no updates
controlled by the @downloadURL
tag in the script header.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The trademarks and logos are property of their respective owners (mostly available in the @match
directive or @icon
directive (except when it's loaded from DuckDuckGo)) and no affiliation, association or endorsement is intended, implied or given by the author.
// ==UserScript==
// @name Zerodha Tradebook Add Total Amount Column
// @version 0.1
// @description Zerodha Tradebook Add Total Amount Column
// @author https://github.com/z-aki
// @namespace https://github.com/z-aki
// @match https://console.zerodha.com/reports/tradebook*
// @icon https://external-content.duckduckgo.com/ip3/www.zerodha.com.ico
// @grant none
// @require https://gist.githubusercontent.com/adamhotep/7c9068f2196326ab79145ae308b68f9e/raw/373f5e8405b98781001aea9a9e74585367344960/waitForKeyElements.js
// @downloadURL none
// ==/UserScript==
function fix(table) {
"use strict";
console.log("Adding amount to the table:", table);
const header = table.querySelector("thead tr");
if (!header.querySelector(".amount-header")) {
const amountHeader = document.createElement("td");
amountHeader.textContent = "Amount(custom)";
amountHeader.classList.add("amount-header");
header.appendChild(amountHeader);
}
const rows = table.querySelectorAll("tbody tr");
rows.forEach((row) => {
try {
if (!row.querySelector(".amount-cell")) {
const qty = row.querySelector(".qty").textContent.replace(/,/g, "");
const price = row.querySelector(".price").textContent;
const amount = (parseFloat(qty) * parseFloat(price)).toFixed(2);
const amountCell = document.createElement("td");
amountCell.textContent = amount;
amountCell.classList.add("amount-cell");
row.appendChild(amountCell);
}
} catch (error) {
console.error("Error calculating amount:", error);
}
});
}
function refreshTable() {
const table = document.querySelector("#tradebook_table");
if (table) {
// Clear existing amount columns
const amountHeaders = table.querySelectorAll(".amount-header");
amountHeaders.forEach((header) => header.remove());
const amountCells = table.querySelectorAll(".amount-cell");
amountCells.forEach((cell) => cell.remove());
// Reapply the fix
fix(table);
}
}
function addPaginationListeners() {
const pageOrSortButtons = document.querySelectorAll(
".pagination a, #tradebook_table thead tr td"
);
pageOrSortButtons.forEach((button) => {
button.addEventListener("click", () => {
setTimeout(() => refreshTable(), 500);
});
});
}
waitForKeyElements(
"#tradebook_table",
(table) => {
fix(table);
addPaginationListeners();
// remove wfke_found="true"
table.removeAttribute("wfke_found");
},
false
);