-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathhomepage.min.js
1 lines (1 loc) · 1.99 KB
/
homepage.min.js
1
var noFocus=0;var ws;var retry=0;decimals=2;function updateTimes(){document.hasFocus?noFocus=0:++noFocus;if(noFocus>120&&ws){ws.close();ws=null}var a=new Date().getTime()/1000;$("td[data-time]").each(function(b){var d=a-$(this).attr("data-time");if(d<60){$(this).text("< 1 minute")}else{if(d<3600){var c=(parseInt(d/60)>1)?"s":"";$(this).text(parseInt(d/60)+" minute"+c)}else{var c=(parseInt(d/3600)>1)?"s":"";$(this).text(parseInt(d/3600)+" hour"+c+" "+parseInt((d%3600)/60)+" minutes")}}})}function connect(){try{ws=new WebSocket(getWebSocketURL());ws.onmessage=function(f){var d=$.parseJSON(f.data);if(d.op=="minitx"){var b=d.x;$('<tr><td><div><a href="'+root+"tx-index/"+b.txIndex+"/"+b.hash+'">'+b.hash.substring(0,25)+'...</a></div></td><td class="hidden-phone" data-time="'+b.time+'"><div>< 1 minute</div></td><td><div><button class="btn btn-success" onclick="toggleSymbol()">'+formatMoney(b.value,true)+"</button></div></td></tr>").insertAfter($("#txs tr:first")).find("div").hide().slideDown("slow");$("#txs tr:last-child").remove()}else{if(d.op=="block"){console.log("on block");var g=BlockFromJSON(d.x);var c="Unknown";if(g.foundBy!=null){c='<a href="'+g.foundBy.link+'">'+g.foundBy.description+"</a>"}$('<tr><td><div><a href="'+root+"block-index/"+g.blockIndex+"/"+g.hash+'">'+g.height+'</a></div></td><td data-time="'+g.time+'"><div>< 1 minute</div></td><td class="hidden-phone"><div>'+g.txIndex.length+'</div></td><td class="hidden-phone"><div>'+formatMoney(g.totalBTCSent,true)+"</div></td><td><div>"+c+'</div></td><td class="hidden-phone"><div>'+parseInt(g.size/1024)+"</div></td></tr>").insertAfter($("#blocks tr:first")).find("div").hide().slideDown("slow");$("#blocks tr:last-child").remove()}}};ws.onopen=function(){retry=0;ws.send('{"op":"set_tx_mini"}{"op":"unconfirmed_sub"}{"op":"blocks_sub"}')};ws.onclose=function(){console.log("On close");if(document.hasFocus&&retry<3){setTimeout(connect,1000*retry);++retry}}}catch(a){console.log(a)}}$(document).ready(function(){setInterval(updateTimes,1000);connect()});