Skip to content

Instantly share code, notes, and snippets.

@gourytch
Last active March 2, 2017 02:45
Show Gist options
  • Save gourytch/f9ae1de36fa774fadbe57433a15bdd99 to your computer and use it in GitHub Desktop.
Save gourytch/f9ae1de36fa774fadbe57433a15bdd99 to your computer and use it in GitHub Desktop.
tampermonkey script for hashflare history log parsing
// ==UserScript==
// @name HFCalc
// @description Подсчёт текущей профитности майнинга по истории
// @author Gourytch
// @license WTFPL
// @version 1.1
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js
// @include https://hashflare.io/panel/history
// ==/UserScript==
(function (window, undefined) {
var w;
if (typeof unsafeWindow !== undefined) {
w = unsafeWindow;
} else {
w = window;
}
if (w.self != w.top) {
return;
}
if (!/https:\/\/hashflare.io\/panel\/history.*/.test(w.location.href)) {
return;
}
$('body').prepend('<div id="hfcdiv">'+
'<button id="hfcbtn">HFCalc</button>'+
'<div id="hfc"/>'+
'<pre id="hfclog"></pre>'+
'</div>');
function LogClear(s) {
$('#hfclog').text('');
}
function Log(s) {
$('#hfclog').text($('#hfclog').text() + s + '\n');
}
$('#hfcbtn').click(function() {
var C = $("#DataTables_Table_0"); // Contracts
if (!C.length) {
Log("Contracts table missing");
return;
}
var L = $("#DataTables_Table_3"); // Log
if (!L.length) {
Log("Log table missing");
return;
}
var Hash = function(name, usd) { // name and amount of investments in usd
this.name = name;
this.usd = usd;
this.invested = null;
this.d0 = null;
this.d1 = null;
this.sum = 0;
this.process = function(day, amount) {
if (this.d0 === null || day < this.d0) this.d0 = day;
if (this.d1 === null || this.d1 < day) this.d1 = day;
this.sum += amount;
};
this.days = function() {
if (this.d0 === null || this.d1 === null) { return NaN; }
return Math.abs(this.d1 - this.d0) + 1;
};
this.daily = function() {
return this.sum / this.days();
};
this.annual = function() {
return this.daily() * 365;
};
this.rate = function() {
return 100 * this.annual() / this.invested;
};
this.row = function() {
return "<tr><th>" +
this.name + "</th><td>" +
this.sum.toFixed(8) + "</td><td>" +
this.days() + "</td><td>" +
this.daily().toFixed(8) + "</td><td>" +
this.annual().toFixed(8) + "</td><td>$" +
this.usd.toFixed(2) + "</td><td>" +
this.invested.toFixed(8) + "</td><td>" +
this.rate().toFixed(2) + "%</td></tr>";
};
};
var sha256_amount = 0;
var scrypt_amount = 0;
C.find('tr').each(function (rowIndex, r) {
var cols = [];
$(this).find('td').each(function (colIndex, c) {
cols.push(c.textContent);
});
if (cols.length <= 4) { return; } // skip it
var t = cols[1];
var v = parseInt(cols[2]);
if (t == 'SHA-256') sha256_amount += v;
if (t == 'Scrypt') scrypt_amount += v;
});
var btc_price = null;
var sha256_price = 1.20 / 10; // $1.20 per 10 GH/s
var scrypt_price = 8.20; // $8.20 per 1 MH/s
var sha256_fee = 0.0035 / 10; // $0.0035 per 10 GH/s
var scrypt_fee = 0.01; // $0.01 per 1 MH/s
var sha256 = new Hash('sha256', sha256_price * sha256_amount);
var scrypt = new Hash('scrypt', scrypt_price * scrypt_amount);
s2days = function(s) {
var v = s.split(" ", 1)[0].split(".");
// Log("<" + s + "> -> <" + v + ">");
var o = new Date(2000 + parseInt(v[2]), parseInt(v[1]), parseInt(v[0]));
// Log("... -> <" + o + ">");
var d = Math.floor(o.getTime() / (1000 * 60 * 60 * 24));
// Log("... -> <" + d + ">");
return d;
};
LogClear();
L.find('tr').each(function (rowIndex, r) {
var cols = [];
$(this).find('td').each(function (colIndex, c) {
cols.push(c.textContent);
});
if (cols.length <= 4) { return; } // skip it
var t = cols[0];
var d = s2days(cols[1]);
var v = parseFloat(cols[2]);
// Log(d+">>> \""+t+"\" "+v);
if (t == 'SHA-256 payout (BTC)') sha256.process(d, +v);
if (t == 'Scrypt payout (BTC)') scrypt.process(d, +v);
if (t == 'SHA-256 maintenance (BTC)') {
sha256.process(d, -v);
// calculate btc price in usd from fee
btc_price = v / sha256_fee;
// Log("found BTC price from SHA-256 Fee: " + v.toFixed(8) + " BTC / " + sha256_fee + " USD = " + btc_price.toFixed(8));
}
if (t == 'Scrypt maintenance (BTC)') {
scrypt.process(d, -v);
// calculate btc price in usd from fee
btc_price = v / scrypt_fee;
// Log("found BTC price from Scrypt Fee: " + v.toFixed(8) + " BTC / " + scrypt_fee + " USD = " + btc_price.toFixed(8));
}
});
// fill gaps
sha256.invested = sha256.usd * btc_price;
scrypt.invested = scrypt.usd * btc_price;
// Log("sha256=" + sha256.sum + "; scrypt=" + scrypt.sum);
$('#hfc').html("<table id='hfc_tab' border='1'>" +
"<tr><th>name</th><th>sum</th><th>days</th><th>daily</th><th>annual</th><th colspan='2'>invested</th><th>rate</th></tr>" +
sha256.row() +
scrypt.row() +
"</table>");
$('#hfc_tab th').css({'padding':'2px 10px', 'text-align':'center'});
$('#hfc_tab td').css({'padding':'2px 10px', 'text-align':'right'});
// Log("------- finished --------");
});
$('#hfcdiv').css("background-color", "#fffff0");
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment