Created
October 1, 2011 05:10
-
-
Save beothorn/1255629 to your computer and use it in GitHub Desktop.
soma extrato
This file contains 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
var indexes = {date:0,description:3,valueSign:6,value:5,balance:7}; | |
var sums = new Array(); | |
function allMonthsSummed(){ | |
console.log("allMonthsSummed"); | |
var divMenuAno = document.getElementById('TRNnoprint03'); | |
var values = document.createElement("textarea"); | |
values.style.width = "100%"; | |
values.style.height = "25em"; | |
for(var i in sums) | |
values.value += sums[i].date+"|"+sums[i].balance+"\n"; | |
divMenuAno.appendChild(values); | |
} | |
function getSumForThisMonth(){ | |
var lineCount = 1; | |
var dateElement = document.getElementById('date'+lineCount); | |
var balanceLine; | |
while(dateElement != null){ | |
balanceLine = dateElement.parentNode.children; | |
var date = balanceLine[indexes.date].innerHTML; | |
var valueSign = balanceLine[indexes.valueSign].innerHTML; | |
var value = balanceLine[indexes.value].innerHTML; | |
var description = balanceLine[indexes.description].innerHTML; | |
var balance = balanceLine[indexes.balance].innerHTML.replace(/^\s+|\s+$/g,""); | |
if(balance != "") | |
sums.push({date:date+"/"+getCurrentBalanceYear(),balance:balance}); | |
lineCount++; | |
dateElement = document.getElementById('date'+lineCount); | |
} | |
} | |
function getSumForThisMonthAndAdvance(){ | |
console.log("getSumForThisMonthAndAdvance"); | |
getSumForThisMonth(); | |
var nextMonthLink = document.getElementById('linhaMesProximo').children[0]; | |
var isThereAnotherMonth = nextMonthLink != null; | |
if(isThereAnotherMonth){ | |
var d = new Date(); | |
var thisMonth = d.getMonth(); | |
var re = new RegExp("javascript:BuscaMesExtrato\\((\\d)"); | |
var m = re.exec(nextMonthLink.href); | |
var advancingMonthWillReloadThePage = m[1] == thisMonth; | |
if(advancingMonthWillReloadThePage){ | |
allMonthsSummed(); | |
return; | |
} | |
eval(nextMonthLink.href); | |
}else{ | |
allMonthsSummed(); | |
return; | |
} | |
function waitNextMonth() { | |
if(document.getElementById('header0') == null) { | |
console.log("wait"); | |
setTimeout(waitNextMonth, 500); | |
}else{ | |
console.log("done"); | |
getSumForThisMonthAndAdvance(); | |
} | |
}; | |
waitNextMonth(); | |
} | |
function getCurrentBalanceYear(){ | |
var re = new RegExp("- (\\d{4})"); | |
var m = re.exec(document.getElementById('header0').innerHTML); | |
return m[1]; | |
} | |
getSumForThisMonthAndAdvance(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment