-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsports.html
More file actions
286 lines (249 loc) · 10.2 KB
/
sports.html
File metadata and controls
286 lines (249 loc) · 10.2 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>AI Cricket Scoring System</title>
<style>
body { font-family: Inter, system-ui, -apple-system, sans-serif; margin: 0; background:#0f172a; color:#e6eef8; }
.app { display: grid; grid-template-columns: 1fr 360px; gap: 12px; height: 100vh; padding: 12px; }
.panel { background: #1e293b; border-radius: 12px; padding: 12px; box-shadow: 0 6px 18px rgba(0,0,0,.1); }
video { width:100%; height: auto; border-radius:12px; background: black; }
canvas { position: absolute; left:12px; top:12px; pointer-events:none; }
.controls { display:flex; gap:8px; flex-wrap:wrap; }
button { background:#4CAF50; border:none; padding:8px 10px; border-radius:8px; color:white; cursor:pointer; }
button.secondary { background:#888; }
.log { max-height:60vh; overflow:auto; padding:8px; font-size:14px; }
.score { font-size:18px; margin-bottom:8px; }
.badge { background:#4CAF50; padding:6px 8px; border-radius:999px; display:inline-block; }
.small { font-size:13px; opacity:.85 }
table { width:100%; margin-top: 20px; border-collapse: collapse; }
table, th, td { border: 1px solid #ddd; }
th, td { padding: 8px 12px; text-align: center; }
</style>
</head>
<body>
<div class="app">
<div class="panel" id="main">
<video id="video" playsinline autoplay muted></video>
<canvas id="overlay"></canvas>
<div style="margin-top:10px; display:flex; align-items:center; justify-content:space-between">
<button id="startBtn">Start Recording</button>
<button id="stopBtn" class="secondary">Stop Recording</button>
<button id="exportBtn">Export Match Report</button>
</div>
<hr />
<h3>Match Details</h3>
<form id="matchDetailsForm">
<label for="competition">Competition:</label>
<input type="text" id="competition" name="competition" required><br>
<label for="matchType">Match Type:</label>
<select id="matchType" name="matchType">
<option value="home">Home</option>
<option value="away">Away</option>
</select><br>
<label for="innings">Innings:</label>
<input type="text" id="innings" name="innings" required><br>
<label for="date">Date:</label>
<input type="date" id="date" name="date" required><br>
<label for="venue">Venue:</label>
<input type="text" id="venue" name="venue" required><br>
<button type="submit">Save Match Details</button>
</form>
</div>
<div class="panel" id="side">
<h2>Ball-by-Ball Scoring</h2>
<p id="score">Runs: 0 | Wickets: 0 | Overs: 0.0 | Current Batsman: N/A | Bowler: N/A</p>
<div class="keypad">
<button class="run" data-value="0">0</button>
<button class="run" data-value="1">1</button>
<button class="run" data-value="2">2</button>
<button class="run" data-value="3">3</button>
<button class="run" data-value="4">4</button>
<button class="run" data-value="5">5</button>
<button class="run" data-value="6">6</button>
<button class="extra" data-value="w">Wide</button>
<button class="extra" data-value="nb">No-ball</button>
<button class="run" data-value="by">Bye</button>
<button class="run" data-value="lb">Leg Bye</button>
<button class="out" data-value="bowled">Bowled</button>
<button class="out" data-value="caught">Caught</button>
<button class="out" data-value="run-out">Run-out</button>
<button class="out" data-value="stumped">Stumped</button>
<button class="submit">Submit</button>
<button class="clear">Clear</button>
</div>
<h3>Ball-by-Ball Details</h3>
<table id="ballDetailsTable">
<thead>
<tr>
<th>Ball</th>
<th>Batsman</th>
<th>Bowler</th>
<th>Runs</th>
<th>Extras</th>
<th>Out</th>
</tr>
</thead>
<tbody id="ballDetailsRows"></tbody>
</table>
<h3>Match Summary</h3>
<div id="matchSummary"></div>
</div>
</div>
<footer>
<p>© 2026 Cricket Scoring System. All rights reserved.</p>
</footer>
<script>
document.addEventListener("DOMContentLoaded", () => {
let totalRuns = 0;
let totalWickets = 0;
let totalBalls = 0;
let ballCount = 1;
const ballDetailsTable = document.getElementById("ballDetailsRows");
const scoreDisplay = document.getElementById("score");
let currentBatsman = '';
let currentBowler = '';
let currentExtras = 0;
let currentOut = '';
let mediaRecorder;
let recordedChunks = [];
// Handle scoring pad button clicks
const buttons = document.querySelectorAll(".keypad button");
let selectedRuns = 0;
let selectedExtras = 0;
let selectedOut = "";
buttons.forEach(button => {
button.addEventListener("click", () => {
const value = button.dataset.value;
if (value === 'w' || value === 'nb' || value === 'by' || value === 'lb') {
selectedExtras = value;
selectedRuns = 0;
} else if (value === 'submit') {
recordBall();
} else if (value === 'clear') {
resetInputs();
} else {
selectedRuns = value;
selectedExtras = 0;
}
updateDisplay();
});
});
// Record ball data
function recordBall() {
if (selectedRuns === 0 && selectedExtras === 0 && selectedOut === "") return;
totalRuns += parseInt(selectedRuns, 10) || 0;
currentExtras = selectedExtras;
if (selectedOut) {
totalWickets++;
}
totalBalls++;
let overs = Math.floor(totalBalls / 6);
let ballsInCurrentOver = totalBalls % 6;
let oversDisplay = `${overs}.${ballsInCurrentOver}`;
scoreDisplay.textContent = `Runs: ${totalRuns} | Wickets: ${totalWickets} | Overs: ${oversDisplay}`;
const row = document.createElement("tr");
row.innerHTML = `
<td>${ballCount}</td>
<td>${currentBatsman}</td>
<td>${currentBowler}</td>
<td>${selectedRuns}</td>
<td>${currentExtras}</td>
<td>${selectedOut || '-'}</td>
`;
ballDetailsTable.appendChild(row);
// Update player stats
updatePlayerStats(currentBatsman, selectedRuns, currentExtras, selectedOut);
ballCount++;
resetInputs();
stopRecording(); // Stop recording after ball is submitted
}
// Update the display after each selection
function updateDisplay() {
scoreDisplay.textContent = `Runs: ${totalRuns} | Wickets: ${totalWickets} | Overs: ${Math.floor(totalBalls / 6)}.${totalBalls % 6}`;
}
// Reset all inputs
function resetInputs() {
selectedRuns = 0;
selectedExtras = 0;
selectedOut = '';
currentExtras = 0;
currentOut = '';
}
// Start video recording
function startRecording() {
const stream = video.srcObject;
mediaRecorder = new MediaRecorder(stream, { mimeType: 'video/webm' });
mediaRecorder.ondataavailable = event => {
recordedChunks.push(event.data);
};
mediaRecorder.onstop = () => {
const blob = new Blob(recordedChunks, { type: 'video/webm' });
const videoURL = URL.createObjectURL(blob);
// Create a downloadable link for the ball-by-ball clip
const a = document.createElement('a');
a.href = videoURL;
a.download = `ball_${ballCount - 1}.webm`; // Automatically names the video file based on ball number
a.click();
// Reset the recorded chunks for the next recording
recordedChunks = [];
};
mediaRecorder.start();
log('Recording started...');
}
// Stop video recording
function stopRecording() {
if (mediaRecorder && mediaRecorder.state !== "inactive") {
mediaRecorder.stop();
log('Recording stopped...');
}
}
// Log information to the UI
function log(message) {
const logElement = document.createElement('div');
logElement.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
document.getElementById('log').appendChild(logElement);
}
// Handle Match Details Form submission
document.getElementById("matchDetailsForm").addEventListener("submit", (e) => {
e.preventDefault();
const matchDetails = {
competition: document.getElementById("competition").value,
matchType: document.getElementById("matchType").value,
innings: document.getElementById("innings").value,
date: document.getElementById("date").value,
venue: document.getElementById("venue").value,
};
console.log("Match Details:", matchDetails);
log('Match details saved.');
});
// Handle Start and Stop buttons
document.getElementById("startBtn").addEventListener("click", startRecording);
document.getElementById("stopBtn").addEventListener("click", stopRecording);
// Handle Export Match Report
document.getElementById("exportBtn").addEventListener("click", () => {
const matchSummary = {
totalRuns,
totalWickets,
totalBalls,
matchDetails: {
competition: document.getElementById("competition").value,
matchType: document.getElementById("matchType").value,
innings: document.getElementById("innings").value,
date: document.getElementById("date").value,
venue: document.getElementById("venue").value,
},
};
const dataStr = 'data:text/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(matchSummary, null, 2));
const a = document.createElement('a');
a.setAttribute('href', dataStr);
a.setAttribute('download', 'match_report.json');
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
});
});
</script>
</body>
</html>