I normalnie chcąc zobaczyć jakie mam "średnie" oprocentowanie, najpierw pobierałem plik Excela, później przechodziłem przez kolejne emisje i sobie przepisywałem ostatni numerek...
// sadly this part is only for hacky way of finding what are Ids
function findIdLambda(elem,list,func) {
var id = elem.id;
if (id && func(id)) {
list.push(id);
}
for (var i=0; i<elem.childNodes.length; i++) {
var child = elem.childNodes[i];
findIdLambda(child,list,func);
}
}
function findId(elem,idStart,list) {
findIdLambda(elem,list,x => x.startsWith(idStart));
}
var list = [];
findId(document,"stanRachunku",list);
var id = list.filter(x => x.endsWith("data")).filter(x => x.indexOf("idt")!=-1)[0];
var no = id.split("idt")[1].split("_")[0]*1;
var idxNo = no;
function findQtipId(pattern) {
var list = [];
findIdLambda(document,list,x => x.startsWith(pattern));
return list[0];
}
//end of hacky way for finding proper Ids
const mouseoverEvent = new Event('mouseover');
function amount2number(s) {
var nbrsp=String.fromCharCode(160);
return s.replace(nbrsp,"").replace(',',".").replace(nbrsp+"PLN","");
}
function getPercents(idx) {
var id = findQtipId("qtip-stanRachunku:j_idt"+idxNo+":"+idx+":j_idt");
console.log(id);
var element=document.getElementById(id);
var data=element.innerText.split("%");
var res = [];
for (var i=0; i<data.length; i++) {
var line=data[i];
line=line.trim();
if (line.length==0) continue;
var l=line.split(" ");
res.push(l[l.length-1]);
}
return res;
}
var table=document.getElementById("stanRachunku:j_idt"+idxNo+"_data");
var data=table.childNodes;
var content="id,number,value,actual value,cycle,%,redemption date\n";
for (var i=0; i<data.length; i++) {
var line = data[i].childNodes;
// ugly hack... but without this it will not be visible, and we would not be able to get percents
line[0].firstChild.dispatchEvent(mouseoverEvent);
var emId=line[0].innerText;
var number=line[1].innerText;
var value=line[3].innerText;
var actual=line[4].innerText;
var redemption=line[5].innerText;
var percents=getPercents(i);
var cycle = percents.length;
var percentage = percents[percents.length-1];
var l=[emId,number,amount2number(value),amount2number(actual),cycle,percentage,redemption];
var cl = "";
for (var j=0; j<l.length; j++) cl+=l[j]+",";
cl=cl.substring(0,cl.length-1);
content+=cl+"\n";
}
console.log(content);
var blob = new Blob([[content]],{type: "text/csv"});
console.log(blob);
var downloadObj = window.URL.createObjectURL(blob);
console.log(downloadObj);
var a = window.document.createElement('a');
a.href = downloadObj;
a.text = "obligacje.csv";
a.download = "obligacje.csv";
a.click();
Jak działa? ;-)
line[0].firstChild.dispatchEvent(mouseoverEvent);
Bookmarklet by policzyć Procent z obligacji, zrobiony przy pomocy Bookmarklet Makera
Podobne postybeta
Ile w tym i przyszłym miesiącu z odsetek za obligacje?
Ile z obligacji... odsłona 2 ;-)
[Updated] Czytanie Pocketa ;-)
Ściana, czyli rozbijam się na onclick ;-)
Go dla Java'owca ;-) odcinek 2 "kontenery dwa ;-)"