Skip to content

Instantly share code, notes, and snippets.

@CodeBrauer
Created March 23, 2016 11:19
Show Gist options
  • Save CodeBrauer/bde4205641fc067c268e to your computer and use it in GitHub Desktop.
Save CodeBrauer/bde4205641fc067c268e to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Are you online?</title>
<style>
body {
color: #fff;
font-family: sans-serif;
font-weight: 900;
line-height: 100vh;
height: 100vh;
width: 100vw;
text-align: center;
font-size: 8vw;
overflow: hidden;
background: #000;
}
</style>
</head>
<body>
LOADING...
<script>
function isOnline() {
var xhr = new XMLHttpRequest();
var status;
xhr.open('GET', "https://maps.googleapis.com/maps/api/timezone/json?rand=" + Math.floor(Math.random() * 10000), false);
document.body.innerHTML = "LOADING...";
try {
xhr.send();
console.log(xhr.status);
return ( xhr.status >= 200 && (xhr.status < 300 || xhr.status === 304) );
} catch (error) {
console.log(xhr.status);
return false;
}
}
setInterval(function() {
document.body.style.background = 'black';
if (isOnline()) {
document.body.style.background = '#8BC34A';
document.body.innerHTML = "ONLINE";
document.title = "#ONLINE";
} else {
document.body.style.background = '#F44336';
document.body.innerHTML = "OFFLINE";
document.title = "(!) OFFLINE";
}
}, 3000);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment