Skip to content

Instantly share code, notes, and snippets.

@olofk
Created February 27, 2021 14:12
Show Gist options
  • Select an option

  • Save olofk/7780e9a7e5f064c0f085ea38a1a1bacc to your computer and use it in GitHub Desktop.

Select an option

Save olofk/7780e9a7e5f064c0f085ea38a1a1bacc to your computer and use it in GitHub Desktop.
<!--
Copyright (C) 2016-2020 Davidson Francis <davidsondfgl@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
Original code butchered by Olof Kindgren <olof.kindgren@gmail.com>
-->
<html>
<head>
<script>
/* WebSocket. */
var ws;
var connected = false;
var sw = false;
/* Establish connection. */
function doConnect(addr)
{
/* Message to be sent. */
var msg;
/* Do connection. */
ws = new WebSocket(addr);
/* Register events. */
ws.onopen = function()
{
connected = true;
document.getElementById("btConn").value = "Withdraw into the real world";
};
/* Deals with messages. */
ws.onmessage = function (evt)
{
if (evt.data == "1") {
document.getElementById("led").src = "ledon.png";
} else {
document.getElementById("led").src = "ledoff.png";
}
};
/* Close events. */
ws.onclose = function(event)
{
document.getElementById("btConn").value = "Extend into an immersive alternative reality";
connected = false;
};
}
document.addEventListener("DOMContentLoaded", function(event)
{
/* Connect buttom. */
document.getElementById("btConn").onclick = function()
{
if (connected == false)
{
doConnect("ws://localhost:8080");
}
else
{
ws.close();
connected = false;
document.getElementById("btConn").value = "Connect!";
}
};
document.getElementById("sw").onclick = function()
{
if (sw == true)
{
ws.send("Switch is off");
document.getElementById("sw").src = "swoff.png";
sw = false;
} else {
ws.send("Switch is on");
document.getElementById("sw").src = "swon.png";
sw = true;
}
};
});
</script>
</head>
<body>
<div id="header">
<h1 align="left">verilatio: The pinnacle of modern web design</h1>
<input type="button" id="btConn" name="btConn" value="Extend into an immersive alternative reality"><br /><br />
<img id="led" src="ledoff.png"/>
<img id="sw" src="swoff.png"/>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment