Creating a Windows Clock Application with HTML Application (HTA)

in #development7 years ago

A clock application that displays the current time to the milliseconds can be useful sometimes.

Originally, I had created this application when I was building up my mining rig. It was very unstable as I had used a single core CPU to save on costs. Also, the CPU could run too hot due to bad thermal paste. In addition, the multiple GPUs and the drivers and mining software will cause the operating system to halt out-of-the-blue sometimes.

I wanted to create something that will keep refreshing something on the screen so I can know when to shutdown the machine and make changes to make it run more stable. I had thought of creating a small clock widget that displays the current time, with the milliseconds. This way, I can know very, very quickly when the operating system has froze, and if I'm not watching it actively and come back to it later, I will know when the freezing happened.


As my environment is Windows, I chose to use an HTML Application, because it is fairly portable and easy to make changes to. It is also easy to work with because it's running on web technologies. To explore more, here is the Wikipedia entry at HTML Application.

Here is the code, put it in a file with the extension .hta:

<hta:application border=thin maximizebutton=no innerborder=no></hta:application>

<body scroll="auto" style="padding:0;margin:0">

<table cellspacing=0 cellpadding=0 height=100% width=100%>
<tr valign=middle align=center>
<td id="time" style="font-size:1.8em;font-family:Arial;"></td>
</tr>
</table>

<script>

resizeTo(280, 100);
moveTo(0, screen.availHeight-100);

function refresh() {
    var d = new Date();
    var ampm = "AM";
    var hour = d.getHours();
    var min = d.getMinutes();
    var sec = d.getSeconds();
    var mil = d.getMilliseconds();
    if(hour == 12) ampm = "PM";
    if(hour == 0) hour = 12;
    if(hour > 12) { hour = hour - 12; ampm = "PM"; }
    if(min < 10) min = "0" + min;
    if(sec < 10) sec = "0" + sec;
    if(mil < 100) mil = "0" + mil;
    document.title = hour + ":" + min + ":" + sec + "." + mil + " " + ampm;
    document.getElementById("time").innerHTML = hour + ":" + min + ":" + sec + "<small>." + mil + "</small> " + ampm;
    setTimeout("refresh()", 200);
}

refresh();

</script>

Here is what it looks like when it is running:


 

Follow me! @bitcoiner

 

And vote for my witness bitcoiner!

Sort:  

Thanks for this app my friend. Very good contribution for the community. I'm going to put it into practice to see how it works. I hope you have an excellent weekend. Big hug.

Thanks for this :)

You're welcome!

SO can you make this show up in an actual steemit post?
when can we have javascript and dynamic action inside a steemit post!?! isnt flash like 20 years ago? cant we have live pokergames inside a steemit post now? or at last have a game of pong between two steemit users!!??!?!?

or is that what @zappl and @peerplays will be like?

Any text including javascript can be posted as a post, but most frontends will strip those out due to security concerns.

Coin Marketplace

STEEM 0.19
TRX 0.16
JST 0.033
BTC 64105.03
ETH 2757.74
USDT 1.00
SBD 2.66