forked from KC3Kai/kancolle-replay
-
Notifications
You must be signed in to change notification settings - Fork 5
/
quiz-kanji.html
114 lines (99 loc) · 2.73 KB
/
quiz-kanji.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
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="js/kcSHIPDATA.js"></script>
<style>
div.outer {
margin-top:50px;
}
div.inner {
text-align: center;
padding:3px;
}
#divScore {
font-size:20px;
}
#spanTimer {
font-size:24px;
}
#spanQuestion {
font-size:20px;
}
</style>
</head>
<body>
<div class="outer">
<div class="inner" id="divScore">Score: <span id="spanScore">0</span></div>
<div class="inner"><span id="spanTimer">1:00</span></div>
<div class="inner"><input type="button" id="btnStart" value="Start" /></div>
<div class="inner"><span id="spanQuestion">test</span></div>
<div class="inner" id="divAnswer"><input id="txtAnswer" /><input type="button" id="btnSkip" value="Skip"/></div>
</div>
<script>
(function() {
function Quiz() {
this.time = 60;
this.currentId = 0;
this.done = [];
this.score = 0;
}
var QUIZ = new Quiz();
var QUESTIONS = [];
for (let mid in SHIPDATA) {
if (mid < 1000 && SHIPDATA[mid].prev == 0 && SHIPDATA[mid].nameJP && !(/\d/.test(SHIPDATA[mid].nameJP))
&& SHIPDATA[mid].nameJP.replace(' ','') != SHIPDATA[mid].name.replace(' ','')) {
QUESTIONS.push(mid);
}
}
function startTimer() {
var itvTimer = setInterval(function() {
QUIZ.time--;
let d = new Date(QUIZ.time*1000);
$('#spanTimer').text(d.toTimeString().substr(4,4));
if (QUIZ.time <= 0) {
clearInterval(itvTimer);
endQuiz();
}
}, 1000);
}
function endQuiz() {
$('#spanQuestion').hide();
$('#divAnswer').hide();
}
function nextQuestion() {
for (let i=0; i<1000; i++) {
QUIZ.currentId = QUESTIONS[Math.floor(Math.random()*QUESTIONS.length)];
if (QUIZ.done.indexOf(QUIZ.currentId) == -1) break;
}
$('#spanQuestion').text(SHIPDATA[QUIZ.currentId].nameJP);
$('#txtAnswer').val('');
}
function clearQuestion() {
QUIZ.done.push(QUIZ.currentId);
QUIZ.score++;
$('#spanScore').text(QUIZ.score);
nextQuestion();
}
function checkAnswer() {
let answer = $('#txtAnswer').val();
if (answer.toLowerCase().replace(' ','') == SHIPDATA[QUIZ.currentId].name.toLowerCase().replace(' ','')) clearQuestion();
}
$('#spanQuestion').hide();
$('#divAnswer').hide();
$('#btnStart').click(function() {
$('#spanQuestion').show();
$('#divAnswer').show();
$('#txtAnswer').focus();
$('#btnStart').hide();
startTimer();
nextQuestion();
});
$('#btnSkip').click(function() {
nextQuestion();
});
$('#txtAnswer').on('keyup',checkAnswer);
})();
</script>
</body>
</html>