-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhome.html
85 lines (77 loc) · 1.84 KB
/
home.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
79
80
81
82
83
84
85
<!doctype html>
<html>
<head>
<title>xdm</title>
<meta name="viewport" content="width=device-width">
<link href="/css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.slim.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<style>
button {
border-top: none;
font-size: 24px;
padding: 15px 0 20px;
}
main {
margin: auto;
width: 500px;
}
a {
display: flex;
flex-direction: column;
justify-content: center;
min-width: 100px;
padding: 10px 0;
text-decoration: none;
}
span {
font-size: 36px;
opacity: 0.5;
}
.neutral span {
font-size: 12px;
margin-bottom: 1em;
}
.row {
display: flex;
justify-content: space-between;
margin-top: 20px;
}
.neutral {
color: black;
width: 200px;
}
</style>
</head>
<body>
<button class="neutral">new game</button>
<main></main>
<script>
function makeLink(team, id, counts) {
return $('<a>').addClass(team).attr('href', `/${id}/${team}`).append(
$('<span>').text(counts[team] || 0), team);
}
function makeRow([date, id, counts]) {
button.disabled = false;
if (!$(`#${id}`)[0]) {
const center = $('<a>').addClass('neutral').attr('href', `/${id}`).append(
$('<b>').text(id), $('<span>'), 'spectate');
$('<div>').addClass('row bar').attr('id', id).prependTo('main').append(
makeLink('red', id, counts), center, makeLink('blue', id, counts));
}
$(`#${id} .neutral span`).text(new Date(date).toLocaleString());
}
const socket = io.connect({query: 'path=' + location.pathname});
socket.on('all', data => {
$('main').empty();
data.forEach(makeRow);
});
socket.on('one', makeRow);
socket.on('num', ([id, side, count]) => $(`#${id} .${side} span`).text(count));
const [button] = $('button').click(() => {
button.disabled = true;
socket.emit('new', {}, console.warn);
});
</script>
</body>
</html>