xmr-pool-site/tools.js

80 lines
1.9 KiB
JavaScript

var lastnavitem = null;
function $(id){
return window.document.getElementById(id);
}
function navigate(page){
$("pagecontent").innerHTML = pagerpc.fetchRaw( page + ".html" );
if (lastnavitem != null){
lastnavitem.className = lastnavitem.className.replace(" selected","");
}
lastnavitem = $("nav-"+page);
lastnavitem.className += " selected";
}
function formatValue(value,unit,decimals = 0){
if (value >= 1000000000){
unit = "G"+unit;
value = value / 1000000000;
} else if (value >= 1000000){
unit = "M"+unit;
value = value / 1000000;
} else if (value >= 1000){
unit = "k"+unit;
value = value / 1000;
}
return value.toFixed(decimals) + " " + unit;
}
function formatTime(value){
unit = "Sekunden";
if (value > 60){
unit = "Minuten";
value /= 60;
if (value == 1){
unit = "Minute"
}
if (value > 60){
unit = "Stunden";
value /= 60;
if (value > 24){
unit = "Tage";
value /= 24;
if (value > 30){
unit = "Monate";
value /= 30;
}
}
}
}
return value.toFixed(0) + " " + unit;
}
function updateStatistics(){
stat = rpc.fetch("stats");
netHashrate = stat.network.difficulty / stat.config.coinDifficultyTarget;
blockrate = stat.network.difficulty / stat.pool.hashrate;
$("vPoolHashrate").innerText = formatValue(stat.pool.hashrate,"H/s",3);
$("vNetworkHashrate").innerText = formatValue(netHashrate,"H/s",3);
$("vBlockRate").innerText = formatTime(blockrate);
$("vCurrentDifficulty").innerText = formatValue( stat.network.difficulty, "", 3 );
$("vDifficultyTarget").innerText = formatTime( stat.config.coinDifficultyTarget );
$("vBlockHeight").innerText = stat.network.height;
$("lastBlockHash").innerText = stat.network.hash;
$("vLastBlockAge").innerText = formatTime((new Date().getTime()/1000) - stat.network.timestamp);
setTimeout( updateStatistics, 2500 );
}