-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlesson.html
514 lines (444 loc) · 14.9 KB
/
lesson.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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
<!DOCTYPE html>
<html
lang="en"
data-bs-theme="auto">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1" />
<meta
name="description"
content="" />
<title>Word Guessing Game</title>
<link
href="css/bootstrap.min.css"
rel="stylesheet" />
<link
rel="stylesheet"
href="css/animate.min.css" />
<meta
name="theme-color"
content="#712cf9" />
<style>
.bd-placeholder-img {
font-size: 1.125rem;
text-anchor: middle;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
@media (min-width: 768px) {
.bd-placeholder-img-lg {
font-size: 3.5rem;
}
}
.b-example-divider {
width: 100%;
height: 0.1rem;
background-color: rgba(0, 0, 0, 0.1);
border: solid rgba(0, 0, 0, 0.15);
border-width: 1px 0;
box-shadow: inset 0 0.5em 1.5em rgba(0, 0, 0, 0.1),
inset 0 0.125em 0.5em rgba(0, 0, 0, 0.15);
}
.b-example-vr {
flex-shrink: 0;
width: 1.5rem;
height: 100vh;
}
.bi {
vertical-align: -0.125em;
fill: currentColor;
}
.nav-scroller {
position: relative;
z-index: 2;
height: 2.75rem;
overflow-y: hidden;
}
.nav-scroller .nav {
display: flex;
flex-wrap: nowrap;
padding-bottom: 1rem;
margin-top: -1px;
overflow-x: auto;
text-align: center;
white-space: nowrap;
-webkit-overflow-scrolling: touch;
}
.btn-bd-primary {
--bd-violet-bg: #252525;
--bd-violet-rgb: 112.520718, 44.062154, 249.437846;
--bs-btn-font-weight: 600;
--bs-btn-color: var(--bs-white);
--bs-btn-bg: var(--bd-violet-bg);
--bs-btn-border-color: var(--bd-violet-bg);
--bs-btn-hover-color: var(--bs-white);
--bs-btn-hover-bg: #252525;
--bs-btn-hover-border-color: #252525;
--bs-btn-focus-shadow-rgb: var(--bd-violet-rgb);
--bs-btn-active-color: var(--bs-btn-hover-color);
--bs-btn-active-bg: #252525;
--bs-btn-active-border-color: #252525;
color: #fff;
}
.bd-mode-toggle {
z-index: 1500;
}
</style>
<!-- Custom styles for this template -->
<link
href="css/dropdowns.css"
rel="stylesheet" />
</head>
<body id="main-body">
<div class="py-0 mb-0">
<header
class="bd-header bg-dark py-1 d-flex align-items-stretch border-bottom border-dark">
<div class="container-fluid d-flex align-items-center">
<h4 class="d-flex align-items-center fs-6 text-white mb-0">
Englist Helper
</h4>
<a
href="index.html"
class="ms-auto link-light"
hreflang="ar">
🏠
</a>
</div>
</header>
</div>
<div
class="dropdown position-fixed bottom-0 end-0 mb-1 me-3 bd-mode-toggle">
<button
class="btn btn-bd-primary py-2 d-flex align-items-center"
id="bd-theme"
type="button"
onclick="showScore()"
data-bs-toggle="dropdown">
<span id="score">0</span>
✅
<span id="wrong-score">0</span>
❌
<span id="max-score">0</span>
📖 : SCORE
</button>
</div>
<div
class="d-flex flex-column flex-wrap flex-md-row p-2 gap-4 py-md-2 align-items-center justify-content-center"
id="content"></div>
<div
id="result-content"
style="display: none">
<div
class="d-flex flex-column flex-wrap flex-md-row p-4 gap-4 py-md-2 align-items-center justify-content-center"
id="hidden-content"
style="margin-top: 500px"></div>
</div>
<div
id="myModal"
class="modal"
tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Score Result</h5>
<button
type="button"
class="btn-close"
data-bs-dismiss="modal"
aria-label="Close"></button>
</div>
<div class="modal-body">
<p><span id="SCORE-RESULT"></span></p>
</div>
<div class="modal-footer">
<button
type="button"
class="btn btn-secondary"
data-bs-dismiss="modal">
Close
</button>
</div>
</div>
</div>
</div>
<script src="js/bootstrap.bundle.min.js"></script>
<script src="js/jquery-3.7.0.min.js"></script>
<script src="js/jquery.confetti.js"></script>
<script>
const myModalAlternative = new bootstrap.Modal("#myModal", {});
var _MAX_COUNT_TIME = 1;
var _REPEAT_WORD = 5;
var word_array = [];
var is_answered = [];
var _CURRENT_SCORE = 0;
var _CURRENT_WRONG_SCORE = 0;
var _CLICKING_COUNT = 0;
var _PAGE_LOAD_COUNT = 0;
var _MAX_COUNT_CHECK = 0;
var WORD_ID = 0;
var WORD_PER_PAGE = 0;
var WORDS = [];
var WORDS_LENGTH = 0;
var WORD_TEMP_COUNT = 1;
var LESSON_ID = "";
function doCheer() {
$("#confettiCanvas").css({ "z-index": "5000" });
$.confetti.start();
setTimeout(function () {
$("#confettiCanvas").css({ "z-index": "1" });
$.confetti.stop();
}, 20000);
}
$(document).ready(function () {
var lesson_id = getUrlVars()["lesson_id"];
if (typeof lesson_id !== "undefined") {
LESSON_ID = lesson_id.replaceAll("#", "");
$.ajax({
url: "words/" + lesson_id + ".txt?v=" + Math.random(), // Replace with the actual path to your text file
dataType: "text",
success: function (data) {
var temp_words = data.split("\n");
temp_words = temp_words.map(function (line) {
return line.trim();
});
WORDS = temp_words;
WORDS_LENGTH = WORDS.length;
_MAX_COUNT_CHECK = _MAX_COUNT_TIME * WORDS_LENGTH * _REPEAT_WORD;
WORD_PER_PAGE = WORDS_LENGTH * _REPEAT_WORD;
getQuestion();
},
error: function (jqXHR, textStatus, errorThrown) {
console.log("Error:", textStatus, errorThrown);
},
});
} else {
window.location = "index.html";
}
});
function getQuestion() {
$("#max-score").html(_MAX_COUNT_CHECK);
$.get("block.html?q=" + Math.random(), function (page) {
for (var LOAD_TIME = 0; LOAD_TIME < _MAX_COUNT_TIME; ++LOAD_TIME) {
$.each(WORDS, function (k, word) {
for (var c = 0; c < _REPEAT_WORD; ++c) {
var word_length = word.length - 1;
var word_random_index = Math.floor(
Math.random() * (word_length + 1)
);
var word_must_fill = word[word_random_index];
//console.log(word + " = " + word_random_index);
//console.log(word_must_fill);
var new_word = replaceCharAtIndex(
word,
'<span class="animate__animated animate__infinite animate__slow animate__flash">_</span>',
word_random_index
);
var new_page = page.replace("_FULLWORD", new_word);
new_page = new_page.replaceAll(
"_IMAGE_FILE",
word + ".png?v=" + Math.random()
);
new_page = new_page.replaceAll("_WORD_DISPLAY_ID", WORD_ID + 1);
new_page = new_page.replaceAll("_LESSON_ID", LESSON_ID);
new_page = new_page.replaceAll("_WORD_ID", WORD_ID);
new_page = new_page.replace("_RESULT", "_RESULT_" + WORD_ID);
var charArray = [word_must_fill];
var win_index = Math.floor(Math.random() * 4);
for (var i = 0; i <= 3; ++i) {
var char_result = "";
//console.log(i + " = " + win_index);
if (i == win_index) {
char_result = word_must_fill;
new_page = new_page.replace(
'id="_CHOIC_' + i + '"',
'onclick="right(' +
WORD_ID +
", '" +
char_result +
"', '" +
word_must_fill +
"')\""
);
} else {
while (true) {
char_result = randomChar();
if ($.inArray(char_result, charArray) !== -1) {
continue;
}
charArray.push(char_result);
break;
}
new_page = new_page.replace(
'id="_CHOIC_' + i + '"',
'onclick="wrong(' +
WORD_ID +
", '" +
char_result +
"', '" +
word_must_fill +
"')\""
);
}
new_page = new_page.replace("_WORD-" + i, char_result);
}
$("#content").prepend(new_page);
WORD_ID++;
}
_PAGE_LOAD_COUNT++;
});
}
for (var i = 0; i <= _MAX_COUNT_CHECK; ++i) {
//console.log("HIDE = #WORD_ID-" + i);
$("#WORD_ID-" + i).hide();
$("#WORD_ID-" + i).toggleClass("d-block");
}
$("#WORD_ID-0").show();
$("#WORD_ID-0").toggleClass("d-block");
//$("#content").prepend('<div class="break b-example-divider"></div>');
});
}
function replaceCharAtIndex(str, newChar, index) {
return str.substr(0, index) + newChar + str.substr(index + 1);
}
function randomChar() {
var randomCharCode = Math.floor(Math.random() * 26) + 97; // ASCII value for 'a' is 97
var randomCharacter = String.fromCharCode(randomCharCode);
return randomCharacter;
}
function right(word_id, char_click, win_text) {
if ($.inArray(word_id, is_answered) === -1) {
var temp_value = $("#FULLWORD-" + word_id).html();
temp_value = temp_value.replaceAll(
'<span class="animate__animated animate__infinite animate__slow animate__flash">_</span>',
'<span class="text-success">' + win_text + "</span>"
);
$("#FULLWORD-" + word_id).html(temp_value);
is_answered.push(word_id);
$("#_RESULT_" + word_id).html(
'<span class="text-success">✅ CORRECT</span>'
);
$("#_RESULT_" + word_id).addClass(
"animate__animated animate__bounce"
);
++_CURRENT_SCORE;
_CLICKING_COUNT++;
$("#score").text(_CURRENT_SCORE);
if (_CLICKING_COUNT >= _MAX_COUNT_CHECK) {
$("#result-content").show();
showScore();
} else {
// if (_CLICKING_COUNT >= _PAGE_LOAD_COUNT * WORD_PER_PAGE) {
// getQuestion();
// }
hiddingBlock(word_id);
}
}
//alert("OK = " + word_id);
}
function wrong(word_id, char_click, win_text) {
if ($.inArray(word_id, is_answered) === -1) {
var temp_value = $("#FULLWORD-" + word_id).html();
temp_value = temp_value.replaceAll(
'<span class="animate__animated animate__infinite animate__slow animate__flash">_</span>',
'<span class="text-danger">' + win_text + "</span>"
);
$("#FULLWORD-" + word_id).html(temp_value);
is_answered.push(word_id);
$("#_RESULT_" + word_id).html(
'<span class="text-danger">❌ WRONG</span>'
);
$("#_RESULT_" + word_id).addClass(
"animate__animated animate__headShake"
);
++_CURRENT_WRONG_SCORE;
$("#wrong-score").text(_CURRENT_WRONG_SCORE);
_CLICKING_COUNT++;
if (_CLICKING_COUNT >= _MAX_COUNT_CHECK) {
$("#result-content").show();
showScore();
} else {
// if (_CLICKING_COUNT >= _PAGE_LOAD_COUNT * WORD_PER_PAGE) {
// getQuestion();
// }
hiddingBlock(word_id);
}
//alert("WRONG = " + word_id);
}
}
/*
✅
<span id="wrong-score">0</span>
❌
<span id="max-score">0</span>
📖 : SCORE
*/
function showScore() {
$("#SCORE-RESULT").html(
"Score is " +
$("#score").text() +
"✅" +
" " +
$("#wrong-score").text() +
"❌" +
" " +
$("#max-score").text() +
"📖" +
"<br>" +
percentage()
);
myModalAlternative.show();
}
function percentage() {
var percent = Math.floor(
(parseInt($("#score").text()) / parseInt($("#max-score").text())) *
100
);
if (percent < 80) {
return (
'<span class="display-3">' +
percent +
'% <span class="text-danger">❌ FAIL</span></span>'
);
} else {
doCheer();
return (
'<span class="display-3">' +
percent +
'% <span class="text-success">✅ PASS</span></span>'
);
}
}
function hiddingBlock(word_id) {
word_id = parseInt(word_id);
setTimeout(function () {
$("#WORD_ID-" + (word_id + 1)).show();
$("#WORD_ID-" + (word_id + 1)).toggleClass("d-block");
$("#WORD_ID-" + word_id).hide();
$("#WORD_ID-" + word_id).toggleClass("d-block");
$("#hidden-content").append(
'<div class="dropdown-menu d-block position-static border-0 pt-0 mx-0 rounded-3 shadow overflow-hidden w-280px" data-bs-theme="dark">' +
$("#WORD_ID-" + word_id).html() +
"</div>"
);
$("#WORD_ID-" + word_id).html("");
}, 1500);
}
function getUrlVars() {
var vars = [],
hash;
var hashes = window.location.href
.slice(window.location.href.indexOf("?") + 1)
.split("&");
for (var i = 0; i < hashes.length; i++) {
hash = hashes[i].split("=");
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
</script>
</body>
</html>