-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathmatch.html
261 lines (215 loc) · 6.83 KB
/
match.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
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Terorist Quiz</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 0;
padding: 0;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
}
@media screen and (min-width: 768px) {
.container {
max-width: 760px;
margin: 0 auto;
padding: 20px;
}
}
.people {
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
gap: 4px;
}
.options {
display: flex;
justify-content: center;
flex-wrap: wrap;
margin-bottom: 17.44px;
}
.options .droppable {
margin-right: 4px;
margin-bottom: 4px;
}
.options .droppable:not(.draggable-dropzone--occupied) {
min-width: 60px;
border: 2px dashed black;
height: 26.5px;
}
.options .answer-draggable {
padding: 4px;
border: 2px solid black;
}
.options .answer-draggable span {
pointer-events: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.person {
flex: 0 0 47%;
}
@media screen and (min-width: 768px) {
.person {
flex: 0 0 24%;
}
}
.person img {
width: 100%;
aspect-ratio: 3 / 4;
}
.person .droppable {
display: flex;
align-items: center;
justify-content: center;
border: 2px dashed black;
width: 100%;
height: 40px;
}
.person .droppable.answer--correct {
color: green;
}
.person .droppable.answer--incorrect {
color: red;
}
.button--play-again {
margin: 15px;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script defer src="https://analytics.eu.umami.is/script.js" data-website-id="c21f2db2-88e9-4f47-931e-106a38134e74"></script>
</head>
<body>
<div class="container">
<h1>Terorist - Orgut Eslestir</h1>
<p>Asagidaki orgutleri surukleyip birakarak gorsellerle eslestir.</p>
<div id="quiz-container"></div>
</div>
<script type="module">
import { Droppable } from 'https://cdn.jsdelivr.net/npm/@shopify/draggable@1.1.3/+esm'
async function fetchTerroristData() {
try {
const response = await fetch('https://raw.githubusercontent.com/osumatu/terorist-quiz/main/data.json');
if (!response.ok) {
throw new Error('Failed to fetch data');
}
const data = await response.json();
return data.filter((terrorist) => !!terrorist.GorselURL?.length);
} catch (error) {
console.error('Error fetching data:', error);
return [];
}
}
async function displayQuiz() {
const terroristData = await fetchTerroristData();
if (terroristData.length === 0) {
alert('Failed to fetch data. Please try again later.');
return;
}
const board = [];
const allOrganisations = terroristData.map((t) => t.TOrgutAdi).filter((v, i, a) => a.indexOf(v) === i);
const randomOrganisations = allOrganisations.sort(() => 0.5 - Math.random()).slice(0, 4);
for (let i = 0; i < 4; i++) {
const organisation = randomOrganisations[i];
const [terrorist] = terroristData.filter((t) => t.TOrgutAdi === organisation).sort(() => 0.5 - Math.random());
board.push(terrorist);
}
const shuffled = board
.map(value => ({ value, sort: Math.random() }))
.sort((a, b) => a.sort - b.sort)
.map(({ value }) => value)
const quizContainer = document.getElementById('quiz-container');
quizContainer.innerHTML = `<div class="options">
${shuffled.map((person) => {
return `<div class="droppable draggable-dropzone--occupied">
<div class="answer-draggable" data-org="${person.TOrgutAdi}"><span>${person.TOrgutAdi}</span></div>
</div>`;
}).join('')}
</div>
<div class="people">
${board.map((person) => {
return `<div class="person">
<img src="https://www.terorarananlar.pol.tr/${person.IlkGorselURL}" alt="Terrorist Image">
<div class="droppable" data-org="${person.TOrgutAdi}"></div>
</div>`;
}).join('')}
</div>`;
const optionsElement = document.querySelector('.options');
optionsElement.style.height = `${optionsElement.clientHeight}px`;
const droppable = new Droppable(document.querySelectorAll('#quiz-container'), {
draggable: '.answer-draggable',
dropzone: '.droppable',
});
droppable.on('droppable:stop', (evt) => {
const zones = Array.from(document.querySelectorAll('.person .droppable'));
const allFilled = zones.every((zone) => zone.classList.contains('draggable-dropzone--occupied'));
if (!allFilled) {
return;
}
let correct = 0;
zones.forEach((zone) => {
const answer = zone.firstChild;
if (answer && answer.dataset.org === zone.dataset.org) {
correct++;
}
});
let title = '';
if (correct === 4) {
title = 'MIT goreve cagiriyor!';
} else if (correct === 3) {
title = 'Yuru be babus!';
} else if (correct === 2) {
title = 'Ha gayret.';
} else {
title = 'Hocam goz var izan var ya.';
}
Swal.fire({
title: title,
text: `4 orgutten ${correct} tanesini dogru eslestirdin.`,
confirmButtonText: 'Tekrar Oyna',
icon: 'info',
...((correct < 4) && {
showCancelButton: true,
cancelButtonText: 'Cevaplara Bakayim',
}),
}).then((result) => {
if (result.isConfirmed) {
window.location.reload();
} else {
optionsElement.remove();
zones.forEach((zone) => {
const answer = zone.firstChild;
if (answer.dataset.org === zone.dataset.org) {
zone.classList.add('answer--correct');
} else {
zone.classList.add('answer--incorrect');
answer.firstChild.innerHTML = zone.dataset.org;
}
});
const replayButton = document.createElement('button');
replayButton.innerText = 'Tekrar Oyna';
replayButton.onclick = () => window.location.reload();
replayButton.classList.add('button--play-again');
document.querySelector('.container').append(replayButton);
}
});
});
}
window.onload = function() {
displayQuiz();
};
</script>
</body>
</html>