Skip to content

Instantly share code, notes, and snippets.

@kwadroke
Last active January 1, 2016 22:28
Show Gist options
  • Save kwadroke/6f4aa0837a5be0621552 to your computer and use it in GitHub Desktop.
Save kwadroke/6f4aa0837a5be0621552 to your computer and use it in GitHub Desktop.
EmptyEpsilon Status Screen for Alerts
<html>
<script>
//Create a directory called "www" in the EmptyEpsilon main directory an place this file there. Then enable http by editing the options.ini file by adding httpserver=8080
var url= "/get.lua?alert=getAlertLevel()"
// Create the XHR object.
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// XHR for Chrome/Firefox/Opera/Safari.
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
// XDomainRequest for IE.
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
// CORS not supported.
xhr = null;
}
return xhr;
}
function showStatus(status) {
document.getElementById('container').innerHTML="";
console.log(status);
var arr = JSON.parse(status);
var element = document.getElementById('container');
if (arr["alert"] == "RED ALERT") {
element.style.background = 'red';
} else if (arr["alert"] == "YELLOW ALERT"){
element.style.background = 'yellow';
} else if (arr["alert"] == "Normal") {
element.style.background = 'black';
} else {
element.style.background = 'black';
}
}
// Make the actual CORS request.
function makeCorsRequest() {
// All HTML5 Rocks properties support CORS.
//var url = 'http://updates.html5rocks.com';
var xhr = createCORSRequest('GET', url);
if (!xhr) {
alert('CORS not supported');
return;
}
// Response handlers.
xhr.onload = function() {
var status = xhr.responseText;
var title = showStatus(status);
};
xhr.onerror = function() {
console.log('Woops, there was an error making the request.');
document.getElementById('container').innerHTML="Error Getting Status";
};
xhr.send();
}
function getjson() {
var xhr = createCORSRequest('GET', url);
if (!xhr) {
console.log("CORS not supported");
//throw new Error('CORS not supported');
}
}
//makeCorsRequest();
var timerId = setInterval(makeCorsRequest, 1000);
</script>
<style>
body {
color: white;
background-color: black;
height: 100%;
margin: 0px;
padding: 0px;
}
#container {
height: 100%
}
</style>
<body>
<div id="container">
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment