Advertisement
Guest User

Untitled

a guest
Jul 29th, 2012
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var api_key;
  2. var timer;
  3.  
  4. $(document).ready(function () {
  5.  
  6.  
  7.     if($.cookie("api_key") != null) {
  8.         api_key = $.cookie("api_key");
  9.         $("#api_key").hide();
  10.         $("#submit").val("Logout");
  11.         load_content();
  12.     }
  13.  
  14.     $("#submit").click(function () {
  15.         if(api_key == null) {
  16.             login();
  17.         } else {
  18.             logout();
  19.         }
  20.     });
  21.  
  22. });
  23.  
  24. function login() {
  25.     api_key = $("#api_key").val();
  26.     $.cookie("api_key", api_key);
  27.     $("#api_key").hide("slow");
  28.     $("#submit").val("Logout");
  29.     load_content();
  30. }
  31.  
  32. function logout() {
  33.     $.cookie("api_key", null);
  34.     api_key = null;
  35.     $("#api_key").show("slow");
  36.     $("#submit").val("Login");
  37.     $("#content").hide("slow");
  38. }
  39.  
  40. function load_content() {
  41.  
  42.     jQuery.ajax({
  43.         url: "proxy.php?api_key="+api_key,
  44.         dataType: 'JSON',
  45.         success:function(data){
  46.             $("#content").show("slow");
  47.             $("#errmsg").text("");
  48.             show_data(data);
  49.             timer = setInterval(load_content, 60000);
  50.         },
  51.         error: function(errorThrown){
  52.             $("#errmsg").text("Invalid API Key");
  53.             logout();
  54.         }
  55.  
  56.     });
  57.  
  58. }
  59.  
  60. function show_data(data) {
  61.     var workers = 0;
  62.     var active_workers = 0;
  63.     var hash_rate = data["hashrate"];
  64.     var paid = data["confirmed_reward"];
  65.  
  66.     var table = '<table border="1" cellspacing="1" cellpadding="11">';
  67.     table += "<tr><th>Name</th><th>Shares</th><th>Stale</th><th>%</th></tr>";
  68.     $.each(data["workers"], function(index, item){
  69.         table += "<tr><td>"+index+"</td><td>"+item.shares+"</td><td>"+item.stales+"</td><td>"+Math.round(((item.shares-item.stales)/item.shares)*100).toFixed(2)+"</td></tr>";
  70.         if(item.alive == "true") {
  71.             workers++;
  72.             active_workers++;
  73.         } else {
  74.             workers++;
  75.         }
  76.     });
  77.     table += '</table>';
  78.     $("#content").html(active_workers +" of "+ workers + " workers @ " + hash_rate + " Mhash/sec<br/>" + paid + " BTC Pending" + "<br/>" +table);  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement