diff rlgterm.js @ 66:57bf0dcd080e

Display idle time of games in progress. statusmsg() now includes games' idle times, and the client displays them using getcurrent().
author John "Elwin" Edwards <elwin@sdf.org>
date Wed, 20 Jun 2012 11:37:05 -0700
parents e63c26dc0497
children b6a3b26fe0dc
line wrap: on
line diff
--- a/rlgterm.js	Wed Jun 20 09:12:26 2012 -0700
+++ b/rlgterm.js	Wed Jun 20 11:37:05 2012 -0700
@@ -453,6 +453,7 @@
       var cell1 = document.createElement("div");
       var cell2 = document.createElement("div");
       var cell3 = document.createElement("div");
+      var cell4 = document.createElement("div");
       cell1.appendChild(document.createTextNode(reply.g[i].p));
       var uname = reply.g[i].g;
       if (uname in games)
@@ -461,14 +462,16 @@
         debug(1, "Unrecognized game: " + uname);
         continue;
       }
+      cell3.appendChild(document.createTextNode(idlestr(reply.g[i].i)));
       var button = document.createElement("span");
       button.appendChild(document.createTextNode("Watch"));
       button.onclick = makeWatcher(reply.g[i].n);
       button.className = "ibutton";
-      cell3.appendChild(button);
+      cell4.appendChild(button);
       row.appendChild(cell1);
       row.appendChild(cell2);
       row.appendChild(cell3);
+      row.appendChild(cell4);
       gamediv.appendChild(row);
     }
   };
@@ -779,6 +782,22 @@
   return;
 }
 
+function idlestr(ms) {
+  if (typeof(ms) != "number")
+    return "?";
+  var seconds = Math.round(ms / 1000);
+  var ss = String(seconds % 60);
+  if (ss.length < 2)
+    ss = "0" + ss;
+  var mm = String(Math.floor((seconds % 3600) / 60));
+  if (mm.length < 2)
+    mm = "0" + mm;
+  var hh = String(Math.floor(seconds / 3600));
+  if (hh.length < 2)
+    hh = "0" + hh;
+  return hh + ":" + mm + ":" + ss;
+}
+
 function bell(on) {
   var imgnode = document.getElementById("bell");
   if (on) {