Source: site.view [edit]
Function name: mediaTime
Arguments:
Description: Displays media time left for today/tomorrow
Page type: html
Render function:  
Module: global

Page source:

<HEAD>
<!-- META HTTP-EQUIV="REFRESH" CONTENT="10" -->
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=0;" />
<meta name="apple-mobile-web-app-capable" content="yes" />

</HEAD>

<BODY>

<CENTER>

<DIV width=100%>

<webl>
   var html = "";
   if Size(OPTIONALARGS) > 0 then
      html = "<font size=5 color=blue>" + OPTIONALARGS[0] + "</font><p>\n";
   end;
   html;
</webl>

<font size=3><b>Time left today<b></font><p>

<form action="/webl/WubHub_DoIt" method="post">
   <input name="cmdline" value="mediaTimeStartStop(cmd, kind)" type="hidden"/>
         
<webl>

   var ZeroStr = fun(num)
      if (num < 10) then
         "0" + ToString(num)
       else
           ToString(num)
       end
   end;

   var TimeStr = fun(msecs) 
      var hours = msecs div (1000 * 60 * 60);
      var rest = msecs mod (1000 * 60 * 60);
      var mins = rest div (1000 * 60);
      rest = rest mod (1000 * 60);
      var secs = rest div 1000;
      return ToString(hours) + ":" + ZeroStr(mins) + ":" + ZeroStr(secs)
   end;

   var info = (WubCall("global.mediaTimeData", []) ? [. currentMedia = "tv", currentState = "STOP" .]);
   var dat = Str_Split(Wub_GetDateTimeStr(), " ");
   var timeLeft = info[dat[0]] ? [. tv = 1000 * 60 * 120, computer = 1000 * 60 * 120 .];
   var now = Wub_GetDateTime();
   var lastClick = info.lastClick ? 0;
   var tvColor = "red";
   var compColor = "red";

   var computerRemaining = timeLeft.computer;
   var tvRemaining = timeLeft.tv;

   var computerTime = "11:22:33";
   var tvTime = "22:33:44";

   var compChecked = "";
   var tvChecked = "";

   if info.currentState == "START" then
      var running = now - lastClick;
      if info.currentMedia == "tv" then
         tvChecked = "checked";
         tvRemaining = timeLeft.tv - running;
         if tvRemaining > 0 then
            tvColor = "green"
         end;
      else
         compChecked = "checked";
         computerRemaining = timeLeft.computer - running;
         if computerRemaining > 0 then
            compColor = "green"
         end;
     end
   end;

   if (tvRemaining) < 0 then tvRemaining = 0; end;
   if (computerRemaining) < 0 then computerRemaining = 0; end;

   computerTime = TimeStr(computerRemaining);
   tvTime = TimeStr(tvRemaining);

   var html = `<input align=left type="radio" name="kind" ` + compChecked + 
      ` value="computer" /> <font size=5 color=` + compColor + `>Computer: ` +
        computerTime + "</font><p>\n";
   html = html + `<input align=left type="radio" name="kind" ` + tvChecked + 
      ` value="tv" /> <font size=5 color=` + tvColor + `>TV: ` +
        tvTime + "</font> <p>\n";
   // html = html + ToString(timeLeft);
   html;
</webl>

         <input align=left name="cmd" type="submit" value="START">
         <input name="cmd" type="submit" value="STOP"><p>
         <input name="cmd" type="submit" value="REFRESH"><p>
         <input name="cmd" type="submit" value="MODIFY TIME"><p>
</form>

<DIV>
</CENTER>

</BODY>