-
Notifications
You must be signed in to change notification settings - Fork 0
/
guest.html
137 lines (133 loc) · 5.47 KB
/
guest.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
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
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
<title>早押しボタン</title>
<script src="https://cdn.socket.io/socket.io-1.2.0.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script src="static.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
</style>
</head>
<body>
<form id="name-form">
<div class="input-group" style="width:100%;">
<label for="userNickName">名前を入力してください</label>
<input type="text" class="form-control" id="userNickName" placeholder="フルネームで!" minlength="3" required>
</div>
<button class="btn btn-default" style="width:100%;">決定する</button>
</form>
<div id="yourname"></div>
<div id="quiz-text" style="width:100%;height:100px;text-align:center;vertical-align:middle;padding-top:20px;position:relative;"></div>
<form id="answer-buttons-form" style="display:none;">
<button class="btn btn-primary" style="width:100%;">1</button><br/><br/>
<button class="btn btn-danger" style="width:100%;">2</button><br/><br/>
<button class="btn btn-success" style="width:100%;">3</button><br/><br/>
<button class="btn btn-warning" style="width:100%;">4</button><br/><br/>
</form>
<script>
$(document).ready(function(){
var name = "";
var socket = io(socket_url);
var gameover = false;
$('#name-form').submit(function(){
name = $("#userNickName").val();
$("#name-form").hide();
$("#quiz-text").html("クイズが始まるまでお待ちください…");
$("#yourname").html(name);
return false;
});
$('#answer-buttons-form button').click(function(){
$("#answer-buttons-form").hide();
stopwatchStop();
socket.emit('chat message', {"admin":false, "type":"answered", "name" : name, "answer" : $(this).text(), "time":parseFloat(answertime)} );
$("#quiz-text").html("回答を送信しました。<br/>司会の指示をお待ちください。");
stopwatchClear();
return false;
});
socket.on('chat message', function(msg){
console.log(msg);
if (msg.admin == true && name != "") {
if(msg.type == "data-gameover-user"){
gameover_user = msg.content;
if(gameover_user.indexOf(name) != -1){
gameover = true;
$("#quiz-text").html("ラウンドが終了するまで回答できません。");
}else{
gameover = false;
}
}
if(!gameover){
if(msg.type == "quiz"){
$("#quiz-text").html(msg.content);
}
if(msg.type == "start"){
stopwatchStart();
$("#answer-buttons-form").show();
}
if(msg.type == "finish") {
stopwatchStop();
$("#answer-buttons-form").hide();
$("#quiz-text").html("回答の受付は終了いたしました。<br/>司会の指示をお待ちください。");
stopwatchClear();
}
}
}
});
});
var $enable = false, $stopwatchTime, $startTime, $stopwatchTimeAdd = 0;
var answertime = "";
function stopwatchStart() {
if( $startTime === undefined ){
var $startDate = new Date();
$startTime = $startDate.getTime();
}
var $nowDate = new Date();
$stopwatchTime = $nowDate.getTime() - $startTime + $stopwatchTimeAdd;
$stopwatchMillisecond = $stopwatchTime % 1000;
$stopwatchSecond = Math.floor( $stopwatchTime / 1000 ) % 60;
$stopwatchMinute = Math.floor( $stopwatchTime / 1000 / 60 ) % 60;
$stopwatchHour = Math.floor( Math.floor( $stopwatchTime / 1000 / 60 ) / 60 );
if( $stopwatchMillisecond < 10 ){
$stopwatchMillisecond = '0' + $stopwatchMillisecond;
}
if( $stopwatchMillisecond < 100 ){
$stopwatchMillisecond = '0' + $stopwatchMillisecond;
}
if( $stopwatchSecond < 10 ){
// $stopwatchSecond = '0' + $stopwatchSecond;
}
if( $stopwatchMinute < 10 ){
$stopwatchMinute = '0' + $stopwatchMinute;
}
if( $stopwatchHour < 10 ){
$stopwatchHour = '0' + $stopwatchHour;
}
// jQuery( '#stopwatchHour' ).text( $stopwatchHour );
// var min = $stopwatchMinute.toString();
var second = $stopwatchSecond.toString();
var mill = $stopwatchMillisecond.toString();
// console.log(second+mill);
answertime = second + "." + mill;
$stopwatch = setTimeout( "stopwatchStart()", 1 );
}
function stopwatchStop() {
clearTimeout( $stopwatch );
$startTime = undefined;
$stopwatchTimeAdd = $stopwatchTime;
}
function stopwatchClear() {
$startTime = undefined;
$stopwatchTimeAdd = 0;
}
</script>
</body>
</html>