-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.html
More file actions
220 lines (192 loc) · 7.1 KB
/
Copy pathindex.html
File metadata and controls
220 lines (192 loc) · 7.1 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
<!DOCTYPE html>
<html lang="en">
<!-- stage.jpg Steve Jurvetson BY https://www.flickr.com/photos/jurvetson/6514526225/in/photolist-aVEDFF-aVEDEV -->
<!-- crowd.jpg "Metallica at Rock Werchter 2009 ♫♪" by crsan is licensed under CC BY 2.0. -->
<!-- Crowd Ooohs and Ahhhs in Excitement by noah0189 -- https://freesound.org/s/264499/ -- License: Creative Commons 0 -->
<!-- Micro_Clicks_001.wav by AlienXXX -- https://freesound.org/s/273833/ -- License: Attribution 4.0 -->
<head>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-D9YF31VXSD"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'G-D9YF31VXSD');
</script>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Jeopardy Game (CSV-upload)</title>
<script src="scripts/teamBox.js"></script>
<script src="scripts/modal.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.4.1/papaparse.min.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1 id="title">
<img id="logo" src="images/jeopardy-csv-logo.png" alt="Jeopardy CSV Logo">
<br />Jeopardy Game<br />
<div class="title-content">
<label for="csvFile" class="drop-zone">
<div class="drop-zone-content">
<div class="drop-icon">📂</div>
<div class="drop-text">Drag & Drop CSV Here<br><small>or click to browse</small></div>
</div>
</label>
<div class="title-section">
<h4>Sample game</h4>
</div>
<a href="https://github.com/domlet/jeopardy-csv?tab=readme-ov-file#jeopardy-csv" target="_blank">
<div class="title-section">
<h4>Instructions</h4>
</div>
</a>
</div>
<input type="file" id="csvFile" accept=".csv" style="display:none;">
</h1>
<div id="game"></div>
<audio id="click-sound" src="sounds/valve.mp3"></audio>
<audio id="ooh-sound" src="sounds/264499__noah0189__crowd-ooohs-and-ahhhs-in-excitement.mp3"></audio>
<audio id="microclick-sound" src="sounds/273833__alienxxx__micro_clicks_001.wav"></audio>
<audio id="timeout-sound" src="sounds/timeout.mp3"></audio>
<div id="modal">
<div id="modal-header">
<span id="modal-label">Clue</span>
</div>
<div id="modal-content">
<div id="clue"></div>
<button id="show-answer">?</button>
<div id="answer" style="display:none; margin-top:1rem;"></div>
<button id="close-btn" aria-label="Close">×</button>
</div>
</div>
<script>
// game
const fileInput = document.getElementById('csvFile');
const gameDiv = document.getElementById('game');
const title = document.getElementById('title');
// modal
const modal = document.getElementById('modal');
const clueDiv = document.getElementById('clue');
const answerDiv = document.getElementById('answer');
const showAnswerBtn = document.getElementById('show-answer');
const closeBtn = document.getElementById('close-btn');
// sounds
const clickSound = document.getElementById('click-sound');
const oohSound = document.getElementById('ooh-sound');
const microclickSound = document.getElementById('microclick-sound');
const timeoutSound = document.getElementById('timeout-sound');
let boardData = {};
let teams = [
{ name: "Team 1", score: 0 },
{ name: "Team 2", score: 0 }
];
// Initialize modal logic
initModalLogic({
showAnswerBtn,
answerDiv,
oohSound,
closeBtn,
modal,
timeoutSound
});
// link to play the sample game (on initial screen)
document.querySelector('.title-section').addEventListener('click', function () {
if (this.querySelector('h4').textContent.trim() === 'Sample game') {
fetch('sample.csv')
.then(response => {
if (!response.ok) throw new Error('No sample.csv found');
return response.text();
})
.then(csvText => {
Papa.parse(csvText, {
header: true,
complete: function (results) {
title.style.display = 'none';
fileInput.style.display = 'none';
buildBoard(results.data);
}
});
})
.catch(() => {
alert('sample.csv not found.');
});
}
});
function parseAndBuild(file) {
Papa.parse(file, {
header: true,
complete: function (results) {
title.style.display = 'none';
fileInput.style.display = 'none';
buildBoard(results.data);
}
});
}
fileInput.addEventListener('change', function (event) {
const file = event.target.files[0];
if (file) parseAndBuild(file);
});
document.addEventListener('dragover', function (e) {
e.preventDefault();
e.dataTransfer.dropEffect = 'copy';
});
document.addEventListener('drop', function (e) {
e.preventDefault();
const file = e.dataTransfer.files[0];
if (file && file.name.endsWith('.csv')) {
parseAndBuild(file);
}
});
function buildBoard(data) {
boardData = {};
data.forEach(row => {
const { Category, Value, Clue, Answer } = row;
if (!boardData[Category]) boardData[Category] = {};
boardData[Category][Value] = { clue: Clue, answer: Answer };
});
const values = [...new Set(data.map(r => r.Value))].sort((a, b) => +a - +b);
const categories = Object.keys(boardData);
let html = '<table><tr>';
categories.forEach(cat => html += `<th>${cat}</th>`);
html += '</tr>';
values.forEach(val => {
html += '<tr>';
categories.forEach(cat => {
const cellData = boardData[cat][val];
if (cellData) {
html += `<td data-cat="${cat}" data-val="${val}">$${val}</td>`;
} else {
html += '<td></td>';
}
});
html += '</tr>';
});
html += '</table>';
gameDiv.innerHTML = html;
// create team boxes and scoring widgets
renderTeamBoxContainer(teams); // teamBox.js
// selecting a tile
document.querySelectorAll('td[data-cat]').forEach(td => {
td.addEventListener('click', function () {
// Play sound effect
clickSound.currentTime = 0;
clickSound.play();
// ...inside your buildBoard function, in the td click handler...
const cat = td.getAttribute('data-cat');
const val = td.getAttribute('data-val');
const { clue, answer } = boardData[cat][val];
clueDiv.textContent = clue;
answerDiv.textContent = answer;
answerDiv.style.display = 'none';
// Update only the label, not the whole header
document.getElementById('modal-label').textContent = `${cat} for $${val}`;
modal.style.display = 'flex';
td.classList.add('used');
});
});
microclickSound.currentTime = 0;
microclickSound.play();
}
</script>
</body>
</html>