-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
538 lines (476 loc) · 16.6 KB
/
index.html
File metadata and controls
538 lines (476 loc) · 16.6 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
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
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Basic Page Info -->
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>30 Seconds Game (Online, Free, Multi-Language)</title>
<meta
name="description"
content="Play the 30 Seconds Game online! A fast-paced word guessing game for family and friends, with multilingual support."
/>
<meta
name="keywords"
content="30 Seconds, word game, multiplayer, fun game, guessing game, online game"
/>
<!-- Social Media Preview -->
<meta property="og:title" content="30 Seconds Game Online" />
<meta
property="og:description"
content="Play the 30 Seconds Game online! A fun, fast-paced guessing game for all ages."
/>
<meta property="og:image" content="logo.png" />
<meta
property="og:url"
content="https://joost.github.io/30-seconds-game-online/"
/>
<meta name="twitter:card" content="summary_large_image" />
<!-- Favicons -->
<link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png" />
<link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<!-- Apple Touch Icon -->
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-title" content="30 Seconds Game" />
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
<link rel="apple-touch-icon" href="apple-touch-icon.png" />
<!-- Manifest for Android -->
<link rel="manifest" href="site.webmanifest" />
<meta name="theme-color" content="#ffffff" />
<!-- Allow "Add to Home Screen" for iOS -->
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-title" content="30 Seconds Game" />
<meta
name="apple-mobile-web-app-status-bar-style"
content="black-translucent"
/>
<!-- SEO Optimization -->
<meta name="robots" content="index, follow" />
<meta
name="viewport"
content="width=device-width,
initial-scale=1.0,
user-scalable=no,
maximum-scale=1.0"
/>
<!-- Bootstrap 5 CSS (CDN) -->
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"
/>
<style>
/* Body & Container Setup */
html,
body {
height: 100%;
margin: 0;
padding: 0;
overflow: hidden; /* Prevent scrolling on mobile */
}
body {
display: flex;
flex-direction: column;
background-color: #f8f9fa;
}
/* Language Bar at the top */
.language-bar {
flex-shrink: 0;
background-color: #fff;
border-bottom: 1px solid #ccc;
display: flex;
justify-content: center;
align-items: center;
padding: 0.5rem;
}
.language-bar .btn {
margin: 0 0.25rem;
}
.language-bar i {
margin-right: 0.25rem;
}
/* Main content area: center the card */
.main-container {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
}
/* Card Flipping Container */
.flip-container {
perspective: 1000px; /* for 3D flip effect */
width: 320px;
height: 350px;
position: relative;
}
/* .flipper holds front and back faces */
.flipper {
width: 100%;
height: 100%;
position: absolute;
transform-style: preserve-3d;
transition: transform 0.8s;
}
/* Add .flipped to rotate */
.flipped {
transform: rotateY(180deg);
}
/* List items styling */
.list-group-item {
display: flex;
align-items: center;
justify-content: space-between;
}
/* Info icon styling */
.list-group-item a {
text-decoration: none;
font-size: 1.2rem; /* Adjust icon size */
color: #007bff; /* Bootstrap primary color */
}
.list-group-item a:hover {
color: #0056b3; /* Hover color */
}
/* Front and Back faces of the card */
.front,
.back {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
top: 0;
left: 0;
border-radius: 0.5rem;
border: 1px solid rgba(0, 0, 0, 0.125);
background-color: #fff;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
display: flex;
flex-direction: column;
justify-content: space-between;
}
.front .card-body,
.back .card-body {
overflow: hidden;
}
.back {
transform: rotateY(180deg);
}
/* Keep the card content comfortably spaced */
.card-body {
padding: 1rem;
}
/* Timer text (larger, centered) */
#timerValue {
font-size: 2rem;
text-align: center;
}
/* Make sure it fits smaller devices */
@media (max-width: 350px) {
.flip-container {
width: 280px;
height: 420px;
}
}
/* Footer with GitHub link */
.footer {
gap: 10px;
flex-shrink: 0;
text-align: center;
padding: 0.5rem;
background-color: #fff;
border-top: 1px solid #ccc;
font-size: 0.9rem;
}
.footer a {
color: gray;
text-decoration: none;
}
.footer a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<!-- Language Switcher Bar -->
<div class="language-bar d-flex align-items-center">
<img src="logo.png" alt="Logo" style="height: 32px; margin-right: 10px" />
<div class="btn-group" role="group">
<!-- Each button uses a flag-icon class instead of an <img> -->
<button type="button" class="btn btn-light" id="lang-en">EN</button>
<button type="button" class="btn btn-light" id="lang-nl">NL</button>
<button type="button" class="btn btn-light" id="lang-fr">FR</button>
<button type="button" class="btn btn-light" id="lang-de">DE</button>
</div>
</div>
<!-- Main Container with the flipping card -->
<div class="main-container">
<div class="flip-container">
<div class="flipper" id="cardFlipper">
<!-- FRONT FACE -->
<div class="front d-flex flex-column" id="cardFront">
<div class="card-body">
<ul class="list-group mb-3" id="cardItems"></ul>
</div>
<div class="p-2">
<!-- Timer display + progress bar -->
<div id="timerValue">30</div>
<div class="progress mt-2" style="height: 8px">
<div
class="progress-bar bg-warning"
role="progressbar"
id="timerBar"
style="width: 100%"
aria-valuenow="100"
aria-valuemin="0"
aria-valuemax="100"
></div>
</div>
</div>
</div>
<!-- BACK FACE -->
<div class="back d-flex flex-column">
<div class="card-body">
<div class="mb-3 text-center">
<h5 class="card-title">Time is up! (or you flipped)</h5>
<p>Pick your next card or go back.</p>
</div>
<div class="d-flex justify-content-around">
<button id="btnBack" class="btn btn-secondary">Back</button>
<button id="btnNext" class="btn btn-primary">Next</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Footer -->
<div class="footer d-flex justify-content-center">
<a id="addToHomeScreen" class="btn btn-sm btn-link text-muted"
>Bookmark</a
>
<a id="shareLink" class="btn btn-sm btn-link text-muted">Share</a>
<a
href="https://github.com/joost/30-seconds-game-online"
target="_blank"
class="btn btn-sm btn-link text-muted"
>GitHub</a
>
</div>
<!-- Bootstrap 5 Bundle (with Popper) -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
// Globals
const TIME_LIMIT = 30; // total seconds
let cardsData = []; // current language's set of cards
let currentCardIndex = 0;
let intervalId = null;
let timeRemaining = TIME_LIMIT;
// UI Elements
const cardFlipper = document.getElementById("cardFlipper");
const cardFront = document.getElementById("cardFront");
const cardItems = document.getElementById("cardItems");
const timerValue = document.getElementById("timerValue");
const timerBar = document.getElementById("timerBar");
const btnBack = document.getElementById("btnBack");
const btnNext = document.getElementById("btnNext");
// Language buttons
const langNl = document.getElementById("lang-nl");
const langFr = document.getElementById("lang-fr");
const langDe = document.getElementById("lang-de");
const langEn = document.getElementById("lang-en");
// Initially load a default language, e.g., English
loadLanguage("en");
// Click handlers for the language switcher
langNl.addEventListener("click", () => loadLanguage("nl"));
langFr.addEventListener("click", () => loadLanguage("fr"));
langDe.addEventListener("click", () => loadLanguage("de"));
langEn.addEventListener("click", () => loadLanguage("en"));
// Loads the JSON file for the given language, randomizes the cards, starts the game
function loadLanguage(lang) {
const fileName = `cards-${lang}.json`;
// Stop any running timer
if (intervalId) {
clearInterval(intervalId);
intervalId = null;
}
fetch(fileName)
.then((resp) => resp.json())
.then((data) => {
cardsData = data.cards;
// Randomize the order of the cards
shuffle(cardsData);
currentCardIndex = 0;
showCard(currentCardIndex);
startTimer();
// If the card is flipped, flip it back to front
if (cardFlipper.classList.contains("flipped")) {
flipCard();
}
})
.catch((err) => {
console.error(`Error loading ${fileName}:`, err);
cardItems.innerHTML = `<li class="list-group-item text-danger">Error loading ${fileName}</li>`;
});
}
// Simple array shuffle (Fisher–Yates)
function shuffle(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]];
}
}
// Display the card at the given index
function showCard(index) {
if (!cardsData || index >= cardsData.length) {
cardItems.innerHTML = `<li class="list-group-item">Game Over</li>`;
return;
}
cardItems.innerHTML = "";
const currentItems = cardsData[index];
currentItems.forEach((item) => {
// Create a list item
const li = document.createElement("li");
li.className =
"list-group-item d-flex align-items-center justify-content-between";
// Add the word
const wordSpan = document.createElement("span");
wordSpan.textContent = item;
// Add the info icon
const infoIcon = document.createElement("a");
infoIcon.href = `https://www.google.com/search?q=${encodeURIComponent(
item
)}`;
infoIcon.target = "_blank";
infoIcon.rel = "noopener noreferrer";
infoIcon.innerHTML = "🔍"; // Replace with an actual icon if needed
infoIcon.addEventListener("click", (e) => e.stopPropagation());
// Append word and icon to the list item
li.appendChild(wordSpan);
li.appendChild(infoIcon);
// Add the list item to the cardItems container
cardItems.appendChild(li);
});
}
// 30-second countdown timer
function startTimer() {
// Clear any existing interval
if (intervalId) {
clearInterval(intervalId);
}
timeRemaining = TIME_LIMIT;
updateTimerUI();
intervalId = setInterval(() => {
timeRemaining--;
if (timeRemaining < 0) {
// Timer ended: flip the card to show the back
flipCard();
// // Move to next card after a short delay
// setTimeout(() => {
// flipCard();
// currentCardIndex++;
// if (currentCardIndex < cardsData.length) {
// showCard(currentCardIndex);
// startTimer();
// } else {
// // No more cards
// clearInterval(intervalId);
// cardItems.innerHTML = `<li class="list-group-item">Game Over</li>`;
// }
// }, 1500);
clearInterval(intervalId);
return;
}
updateTimerUI();
}, 1000);
}
// Update timer text + progress bar
function updateTimerUI() {
timerValue.textContent = timeRemaining;
const pct = (timeRemaining / TIME_LIMIT) * 100;
timerBar.style.width = pct + "%";
timerBar.setAttribute("aria-valuenow", pct);
}
// Clicking the FRONT of the card flips it (if not already flipped)
cardFront.addEventListener("click", () => {
if (!cardFlipper.classList.contains("flipped")) {
flipCard();
}
});
// Flip the card
function flipCard() {
cardFlipper.classList.toggle("flipped");
}
// Buttons on the BACK face
btnBack.addEventListener("click", () => {
// Flip to front if we're on the back
if (cardFlipper.classList.contains("flipped")) {
flipCard();
}
});
btnNext.addEventListener("click", () => {
// Move to next card
currentCardIndex++;
if (currentCardIndex < cardsData.length) {
showCard(currentCardIndex);
// Flip to front if on the back
if (cardFlipper.classList.contains("flipped")) {
flipCard();
}
startTimer();
} else {
// All cards done
clearInterval(intervalId);
cardItems.innerHTML = `<li class="list-group-item">Game Over</li>`;
if (cardFlipper.classList.contains("flipped")) {
flipCard();
}
}
});
// Add to home screen
let deferredPrompt; // Stores the event for later use
const addToHomeScreenButton = document.getElementById("addToHomeScreen");
// Listen for the `beforeinstallprompt` event (only works on supported browsers)
window.addEventListener("beforeinstallprompt", (e) => {
// Prevent the default mini-infobar from showing
e.preventDefault();
// Save the event for later use
deferredPrompt = e;
// Show the "Add to Home Screen" link
bookmarkLink.style.display = "inline-block";
// Add click event for the "Add to Home Screen" link
bookmarkLink.addEventListener("click", async (event) => {
event.preventDefault();
// Show the install prompt
deferredPrompt.prompt();
// Wait for the user's response
const choiceResult = await deferredPrompt.userChoice;
if (choiceResult.outcome === "accepted") {
console.log("User accepted the A2HS prompt");
} else {
console.log("User dismissed the A2HS prompt");
}
// Clear the deferred prompt variable
deferredPrompt = null;
});
});
const shareLink = document.getElementById("shareLink");
// Add click event for the "Share" link
shareLink.addEventListener("click", async (event) => {
event.preventDefault();
// Check if the Web Share API is supported
if (navigator.share) {
try {
await navigator.share({
title: "30 Seconds Game",
text: "Check out this fun 30 Seconds Game!",
url: window.location.href,
});
console.log("Share successful");
} catch (error) {
console.error("Error sharing:", error);
}
} else {
alert("Sharing is not supported on this browser.");
}
});
</script>
</body>
</html>