-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
306 lines (282 loc) · 8.79 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
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
<html>
<head>
<title>進制轉換Quiz</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="stylesheet" type="text/css" href="lib/css/bootstrap.min.css">
<link rel="stylesheet" href="lib/css/animate.css">
<link rel="stylesheet" href="lib/css/sweetalert2.min.css">
<link rel="stylesheet" href="assets/css/gigantic-screen.css" />
<link rel="stylesheet" media="only screen and (max-width: 900px)" href="assets/css/large-screen.css" />
<link rel="stylesheet" media="only screen and (max-width: 700px)" href="assets/css/median-screen.css" />
<script src="lib/js/jquery.js"></script>
<script src="lib/js/sweetalert2.min.js"></script>
<script>
/*
* @countdown: goalSec
# @challenge_count: goalToSuccess
* @countdown: leftSec
*
*/
var Global = {'fcur_count':0,'cur_count':0,'challenge_mode':false,'countdown':60,'_countdown':0,'challenge_count':50,'err_penalty':2}
$(function(){
$("<audio id=\"correct_audio\" style='display:none;'><source src='assets/audio/correct-trim.mp3'/></audio>").appendTo('body')
setCountDisplay(Global.cur_count)
$("#f_count").text(Global.fcur_count);
$.get('generate_qa/25',function(data,res){
Global.pairs = getPairs(data)
chg_thematic(Global.pairs.pop())
eventRegister()
})
});
function challenge_init() {
Global.cur_count=0
Global.challenge_mode = true
Global._countdown = Global.countdown
$('#bg').css({"background-color":"rgb(237, 197, 63)"});
$("#count").css({'margin-right':'0'});
$(".f_remind").css({'display':'none'})
$("#f_count").css({'display':'none'})
$("#normal").css({'display':'inline-block','margin-top':'5px'})
$('#lookans').remove()
$('#surprise').remove()
chg_thematic(Global.pairs.pop());
setTitle(Global.count_down)
$('.count_remind').text('剩餘題數')
setCountDisplay(Global.challenge_count - Global.cur_count)
}
function setCountDisplay(str) {
$("#count").text(str);
}
function eventRegister() {
$("#lookans").on('click', function(){
swal("請盡量自行計算", $("#answer").val(),'warning');
});
$("#surprise").on('click', function(){
challenge_init()
swal({
title:"成功條件",
text:'請於'+Global.countdown+'秒內"連續"答對'+Global.challenge_count+'題\n若錯誤一次扣秒數'+Global.err_penalty+'秒',
type:'info',
allowOutsideClick:false
}).then(
function(){
count_down(Global.countdown)
$('h1').css({'color':'#FE2E64','font-size':'110px'})
}
)
})
$('.option').on('click', function(){
if($("#answer").val() == $(this).val()){
playCorrectSound()
++Global.cur_count
chg_thematic(Global.pairs.pop());
$('#bg').css({"background-color":"rgb(237, 197, 63)"});
setCountDisplay(Global.cur_count)
if(Global.challenge_mode) {
score = Global.challenge_count - (Global.cur_count)
if(score<=0) {
score = "太厲害啦!"
}
setCountDisplay(score)
}
}else{
$('#bg').css({"background-color":"red"});
$("#f_count").text(++Global.fcur_count);
if(Global.challenge_mode === true) {
Global._countdown = Global._countdown - Global.err_penalty
if(Global._countdown<=0) {
Global._countdown = 0
challenge_check()
}
setTitle(Global._countdown)
}
}
})
}
function playCorrectSound() {
$('#correct_audio')[0].play()
}
function challenge_check(str) {
if(Global.challenge_mode && Global.cur_count>=Global.challenge_count) {
swal({
title: "挑戰成功",
text: "請在下方留下你的大名",
input:"text",
closeOnConfirm: false,
animation: "slide-from-top",
inputPlaceholder: "暱稱",
type:"success",
allowOutsideClick:false
}).then(
function(inputValue){
if (inputValue.trim() === "" || null) {
inputValue = "不知名的你"
}
/*
如果你都願意進來看Source Code了,那麼我想你一定是有需要的人
這邊有一份電子書:https://tinyurl.com/4c88dyny
希望對你有所幫助!(但還是破一下關卡嘛,真的挺有趣的)
*/
swal({
title:"給"+inputValue+"的小祝福!",
html:"<p>感謝您的支持!<br>下方連結為之前找到的電子書PDF,希望對您能有所幫助<br><a target=\"_blank\" href=\"https://tinyurl.com/4c88dyny\">https://tinyurl.com/4c88dyny</a><br>祝 考上心中理想志願。</p>",
type:"question",
allowOutsideClick:false
}).then(function(){
location.reload()
})
})
return false
}
var str = str || ""
swal({
title: "挑戰失敗",
text: "再來一局?",
type: "error",
animation: false,
customClass: 'animated bounceInDown',
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "好的",
cancelButtonText: "回練習模式",
closeOnConfirm: false,
closeOnCancel: false,
allowOutsideClick:false
}).then(
function(){
swal({
title: "預備",
text: "即將開始..",
timer: 1000,
showConfirmButton: false,
allowOutsideClick:false
}).then(
function () {},
// handling the promise rejection
function() {
challenge_init()
count_down(Global._countdown)
})
},
function() {
location.reload()
}
)
}
function setTitle(str) {
$('h1').text(str)
}
function count_down() {
setTitle(Global._countdown)
if(Global._countdown<=0) {
setTitle(0)
challenge_check('Time\'s up\n')
return
}
setTimeout(function(){
count_down(--Global._countdown)
},1000)
}
function gen_format(type,q) {
var res = ""
var pre = "(" + q + ")"
var pre_under = ""
var post = "( ? )"
var post_under = ""
switch(type) {
case "base2to10":
pre_under = "2"
post_under = "10"
break
case "base10to2":
pre_under = "10"
post_under = "2"
break
case "base10to16":
pre_under = "10"
post_under = "16"
break
case "sqrt10":
pre = q
post = "2^?"
break
case "pow10":
pre = q
post = "?"
break
}
res = pre+"<span class=\"base\">"+pre_under+"</span>="+post+"<span class=\"base\">"+post_under+"</span>"
return res
}
function chg_thematic(data){
let q = data.ques,
opt = data.ans,
pos = data.correct_position,
type = data.type,
a = opt[pos]
$("#thematic").html(gen_format(type,q));
$("#answer").val(a);
for(let i=0;i<4;i++) {
$('.option')[i].value = opt[i]
$('.option')[i].textContent = opt[i]
}
}
function getPairs(obj) {
var _obj = obj || {},
fn = {},
_num = Object.keys(obj).length
fn.pop = function() {
if(_num<0) return null
else if(_num<5) {
setTimeout(function(){
$.get('generate_qa/25',function(data,res){
Global.pairs = getPairs(data)
})
},0)
}
return obj[--_num]
}
return fn
}
function fix_mobile_hover() {
var el = this;
var par = el.parentNode;
var next = el.nextSibling;
par.removeChild(el);
par.insertBefore(el, next);
}
</script>
</head>
<body style="background-color:rgb(250, 248, 239);font-family: 'Clear Sans', 'Helvetica Neue', Arial, sans-serif;">
<div class="container">
<div style="text-align:center;">
<h1 style="font-family: 'Clear Sans', 'Helvetica Neue', Arial, sans-serif;color:rgb(119, 110, 101);">Quick Test</h1>
<span class="count_remind" style="font-family: '微軟正黑體';font-size:20px;color:rgb(119, 110, 101);">累計題數:</span>
<span id="count"></span>
<span class="f_remind"style="font-family: '微軟正黑體';font-size:20px;color:rgb(119, 110, 101);">答錯次數:</span>
<span id="f_count"></span>
</div>
<div style="padding:2%;text-align:center">
<div id="bg">
<p id="thematic"></p>
</div>
<button id="surprise" class="btn btn-danger">挑戰模式</button>
<button id="lookans" class="btn btn-info">查看答案</button>
<button id="normal" class="btn btn-primary" style="display:none" onclick="location.reload()">練習模式</button>
</div>
<div style="padding:1%;">
<div style="text-align:center"><button id="1" class="option btn" value="" ontouchend="this.onclick=fix_mobile_hover"></button><button id="2" class="option btn" value="" ontouchend="this.onclick=fix_mobile_hover"></button></div>
<div style="text-align:center"><button id="3" class="option btn" value="" ontouchend="this.onclick=fix_mobile_hover"></button><button id="4" class="option btn" value="" ontouchend="this.onclick=fix_mobile_hover"></button></div>
<input id="answer" type="hidden"/>
</div>
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-76188489-2', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>