1 #!/usr/bin/phantomjs --ssl-protocol=TLSv1
3 var llDebug = 1, llStatus = 2, llError = 3;
7 var stderr = require("system").stderr;
10 for(var i=0; i<phantom.args.length; i++)
12 if(phantom.args[i] == '--debug') vlDebug = true;
13 else if(phantom.args[i] == '--verbose') vlStatus = true;
14 else if(phantom.args[i].match(/^-/))
16 stderr.write("Unknown option: "+phantom.args[i]+"\n");
21 Glob.username = phantom.args[i];
22 Glob.password = phantom.args[i+1];
27 if(Glob.password == undefined)
29 stderr.write("Usage: erzsebetplusz.js [--debug] [--verbose] <kartya-utolso-8-szamjegye> <jelszo>\n");
34 var url_login = "https://egyenleg.erzsebetutalvanyplusz.hu/cardholderlogin";
35 var loadInProgress = false;
37 var page = new WebPage();
39 function log(level, msg)
41 if(level == llDebug && vlDebug ||
42 level == llStatus && vlStatus ||
43 level == llError && vlError)
45 stderr.write(msg + "\n");
55 page.onConsoleMessage = function(msg)
57 log(llDebug, ">>> " + msg);
60 page.onLoadStarted = function()
62 loadInProgress = true;
63 log(llStatus, "load started [" + page.url + "]");
66 page.onLoadFinished = function()
68 loadInProgress = false;
69 log(llStatus, "load finished [" + page.evaluate(function(){return document.title;}) + "]");
72 page.onResourceRequested = function(requestData, networkRequest)
74 log(llDebug, requestData.method+' '+requestData.url);
76 for(var i=0; i<requestData.headers.length; i++)
78 log(llDebug, requestData.headers[i].name + ': ' + requestData.headers[i].value);
80 log(llDebug, JSON.stringify(requestData));
85 page.open(url_login, function(status)
87 if(status !== 'success')
89 log(llError, "ERROR " + status);
97 //return document.getElementById('login_form').innerHTML;
98 document.getElementById('username').value = param.username;
99 document.getElementById('password').value = param.password;
100 //document.getElementById('login_form').setAttribute('method','GET');
101 var captcha_field = document.getElementById('g-recaptcha-response');
102 captcha_field.parentElement.removeChild(captcha_field);
103 document.getElementById('login_form').submit.click();
108 var a = document.querySelectorAll('.alert');
111 for(var i=0; i<a.length; i++)
113 console.log(a[i].innerHTML.replace(/^\s*()/m, ''));
119 //console.log(document.querySelectorAll('html')[0].outerHTML);
129 log(llDebug, "step "+stepindex);
130 var ret = page.evaluate(steps[stepindex], Glob);
131 log(llDebug, "step "+stepindex+" returned: "+ret);
139 if(stepindex < steps.length)
141 setTimeout(worker, 200);
145 log(llDebug, "complete");
146 setInterval(checkReady, 200);
149 setTimeout(worker, 200);
151 readBalance = function()
156 var a = document.querySelectorAll('.egyenlegWidgetHeaderTitleStyle');
157 for(var i=0; i<a.length; i++)
159 //console.log(a[i].outerHTML);
160 if(name == undefined)
162 name = a[i].innerText;
166 value = a[i].innerText;
167 balance.push({name: name, value: value});
171 return JSON.stringify(balance);
174 checkReady = function()
176 var balance = JSON.parse(page.evaluate(readBalance));
177 if(balance && balance.length)
179 for(var i=0; i<balance.length; i++)
181 var zseb = balance[i].name.replace(/ zseb.*()/, '');
182 var penz = balance[i].value.replace(/[^0-9 \.,]/g, '');
183 output(zseb + ': ' + penz);