wownero-puddle/src/webui-embed.html

226 lines
8.4 KiB
HTML
Raw Normal View History

2018-08-12 14:46:08 +01:00
<!doctype html>
<html>
<head>
2020-04-11 15:52:52 +01:00
<title>wownero-puddle</title>
2018-08-12 14:46:08 +01:00
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
font-family: "Courier New", Courier, monospace;
}
header {
font-size: larger;
font-weight: bold;
padding-bottom: 1em;
}
2019-03-21 03:55:09 +00:00
table {
2019-03-08 03:50:58 +00:00
padding-bottom: 1em;
}
2019-05-04 05:00:27 +01:00
td {
vertical-align: top;
2019-05-04 21:21:46 +01:00
white-space: nowrap;
2019-05-04 05:00:27 +01:00
}
td:last-child {
white-space: unset;
}
2020-01-05 09:33:56 +00:00
.miner {
2018-08-12 14:46:08 +01:00
display: none;
}
2020-01-18 21:05:34 +00:00
#address {
2020-01-05 09:33:56 +00:00
min-width: 10ch;
max-width: 10ch;
overflow: hidden;
border-bottom: 1px dashed black;
text-overflow: ellipsis;
white-space: nowrap;
word-wrap: unset;
}
2020-01-18 21:05:34 +00:00
#address:focus {
2020-01-05 09:33:56 +00:00
outline: 0px solid transparent;
text-overflow: initial;
white-space: initial;
word-wrap: break-word;
}
2018-08-12 14:46:08 +01:00
</style>
</head>
<body>
2020-04-11 15:52:52 +01:00
<header>Wow its a Puddle</header>
2018-08-12 14:46:08 +01:00
<table>
2020-04-11 15:52:52 +01:00
<tr><td>Puddle HR: </td><td id="pool_hashrate"></td></tr>
2019-03-03 20:26:11 +00:00
<tr><td>Network HR: </td><td id="network_hashrate"></td></tr>
2019-05-04 05:00:27 +01:00
<tr><td>Network height: </td><td id="network_height"></td></tr>
2019-03-03 20:26:11 +00:00
<tr><td>Blocks found: </td><td id="pool_blocks_found"></td></tr>
<tr><td>Last block found: </td><td id="last_block_found"></td></tr>
<tr><td>Last template: </td><td id="last_template_fetched"></td></tr>
2020-01-17 12:40:09 +00:00
<tr><td>Round HR: </td><td id="round_hashrate"></td></tr>
<tr><td>Round hashes: </td><td id="round_hashes"></td></tr>
2019-03-03 20:26:11 +00:00
<tr><td>Payment threshold: </td><td id="payment_threshold"></td></tr>
2020-04-11 15:52:52 +01:00
<tr><td>Puddle fee: </td><td id="pool_fee"></td></tr>
<tr><td>Puddle port: </td><td id="pool_port"></td></tr>
2020-01-05 22:53:51 +00:00
<tr><td>Pool SSL port: </td><td id="pool_ssl_port"></td></tr>
<tr><td>Allow self-select: </td><td id="allow_self_select"></td></tr>
2019-03-03 20:26:11 +00:00
<tr><td>Miners connected: </td><td id="connected_miners"></td></tr>
2020-01-05 09:33:56 +00:00
<tr class="miner"><td>Your HR: </td><td id="miner_hashrate"></td></tr>
<tr class="miner"><td>Balance due: </td><td id="miner_balance"></td></tr>
2020-01-18 21:05:34 +00:00
<tr><td>Miner address: </td><td id="address" contenteditable="true"></td></tr>
2018-08-12 14:46:08 +01:00
</table>
<script>
function format_last_time(last)
2019-03-03 20:26:11 +00:00
{
var now = new Date().getTime() / 1000;
var diff = now - last;
var v;
2019-03-03 20:26:11 +00:00
if (last == 0)
return "None yet";
2020-01-19 09:50:14 +00:00
else if (diff <= 0)
return "Just now";
2019-03-03 20:26:11 +00:00
else if (diff < 60)
{
v = parseInt(diff);
return v + " second" + (v != 1 ? "s" : "") + " ago";
}
2019-03-03 20:26:11 +00:00
else if (diff < 3600)
{
v = parseInt(diff/60);
return v + " minute" + (v != 1 ? "s" : "") + " ago";
}
2019-03-03 20:26:11 +00:00
else if (diff < 86400)
{
v = parseInt(diff/3600);
return v + " hour" + (v != 1 ? "s" : "") + " ago";
}
2019-03-03 20:26:11 +00:00
else
{
v = parseInt(diff/86400);
return v + " day" + (v != 1 ? "s" : "") + " ago";
}
2019-03-03 20:26:11 +00:00
}
2020-01-18 21:05:34 +00:00
function max_precision(n, p)
{
return parseFloat(parseFloat(n).toFixed(p));
}
2020-01-17 12:40:09 +00:00
function format_hashes(h)
2019-03-03 20:26:11 +00:00
{
2020-01-17 12:40:09 +00:00
if (h < 1e-12)
return "0 H";
else if (h < 1e-9)
2020-01-18 21:05:34 +00:00
return max_precision(h*1e+12, 0) + " pH";
2020-01-17 12:40:09 +00:00
else if (h < 1e-6)
2020-01-18 21:05:34 +00:00
return max_precision(h*1e+9, 0) + " nH";
2020-01-17 12:40:09 +00:00
else if (h < 1e-3)
2020-01-18 21:05:34 +00:00
return max_precision(h*1e+6, 0) + " μH";
2020-01-17 12:40:09 +00:00
else if (h < 1)
2020-01-18 21:05:34 +00:00
return max_precision(h*1e+3, 0) + " mH";
2020-01-17 12:40:09 +00:00
else if (h < 1e+3)
return parseInt(h) + " H";
else if (h < 1e+6)
2020-01-18 21:05:34 +00:00
return max_precision(h*1e-3, 2) + " KH";
2020-01-17 12:40:09 +00:00
else if (h < 1e+9)
2020-01-18 21:05:34 +00:00
return max_precision(h*1e-6, 2) + " MH";
2019-03-03 20:26:11 +00:00
else
2020-01-18 21:05:34 +00:00
return max_precision(h*1e-9, 2) + " GH";
2020-01-17 12:40:09 +00:00
}
function format_hashrate(h)
{
return format_hashes(h) + "/s";
}
function format_round_hashrate(round_hashes, last_block_found)
{
var now = new Date().getTime() / 1000;
var diff = now - last_block_found;
if (last_block_found == 0)
return 0;
if (diff <= 0)
return 0;
2020-01-18 21:05:34 +00:00
return format_hashrate(round_hashes / diff);
2019-03-03 20:26:11 +00:00
}
2020-01-18 21:05:34 +00:00
var wf = document.querySelector("#address");
2019-03-03 20:26:11 +00:00
var xhr = new XMLHttpRequest();
2020-01-18 21:05:34 +00:00
var rhr = document.querySelector("#round_hashrate");
2019-03-21 03:55:09 +00:00
2019-03-03 20:26:11 +00:00
xhr.onload = function()
{
var stats = JSON.parse(xhr.responseText);
for (var e in stats)
{
var el = document.querySelector("#"+e);
2019-03-21 03:55:09 +00:00
if (!el)
continue;
2020-01-18 21:05:34 +00:00
if (/^last/.test(e))
el.innerHTML = format_last_time(stats[e]);
2019-03-03 20:26:11 +00:00
else if (/hashrate/.test(e))
el.innerHTML = format_hashrate(stats[e]);
2019-05-12 22:31:54 +01:00
else if (e == "pool_fee")
el.innerHTML = (stats[e]*100) + "%";
else if (e == "allow_self_select")
el.innerHTML = stats[e] == 1 ? "Yes" : "No";
2020-01-17 12:40:09 +00:00
else if (e == "round_hashes")
{
2020-01-18 21:05:34 +00:00
el.innerHTML = max_precision(stats[e]*100 /
stats["network_difficulty"], 1) + "%" +
" (" + format_hashes(stats[e]) + " / " +
format_hashes(stats["network_difficulty"]) + ")";
rhr.innerHTML = format_round_hashrate(
stats["round_hashes"], stats["last_block_found"]);
2020-01-17 12:40:09 +00:00
}
2020-01-05 22:53:51 +00:00
else if (e == "pool_ssl_port")
{
el.closest("tr").style = "display: " +
(stats[e] == 0 ? "none;" : "table-row;");
el.innerHTML = stats[e];
}
2019-03-03 20:26:11 +00:00
else
el.innerHTML = stats[e];
}
};
2020-01-05 09:33:56 +00:00
wf.onblur = function(e)
2018-08-12 14:46:08 +01:00
{
var d = new Date();
d.setTime(d.getTime() + (86400 * 365 * 1000));
2020-01-18 21:05:34 +00:00
document.cookie = "wa=" + this.innerText +
";expires=" + d.toGMTString();
2018-08-12 14:46:08 +01:00
window.location.reload();
return false;
};
2019-03-21 03:55:09 +00:00
2018-08-12 14:46:08 +01:00
window.onload = function()
{
2020-01-17 05:35:41 +00:00
var jar = {};
for (var kv, i=0, kvs=document.cookie.split(/\s*;\s*/); i<kvs.length; i++)
{
kv = kvs[i].split(/\s*=\s*/);
if (kv.length > 1)
{
try {
jar[kv[0]] = kv[1];
} catch (e) {}
}
}
if (jar.wa &&
/^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$/.test(jar.wa))
2018-08-12 14:46:08 +01:00
{
2020-01-05 09:33:56 +00:00
var m = document.querySelectorAll(".miner");
for (var i=0; i<m.length; i++)
2018-08-12 14:46:08 +01:00
{
2020-01-05 09:33:56 +00:00
m[i].style = "display: table-row;";
}
2020-01-17 05:35:41 +00:00
wf.innerText = jar.wa;
2018-08-12 14:46:08 +01:00
}
2019-03-07 22:17:11 +00:00
var get_stats = function()
2018-08-12 14:46:08 +01:00
{
2019-03-07 22:17:11 +00:00
xhr.open("GET", "/stats");
2019-03-03 20:26:11 +00:00
xhr.send(null);
2019-03-07 22:17:11 +00:00
};
setInterval(get_stats, 30000);
get_stats();
2018-08-12 14:46:08 +01:00
};
</script>
</body>
</html>