Skip to content

Instantly share code, notes, and snippets.

@muhammad-saleh
Created July 25, 2022 05:22
Show Gist options
  • Save muhammad-saleh/07f899885daea22cb8283ce40a3457f8 to your computer and use it in GitHub Desktop.
Save muhammad-saleh/07f899885daea22cb8283ce40a3457f8 to your computer and use it in GitHub Desktop.
Egypt CIB utility functions
/*
Descriptions:
Utility functions for https://ebanking.cibeg.com/CIBInternet/ (Egypt CIB) bank to help you get more insights of your transaction.
Usage:
Paste this code in the console and expand the credit card pane.
Start using the functions.
*/
var parent = document.querySelector(`div[toggle="bCreditCardTransactionsLoaded"]`)
var tableSelector = parent.querySelector(`.trans_table_container_inner .resp_table_container.name_value_pairs`)
function sumFromTo(from, to) {
var rows = Array.from(tableSelector.querySelectorAll(`.tbl-row`)).slice(from,to)
var valueCells = rows.map(i => i.querySelectorAll(`.tbl-cell:nth-child(3)`))
var values = valueCells.map(i => Number(i[0].innerText.replace(',','')))
console.log({valueCells, values})
var sum = values.reduce((a, b) => a + b, 0)
return sum
}
function sumDebitFromTo(from, to) {
var rows = Array.from(tableSelector.querySelectorAll(".tbl-row")).slice(from,to)
var debitRows = rows.filter(i => i.innerText.indexOf('Credit') < 0)
var valueCells = debitRows.map(i => i.querySelectorAll(`.tbl-cell:nth-child(3)`)[0])
var arr = valueCells.map(i => Number(i.innerText.replace(',','')))
console.log({
valueCells,
arr
})
var sum = arr.reduce((a, b) => a + b, 0)
return sum
}
function sumCreditFromTo(from, to) {
var rows = Array.from(tableSelector.querySelectorAll(".tbl-row")).slice(from,to)
var creditRows = rows.filter(i => i.innerText.indexOf('Credit') >= 0)
var valueCells = creditRows.map(i => i.querySelectorAll(`.tbl-cell:nth-child(3)`)[0])
var arr = valueCells.map(i => Number(i.innerText.replace(',','')))
console.log({
valueCells,
arr
})
var sum = arr.reduce((a, b) => a + b, 0)
return sum
}
function sumAll(from, to) {
var rows = Array.from(tableSelector.querySelectorAll(".tbl-row")).slice(from,to)
return {
rows,
credit: sumCreditFromTo(from, to),
debit: sumDebitFromTo(from, to),
diff: sumCreditFromTo(from, to) - sumDebitFromTo(from, to)
}
}
function sumAllInstallments(from, to, installments) {
var rows = Array.from(tableSelector.querySelectorAll(".tbl-row")).slice(from,to)
return {
rows,
credit: sumCreditFromTo(from, to),
debit: sumDebitFromTo(from, to),
diff: sumCreditFromTo(from, to) - installments - sumDebitFromTo(from, to)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment