Skip to content

Instantly share code, notes, and snippets.

@stoffie
Created November 5, 2015 19:08
Show Gist options
  • Select an option

  • Save stoffie/f6bbe4d350eeedf9d5b1 to your computer and use it in GitHub Desktop.

Select an option

Save stoffie/f6bbe4d350eeedf9d5b1 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<p>Test loaded and ready to fire, plase click left mouse button and follow the instructions on screen</p>
<script>
var body = document.getElementsByTagName("BODY")[0];
var text = document.getElementsByTagName("P")[0];
var time;
var time2;
function ready() {
body.style.backgroundColor = "yellow";
text.innerHTML = "Test started, click as soon as the screen is red";
var false_start = false;
window.onclick = null;
window.onmousemove = function() {
false_start = true;
body.style.backgroundColor = "blue";
text.innerHTML = "You actualy tried to cheat, did you? Click to restart the test";
window.onclick = ready;
};
setTimeout(function() {
if (!false_start) {
body.style.backgroundColor = "red";
text.innerHTML = "Now you should click";
window.onclick = null;
window.onmousemove = stop;
time = new Date();
}
}, 2300);
}
function stop() {
time2 = new Date();
var m = time.getTime();
var m2 = time2.getTime();
var t = m2 - m;
body.style.backgroundColor = "green";
text.innerHTML = "Found latency: " + t + "; Click (again) to restart the test";
window.onclick = ready;
window.onmousemove = null;
}
window.onclick = ready;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment