Skip to content

Instantly share code, notes, and snippets.

@gkucmierz
Last active December 24, 2015 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gkucmierz/6754083 to your computer and use it in GitHub Desktop.
Save gkucmierz/6754083 to your computer and use it in GitHub Desktop.
making automated multiple BTC withdrawals from mtgox
(function(){
var form = document.querySelector('#withForm');
var DialogsControl = function(w){
w = w || window;
var d = {
alert: w.alert,
confirm: w.confirm,
prompt: w.prompt
};
return {
disable: function(confirmRet, promptRet){
if (typeof confirmRet === 'undefined')
confirmRet = true;
if (typeof promptRet === 'undefined')
promptRet = '';
w.alert = function(){};
w.confirm = function(){return confirmRet;};
w.prompt = function(){return promptRet;};
},
restore: function(){
w.alert = d.alert;
w.confirm = d.confirm;
w.prompt = d.prompt;
}
};
};
var onContentChange = function(htmlEl, fn) {
var content = htmlEl.innerHTML;
(function callee(){
if (htmlEl.innerHTML !== content) {
fn(htmlEl.innerHTML, content);
return;
}
setTimeout(callee, 50);
})();
};
var sendForm = function(form, amount, address, fee) {
fee = fee || 0;
form.querySelector('#amount').value = (amount+'').replace(/\./, '.');
form.querySelector('#btca').value = address;
form.querySelector('#addWithdrawFee').value = 0;
form.querySelector('.submitBtn').click();
}
var lines = prompt().split(/\n/);
var dc = DialogsControl();
var res = [];
var err = [];
dc.disable();
(function callee(){
if (lines.length === 0) {
console.log('SUCCESS:');
console.log(res.join("\n"));
console.log('');
console.log('ERRORS:');
console.log(err.join("\n"));
dc.restore();
return;
}
var line = lines.shift();
res.push(line);
var match = line.match(/\s*(bitcoind\s+)?sendfrom\s+[\w]+\s+(1[\w]+)\s+([0-9\.]+)\s*$/);
if (match) {
var resDiv = form.querySelector('#withdrawStatus');
(function loop(){
onContentChange(resDiv, function(content){
if (content.match(/The transaction is under way/i)) {
//alert('match ok');
// success
res.push(content);
res.push('');
callee();
} else {
loop();
}
});
})();
sendForm(form, parseFloat(match[3]), match[2]);
} else {
err.push(line);
callee();
}
})();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment