-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol.html
More file actions
executable file
·202 lines (194 loc) · 6.1 KB
/
Copy pathcontrol.html
File metadata and controls
executable file
·202 lines (194 loc) · 6.1 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Scoreboard</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="/socket.io/socket.io.js"></script>
<link rel="stylesheet" href="/css/control.css">
</head>
<body>
<nav class="header">
<a class="title" href="/">Scoreboard</a>
<div class="top-menu">
<a class="link" href="/control">コントロールパネル</a>
<a class="link" href="https://github.com/0505Keitan/Scoreboard">GitHub</a>
</div>
</nav>
<div class="container">
<div class="control">
<input id="code" class="input" placeholder="あいことばを入力">
<div class="name">
<input id="leftName" class="input" placeholder="名前を入力">
<input id="rightName" class="input" placeholder="名前を入力">
</div>
<div class="view">
<p id="leftScore" class="leftScore">0</p>
<p id="rightScore" class="rightScore">0</p>
</div>
<div class='view'>
<input type="button" class="btn scoreBtn" value="+1" onclick="leftBtn()">
<input type="button" class="btn scoreBtn" value="+1" onclick="rightBtn()">
</div>
<div class="view">
<input type="button" class="btn scoreMinusBtn" value="-1" onclick="leftBtnMin()">
<input type="button" class="btn scoreMinusBtn" value="-1" onclick="rightBtnMin()">
</div>
<div class="enter">
<input type="button" id="register" value="URL発行" class="btn submit" onclick="setting()">
<input type="button" id="reset" class="btn submit" value="スコアリセット" onclick="reset()">
<span id="news"></span>
</div>
<p id="hidden" style="display: none;">表示用URL:<input id="share" class="share" readonly></p>
</div>
</div>
<script>
const getId = (n) => document.getElementById(n);
const socketio = io();
const leftName = getId('leftName');
const rightName = getId('rightName');
let leftCount = 0;
let rightCount = 0;
let isStarted = false;
const SOURCE = "abcdefghijklmnopqrstuvwxyz0123456789";
let result = '';
/*
document.addEventListener('keydown', (event) => {
switch(event.key) {
case 'ArrowLeft':
leftBtn();
break;
case 'ArrowRight':
rightBtn();
break;
case ',':
leftBtnMin();
break;
case '.':
rightBtnMin();
break;
case 'r':
reset();
break;
}
});
*/
const setting = () => {
if((getId('leftName').value && getId('rightName').value) === ''){
alert('名前を設定してください。');
return;
}else if(getId('code').value === ''){
result = '';
for(let i=0; i<16; i++){
result += SOURCE[Math.floor(Math.random() * SOURCE.length)];
}
getId('code').value = result;
}else if(getId('code').value.length <= 5){
alert('あいことばは5文字以下にすることはできません。\n6文字以上にするか自動生成させてください。');
return;
}
socketio.emit('name', {
left: getId('leftName').value,
right: getId('rightName').value,
code: getId('code').value
});
getId('share').value = `${window.location.origin}/view?left=${encodeURI(getId('leftName').value)}&right=${encodeURI(getId('rightName').value)}&code=${encodeURI(getId('code').value)}`;
getId('hidden').style.display = '';
if(!isStarted){
getId('news').innerText = 'URLを発行しました!';
leftCount = 0;
rightCount = 0;
getId('leftScore').innerText = leftCount;
getId('rightScore').innerText = rightCount;
getId('register').value = '設定を適用';
isStarted=!isStarted;
}else{
getId('news').innerText = '適用しました!';
leftCount = 0;
rightCount = 0;
getId('leftScore').innerText = leftCount;
getId('rightScore').innerText = rightCount;
}
setTimeout(function() {
getId('news').innerText = '';
}, 2000);
}
getId('share').onclick = function() {
this.select();
document.execCommand("copy");
getId('news').innerText = 'コピーしました!';
setTimeout(function() {
getId('news').innerText = '';
}, 2000);
}
const leftBtn = () => {
if((getId('leftName').value && getId('rightName').value && getId('code').value) === ''){
alert('URLを発行してください。');
return;
}
leftCount++;
socketio.emit('left', {
count: leftCount,
code: getId('code').value
});
getId('leftScore').innerText = leftCount;
}
const rightBtn = () => {
if((getId('leftName').value && getId('rightName').value && getId('code').value) === ''){
alert('URLを発行してください。');
return;
}
rightCount++;
socketio.emit('right', {
count: rightCount,
code: getId('code').value
});
getId('rightScore').innerText = rightCount;
}
const leftBtnMin = () => {
if((getId('leftName').value && getId('rightName').value && getId('code').value) === ''){
alert('URLを発行してください。');
return;
}
if(leftCount === 0)return;
leftCount--;
socketio.emit('left', {
count: leftCount,
code: getId('code').value
});
getId('leftScore').innerText = leftCount;
}
const rightBtnMin = () => {
if((getId('leftName').value && getId('rightName').value && getId('code').value) === ''){
alert('URLを発行してください。');
return;
}
if(rightCount === 0)return;
rightCount--;
socketio.emit('right', {
count: rightCount,
code: getId('code').value
});
getId('rightScore').innerText = rightCount;
}
const reset = () => {
if((getId('leftName').value && getId('rightName').value && getId('code').value) === ''){
alert('URLを発行してください。');
return;
}
leftCount = 0;
rightCount = 0;
socketio.emit('reset', {
reset: true,
code: getId('code').value
});
getId('leftScore').innerText = leftCount;
getId('rightScore').innerText = rightCount;
getId('news').innerText = 'スコアをリセットしました!';
setTimeout(function() {
getId('news').innerText = '';
}, 2000);
}
</script>
</body>
</html>