-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
78 lines (70 loc) · 2.18 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<html>
<head>
<title>Trivia Party!</title>
<script src="/socket.io/socket.io.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
var name = prompt("enter your name");
var socket = io.connect('http://www.reillywatson.net/');
socket.emit('name', name);
var answers = [];
var hintTimer;
var stopTimer = function() {
clearTimeout(hintTimer);
hintTimer = null;
}
var hintTick = function() {
if (hintTimer != null) {
var hint = document.getElementById('hint');
var hintText = hint.innerHTML.replace('&', '&');
var newHint = hintText;
while (newHint === hintText && hintText !== answers[0]) {
var replacementPoint = Math.floor(Math.random() * hintText.length);
newHint = newHint.substr(0, replacementPoint) + answers[0].substr(replacementPoint, 1) + newHint.substr(replacementPoint+1);
}
hint.innerHTML = newHint.replace('&', '&');
hintTimer = setTimeout("hintTick()", 1500);
}
}
socket.on('gotquestion', function (data) {
document.getElementById('question').innerHTML = data.question.toString();
answers = data.answers;
document.getElementById('guess').value = "";
document.getElementById('guess').focus();
document.getElementById('hint').innerHTML = answers[0].replace(/[A-Z0-9]/gi, '_')
stopTimer();
hintTimer = setTimeout("hintTick()", 3000);
});
socket.on('gottext', function(data) {
$("#text").append(data.text + '<br/>');
$("#textContainer").scrollTop($("#textContainer")[0].scrollHeight);
});
var guesstextentered = function(e, element) {
var key=e.keyCode || e.which;
if (key == 13 && element.value != "") {
socket.emit('userguess', { guess: element.value});
element.focus();
element.select();
}
}
var skipquestion = function() {
socket.emit("nextquestion");
}
</script>
</head>
<style>
#hint {
font-family: monospace;
letter-spacing: 0.5em;
}
</style>
<body>
<span id="question">Loading question...</span><p/>
<span id="hint"></span><p/>
<input id="guess" type="text" onkeypress="guesstextentered(event, this)" default="true" /><p/>
<button type="button" onclick="skipquestion()">Skip</button>
<p/>
<div id="textContainer" style="overflow:auto; height: 50%; width: 50%">
<span id="text"></span>
</div>
</body>