-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
376 lines (321 loc) · 12.4 KB
/
index.html
File metadata and controls
376 lines (321 loc) · 12.4 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Zodiax - Guess star signs</title>
<meta name="description" content="When is each star sign? Try to find out with this simple guessing game." />
<meta name="keywords" content="zodiac,star sign, learn, when, date, game" />
<meta name="author" content="Marques Xiaomi" />
<meta name="copyright" content="Maxim Schulz" />
<meta name="page-topic" content="Sternzeichen" />
<meta http-equiv="Reply-to" content="maxim@omg.lol" />
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.15/dist/tailwind.min.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
.dark {
background-color: #1a1a1a;
color: white;
}
</style>
</head>
<body class="flex flex-col min-h-screen">
<header class="bg-purple-700 py-4 flex items-center justify-between">
<div class="ml-4 container mx-auto">
<h1 class="text-white text-4xl font-bold">Welcome to Zodiax!</h1>
</div>
<a href="index_de.html" class="block mr-4">
<button class="bg-white text-purple-700 font-bold py-2 px-4 rounded hover:bg-gray-100">
Deutsch
</button>
</a>
</header>
<main class="container mx-auto py-8 flex-grow">
<section class="rounded-lg shadow-lg p-6">
<form>
<fieldset class="mt-4">
<legend class="text-xl font-bold mb-6">Question: What zodiac sign is on <u id="date">February, 14th</u>?</legend>
<div class="lg:flex lg:flex-wrap lg:-mx-2 space-y-4" id="answers">
<label class="flex items-center lg:w-1/2 lg:px-2">
<input type="radio" name="answer" value="1">
<span class="ml-2">♑️ Capricorn (Goat)</span>
</label>
<label class="flex items-center lg:w-1/2 lg:px-2"">
<input type="radio" name="answer" value="2">
<span class="ml-2">♒️ Aquarius (Water bearer)</span>
</label>
<label class="flex items-center lg:w-1/2 lg:px-2"">
<input type="radio" name="answer" value="3">
<span class="ml-2">♓️ Pisces (Fishes)</span>
</label>
<label class="flex items-center lg:w-1/2 lg:px-2"">
<input type="radio" name="answer" value="4">
<span class="ml-2">♈️ Aries (Ram)</span>
</label>
<label class="flex items-center lg:w-1/2 lg:px-2"">
<input type="radio" name="answer" value="5">
<span class="ml-2">♉️ Taurus (Bull)</span>
</label>
<label class="flex items-center lg:w-1/2 lg:px-2"">
<input type="radio" name="answer" value="6">
<span class="ml-2">♊️ Gemini (Twins)</span>
</label>
<label class="flex items-center lg:w-1/2 lg:px-2"">
<input type="radio" name="answer" value="7">
<span class="ml-2">♋️ Cancer (Crab)</span>
</label>
<label class="flex items-center lg:w-1/2 lg:px-2"">
<input type="radio" name="answer" value="8">
<span class="ml-2">♌️ Leo (Lion)</span>
</label>
<label class="flex items-center lg:w-1/2 lg:px-2"">
<input type="radio" name="answer" value="9">
<span class="ml-2">♍️ Virgo (Virgin)</span>
</label>
<label class="flex items-center lg:w-1/2 lg:px-2"">
<input type="radio" name="answer" value="10">
<span class="ml-2">♎️ Libra (Scales)</span>
</label>
<label class="flex items-center lg:w-1/2 lg:px-2"">
<input type="radio" name="answer" value="11">
<span class="ml-2">♏️ Scorpio (Scorpion)</span>
</label>
<label class="flex items-center lg:w-1/2 lg:px-2"">
<input type="radio" name="answer" value="12">
<span class="ml-2">♐️ Sagittarius (Archer)</span>
</label>
</div>
</fieldset>
<button type ="button" id="showResult" class="bg-purple-600 hover:bg-purple-700 text-white font-bold py-2 px-4 rounded mt-4">
Check
</button>
<p id="errorMsg" class="hidden text-red-500">Please choose one</p>
<label class="flex items-center">
<input type="checkbox" class="form-checkbox mr-2" id="shuffle">
<span>Shuffle Answers</span>
</label>
</form>
</section>
</main>
<div id="popupOverlay" class="fixed top-0 left-0 w-full h-full bg-gray-800 bg-opacity-50 flex justify-center items-center hidden">
<div id="popupContent" class="text-white p-8 rounded-lg shadow-lg">
<div class="flex items-center justify-between mb-4">
<h2 id="popupTitle" class="text-2xl font-bold">You are right!</h2>
<p id="correctAnswers" class="text-sm font-semibold text-gray-300">0/0 correct</p>
</div>
<p id="popupContentReal">Zodiaxxx</p>
<button id="newQuestion" class="bg-purple-600 hover:bg-purple-700 text-white font-bold py-2 px-4 rounded mt-4 border border-white">
New Question
</button>
</div>
</div>
<footer class="bg-gray-800 py-4">
<div class="flex justify-center">
<button id="darkModeToggle" class="bg-gray-600 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded mt-4 mb-4">Toggle Nightmode</button>
</div>
<div class="container mx-auto text-center">
<p class="text-gray-600">© 2023 Zodiax. All rights reserved.</p>
</div>
</footer>
</body>
<script>
$(document).ready(onSiteLoad);
let correctZodiac;
let correctZodiacsCount = 0;
let totalZodiacsCount = 0;
let doShuffle = false;
const zodiacs = {
1: {
name: '♑️ Capricorn (Goat)',
nameSimple: 'Capricorn',
start: 355,
end: 18,
},
2: {
name: '♒️ Aquarius (Water bearer)',
nameSimple: 'Aquarius',
start: 19,
end: 48,
},
3: {
name: '♓️ Pisces (Fishes)',
nameSimple: 'Pisces',
start: 49,
end: 78,
},
4: {
name: '♈️ Aries (Ram)',
nameSimple: 'Aries',
start: 79,
end: 108,
},
5: {
name: '♉️ Taurus (Bull)',
nameSimple: 'Taurus',
start: 109,
end: 139,
},
6: {
name: '♊️ Gemini (Twins)',
nameSimple: 'Gemini',
start: 140,
end: 171,
},
7: {
name: '♋️ Cancer (Crab)',
nameSimple: 'Cancer',
start: 172,
end: 202,
},
8: {
name: '♌️ Leo (Lion)',
nameSimple: 'Leo',
start: 203,
end: 233,
},
9: {
name: '♍️ Virgo (Virgin)',
nameSimple: 'Virgo',
start: 234,
end: 264,
},
10: {
name: '♎️ Libra (Scales)',
nameSimple: 'Libra',
start: 265,
end: 294,
},
11: {
name: '♏️ Scorpio (Scorpion)',
nameSimple: 'Scorpio',
start: 295,
end: 324,
},
12: {
name: '♐️ Sagittarius (Archer)',
nameSimple: 'Sagittarius',
start: 325,
end: 354,
}
}
function onSiteLoad() {
generateDate();
$('#showResult').on('click', showResult);
$('#newQuestion').on('click', newQuestion);
$('#shuffle').on('change', shuffleAnswers);
$('#darkModeToggle').on('click', darkModeToggle);
setDarkModePreference();
}
function setDarkModePreference() {
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
$('html').addClass('dark');
}
}
function darkModeToggle () {
console.log("Toggle Darkmode");
$('html').toggleClass('dark');
$('#shuffle').on('change', shuffleAnswers);
}
function showResult () {
if ($('input[name="answer"]:checked').length === 0) {
$('#errorMsg').removeClass('hidden');
return;
}
const selectedValue = $('input[type="radio"][name="answer"]:checked').val(); //get the form value
$('input[type="radio"][name="answer"]').prop("checked", false); //uncheck the form
totalZodiacsCount++;
const choosenZodiac = zodiacs[selectedValue].nameSimple;
const choosenZodiacStart = outputDate(zodiacs[selectedValue].start);
const choosenZodiacEnd = outputDate(zodiacs[selectedValue].end);
const correctZodiacName = zodiacs[correctZodiac].nameSimple;
if (selectedValue == correctZodiac) {
correctZodiacsCount++;
$('#popupTitle').html("You are right!");
$('#popupContentReal').html(`${choosenZodiac} is between ${choosenZodiacStart} and ${choosenZodiacEnd}.`);
$('#correctAnswers').html(`${correctZodiacsCount}/${totalZodiacsCount} correct`);
$('#popupContent').addClass('bg-green-500');
$('#popupContent').removeClass('bg-red-500');
} else {
$('#popupTitle').html("You are wrong!");
$('#popupContentReal').html(`<b>${correctZodiacName}</b> is the right one. <br> ${choosenZodiac} is between ${choosenZodiacStart} and ${choosenZodiacEnd}.`);
$('#correctAnswers').html(`${correctZodiacsCount}/${totalZodiacsCount} correct`);
$('#popupContent').removeClass('bg-green-500');
$('#popupContent').addClass('bg-red-500');
}
$('#popupOverlay').removeClass('hidden');
$('#errorMsg').addClass('hidden');
}
function newQuestion () {
shuffleAnswers();
$('#popupOverlay').addClass('hidden');
generateDate();
$("html, body").animate({ scrollTop: 0 }, "slow");
}
function getZodiacSign(day) {
for (const key in zodiacs) {
const zodiac = zodiacs[key];
// Handle the wrap-around case for each zodiac sign
if (zodiac.start <= zodiac.end) {
if (day >= zodiac.start && day <= zodiac.end) {
return key;
}
} else {
if ((day >= zodiac.start && day <= 364) || (day >= 0 && day <= zodiac.end)) {
return key;
}
}
}
}
function generateDate() {
const daysOfYear = 365;
let randomValue = Math.floor(Math.random() * daysOfYear); // Generate random value from 0 to 364
correctZodiac = getZodiacSign(randomValue);
date = outputDate(randomValue);
$("#date").html(date) ;
}
function outputDate (day) {
// Create a date object for January 1st of the current year
const startDate = new Date(new Date().getFullYear(), 0, 1);
// Add the day to the start date
const generatedDate = new Date(startDate.getTime() + day * 24 * 60 * 60 * 1000);
// Get the day and month from the generated date
const day_ = generatedDate.getDate();
const month = generatedDate.toLocaleString('en-US', { month: 'long' });
return `${month}, ${day_}${getOrdinalSuffix(day_)}`;
}
// Function to get the ordinal suffix (e.g., 1st, 2nd, 3rd, 4th, etc.)
function getOrdinalSuffix(i) {
var j = i % 10,
k = i % 100;
if (j == 1 && k != 11) {
return "st";
}
if (j == 2 && k != 12) {
return "nd";
}
if (j == 3 && k != 13) {
return "rd";
}
return "th";
}
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}
function shuffleAnswers() {
if($('#shuffle').prop('checked')) {
const answersContainer = $("#answers");
const answerLabels = answersContainer.find(".flex");
const answersArray = Array.from(answerLabels);
const shuffledAnswers = shuffleArray(answersArray);
answersContainer.empty();
shuffledAnswers.forEach((answer) => {
answersContainer.append(answer);
});
}
}
</script>
</html>