Spaces:
Running
Running
File size: 27,932 Bytes
3bab5cb |
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 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Night Shift Break Tracker</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.pulse-animation {
animation: pulse 2s infinite;
}
@keyframes pulse {
0% { opacity: 1; }
50% { opacity: 0.5; }
100% { opacity: 1; }
}
.slide-in {
animation: slideIn 0.3s ease-out;
}
@keyframes slideIn {
from { transform: translateY(20px); opacity: 0; }
to { transform: translateY(0); opacity: 1; }
}
</style>
</head>
<body class="bg-gray-100 min-h-screen">
<div class="container mx-auto px-4 py-8 max-w-3xl">
<!-- Header -->
<header class="mb-8 text-center">
<h1 class="text-3xl font-bold text-gray-800 mb-2">Night Shift Break Tracker</h1>
<p class="text-gray-600">Monitor employee breaks during night shifts (6PM - 6AM)</p>
<div class="mt-4 p-3 bg-blue-50 rounded-lg flex items-center justify-center">
<i class="fas fa-clock text-blue-500 mr-2"></i>
<span id="current-time" class="font-mono font-bold text-blue-700"></span>
<span id="shift-status" class="ml-4 px-3 py-1 rounded-full text-xs font-semibold bg-blue-100 text-blue-800"></span>
</div>
</header>
<!-- Employee Card -->
<div class="bg-white rounded-xl shadow-md overflow-hidden mb-6 slide-in">
<div class="p-6">
<div class="flex items-center justify-between mb-4">
<div>
<h2 class="text-xl font-semibold text-gray-800" id="employee-name">John Doe</h2>
<p class="text-gray-600 text-sm">Employee ID: NS-2023-001</p>
</div>
<div class="flex items-center">
<div class="w-3 h-3 rounded-full mr-2" id="status-indicator"></div>
<span class="text-sm font-medium" id="status-text">Working</span>
</div>
</div>
<!-- Time Tracking -->
<div class="grid grid-cols-2 gap-4 mb-6">
<div class="bg-gray-50 p-4 rounded-lg">
<p class="text-sm text-gray-500 mb-1">Shift Started</p>
<p class="font-mono font-bold" id="shift-start-time">--:-- --</p>
</div>
<div class="bg-gray-50 p-4 rounded-lg">
<p class="text-sm text-gray-500 mb-1">Current Break</p>
<p class="font-mono font-bold" id="current-break-time">00:00</p>
</div>
<div class="bg-gray-50 p-4 rounded-lg">
<p class="text-sm text-gray-500 mb-1">Total Break Time</p>
<p class="font-mono font-bold" id="total-break-time">00:00</p>
</div>
<div class="bg-gray-50 p-4 rounded-lg">
<p class="text-sm text-gray-500 mb-1">Break Type</p>
<p class="font-mono font-bold" id="break-type">None</p>
</div>
</div>
<!-- Break Progress -->
<div class="mb-6">
<div class="flex justify-between text-sm text-gray-600 mb-1">
<span>Break Progress</span>
<span id="break-progress-text">0%</span>
</div>
<div class="w-full bg-gray-200 rounded-full h-2.5">
<div class="bg-blue-600 h-2.5 rounded-full" id="break-progress-bar" style="width: 0%"></div>
</div>
</div>
<!-- Action Buttons -->
<div class="flex flex-col space-y-3" id="action-buttons">
<button id="check-in-btn" class="hidden w-full bg-green-500 hover:bg-green-600 text-white py-3 px-4 rounded-lg font-medium transition duration-200 flex items-center justify-center">
<i class="fas fa-sign-in-alt mr-2"></i> Check In to Start Shift
</button>
<button id="check-out-btn" class="w-full bg-red-500 hover:bg-red-600 text-white py-3 px-4 rounded-lg font-medium transition duration-200 flex items-center justify-center">
<i class="fas fa-sign-out-alt mr-2"></i> Check Out for Break
</button>
</div>
<!-- Location Warning -->
<div id="location-warning" class="hidden mt-4 p-3 bg-red-50 border border-red-200 rounded-lg text-red-600 text-sm flex items-center">
<i class="fas fa-exclamation-circle mr-2"></i>
<span>You must be within 20m of workplace to check in/out</span>
</div>
</div>
</div>
<!-- Break Rules -->
<div class="bg-white rounded-xl shadow-md overflow-hidden mb-6 slide-in">
<div class="p-6">
<h3 class="text-lg font-semibold text-gray-800 mb-4">Break Rules</h3>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="bg-blue-50 p-4 rounded-lg border border-blue-100">
<div class="flex items-center mb-2">
<div class="w-3 h-3 rounded-full bg-blue-500 mr-2"></div>
<span class="font-medium">Break 1</span>
</div>
<p class="text-sm text-gray-700">10 minutes duration</p>
</div>
<div class="bg-purple-50 p-4 rounded-lg border border-purple-100">
<div class="flex items-center mb-2">
<div class="w-3 h-3 rounded-full bg-purple-500 mr-2"></div>
<span class="font-medium">Break 2</span>
</div>
<p class="text-sm text-gray-700">40 minutes duration</p>
</div>
<div class="bg-green-50 p-4 rounded-lg border border-green-100">
<div class="flex items-center mb-2">
<div class="w-3 h-3 rounded-full bg-green-500 mr-2"></div>
<span class="font-medium">Break 3</span>
</div>
<p class="text-sm text-gray-700">10 minutes duration</p>
</div>
<div class="bg-yellow-50 p-4 rounded-lg border border-yellow-100">
<div class="flex items-center mb-2">
<div class="w-3 h-3 rounded-full bg-yellow-500 mr-2"></div>
<span class="font-medium">Break 4</span>
</div>
<p class="text-sm text-gray-700">10 minutes duration</p>
</div>
</div>
</div>
</div>
<!-- Break History -->
<div class="bg-white rounded-xl shadow-md overflow-hidden slide-in">
<div class="p-6">
<h3 class="text-lg font-semibold text-gray-800 mb-4">Today's Break History</h3>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th scope="col" class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Break</th>
<th scope="col" class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Start Time</th>
<th scope="col" class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">End Time</th>
<th scope="col" class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Duration</th>
<th scope="col" class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200" id="break-history">
<!-- Will be populated by JavaScript -->
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- Success Modal -->
<div id="success-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
<div class="bg-white rounded-xl p-6 max-w-sm w-full mx-4 slide-in">
<div class="text-center">
<div class="mx-auto flex items-center justify-center h-12 w-12 rounded-full bg-green-100 mb-4">
<i class="fas fa-check text-green-600 text-xl"></i>
</div>
<h3 class="text-lg font-medium text-gray-900 mb-2" id="modal-title">Success</h3>
<p class="text-sm text-gray-500 mb-4" id="modal-message">Action completed successfully.</p>
<button id="modal-close-btn" class="w-full bg-blue-600 text-white py-2 px-4 rounded-lg hover:bg-blue-700 transition duration-200">
OK
</button>
</div>
</div>
</div>
<script>
// App State
const state = {
shiftStarted: false,
currentBreak: null,
breakStartTime: null,
totalBreakTime: 0,
breakHistory: [],
currentBreakType: null,
inLocation: true, // Simulate location check
workplaceLocation: { lat: 40.7128, lng: -74.0060 }, // Example coordinates
breakRules: {
1: { name: "Break 1", duration: 10 * 60 * 1000, color: "blue" },
2: { name: "Break 2", duration: 40 * 60 * 1000, color: "purple" },
3: { name: "Break 3", duration: 10 * 60 * 1000, color: "green" },
4: { name: "Break 4", duration: 10 * 60 * 1000, color: "yellow" }
},
shiftStartTime: null
};
// DOM Elements
const elements = {
currentTime: document.getElementById('current-time'),
shiftStatus: document.getElementById('shift-status'),
employeeName: document.getElementById('employee-name'),
statusIndicator: document.getElementById('status-indicator'),
statusText: document.getElementById('status-text'),
shiftStartTime: document.getElementById('shift-start-time'),
currentBreakTime: document.getElementById('current-break-time'),
totalBreakTime: document.getElementById('total-break-time'),
breakType: document.getElementById('break-type'),
breakProgressText: document.getElementById('break-progress-text'),
breakProgressBar: document.getElementById('break-progress-bar'),
checkInBtn: document.getElementById('check-in-btn'),
checkOutBtn: document.getElementById('check-out-btn'),
locationWarning: document.getElementById('location-warning'),
breakHistory: document.getElementById('break-history'),
successModal: document.getElementById('success-modal'),
modalTitle: document.getElementById('modal-title'),
modalMessage: document.getElementById('modal-message'),
modalCloseBtn: document.getElementById('modal-close-btn')
};
// Initialize the app
function init() {
updateClock();
setInterval(updateClock, 1000);
// Check if shift should be active based on time (6PM-6AM)
checkShiftTime();
// Set up event listeners
elements.checkInBtn.addEventListener('click', startShift);
elements.checkOutBtn.addEventListener('click', toggleBreak);
elements.modalCloseBtn.addEventListener('click', () => {
elements.successModal.classList.add('hidden');
});
// Simulate location check (in a real app, this would use Geolocation API)
simulateLocationCheck();
}
// Update clock display
function updateClock() {
const now = new Date();
const timeString = now.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', second: '2-digit' });
elements.currentTime.textContent = timeString;
// Update current break timer if in break
if (state.currentBreak) {
updateBreakTimer();
}
}
// Check if current time is within shift hours (6PM-6AM)
function checkShiftTime() {
const now = new Date();
const hours = now.getHours();
const isNightShift = hours >= 18 || hours < 6;
if (isNightShift) {
elements.shiftStatus.textContent = "Night Shift Active";
elements.shiftStatus.classList.remove('bg-red-100', 'text-red-800');
elements.shiftStatus.classList.add('bg-green-100', 'text-green-800');
} else {
elements.shiftStatus.textContent = "Day Time (Shift Inactive)";
elements.shiftStatus.classList.remove('bg-green-100', 'text-green-800');
elements.shiftStatus.classList.add('bg-red-100', 'text-red-800');
// Reset if outside shift hours
if (state.shiftStarted) {
endShift();
}
}
}
// Start the shift
function startShift() {
if (!state.inLocation) {
showLocationWarning();
return;
}
state.shiftStarted = true;
state.shiftStartTime = new Date();
state.totalBreakTime = 0;
state.breakHistory = [];
state.currentBreak = null;
state.currentBreakType = null;
updateUI();
const timeString = state.shiftStartTime.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' });
elements.shiftStartTime.textContent = timeString;
showSuccessModal("Shift Started", "Your night shift has started successfully. Remember to take your breaks on time!");
}
// End the shift
function endShift() {
state.shiftStarted = false;
state.shiftStartTime = null;
state.currentBreak = null;
state.currentBreakType = null;
updateUI();
}
// Toggle break (start or end)
function toggleBreak() {
if (!state.inLocation) {
showLocationWarning();
return;
}
if (state.currentBreak) {
endBreak();
} else {
startBreak();
}
}
// Start a break
function startBreak() {
if (!state.shiftStarted) return;
// Determine next break type
const breaksTaken = state.breakHistory.filter(b => b.type !== null).length;
let nextBreakType = null;
if (breaksTaken < 4) {
nextBreakType = breaksTaken + 1;
} else {
// All breaks taken
showSuccessModal("All Breaks Taken", "You have already taken all your scheduled breaks for this shift.");
return;
}
state.currentBreak = true;
state.breakStartTime = new Date();
state.currentBreakType = nextBreakType;
updateUI();
// Add to history
state.breakHistory.push({
type: nextBreakType,
startTime: new Date(state.breakStartTime),
endTime: null,
duration: null
});
updateBreakHistory();
const breakName = state.breakRules[nextBreakType].name;
showSuccessModal("Break Started", `Your ${breakName} has started. Duration: ${state.breakRules[nextBreakType].duration / 60000} minutes.`);
}
// End current break
function endBreak() {
if (!state.currentBreak || !state.breakStartTime) return;
const endTime = new Date();
const duration = endTime - state.breakStartTime;
state.totalBreakTime += duration;
// Update history
const currentBreak = state.breakHistory.find(b => b.endTime === null);
if (currentBreak) {
currentBreak.endTime = endTime;
currentBreak.duration = duration;
}
// Check if break duration matches rules
const expectedDuration = state.breakRules[state.currentBreakType].duration;
const isCorrectDuration = Math.abs(duration - expectedDuration) < 30000; // 30 second tolerance
state.currentBreak = false;
state.breakStartTime = null;
state.currentBreakType = null;
updateUI();
updateBreakHistory();
const breakName = state.breakRules[state.currentBreakType].name;
if (isCorrectDuration) {
showSuccessModal("Break Ended", `Your ${breakName} has ended. Duration was correct.`);
} else {
showSuccessModal("Break Ended", `Your ${breakName} has ended. Note: Duration was ${Math.round(duration / 60000)} minutes (expected ${expectedDuration / 60000} minutes).`);
}
}
// Update break timer display
function updateBreakTimer() {
if (!state.currentBreak || !state.breakStartTime) return;
const now = new Date();
const elapsed = now - state.breakStartTime;
const minutes = Math.floor(elapsed / 60000);
const seconds = Math.floor((elapsed % 60000) / 1000);
elements.currentBreakTime.textContent = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
// Update progress
if (state.currentBreakType) {
const expectedDuration = state.breakRules[state.currentBreakType].duration;
const progress = Math.min(100, (elapsed / expectedDuration) * 100);
elements.breakProgressBar.style.width = `${progress}%`;
elements.breakProgressText.textContent = `${Math.round(progress)}%`;
// Change color if over duration
if (progress >= 100) {
elements.breakProgressBar.classList.remove('bg-blue-600');
elements.breakProgressBar.classList.add('bg-red-600');
} else {
elements.breakProgressBar.classList.remove('bg-red-600');
elements.breakProgressBar.classList.add('bg-blue-600');
}
}
}
// Update UI based on current state
function updateUI() {
// Check in/out button visibility
elements.checkInBtn.classList.toggle('hidden', state.shiftStarted);
elements.checkOutBtn.classList.toggle('hidden', !state.shiftStarted);
// Status indicator
if (state.currentBreak) {
elements.statusIndicator.className = 'w-3 h-3 rounded-full mr-2 pulse-animation';
elements.statusIndicator.classList.add(`bg-${state.breakRules[state.currentBreakType].color}-500`);
elements.statusText.textContent = state.breakRules[state.currentBreakType].name;
elements.checkOutBtn.innerHTML = '<i class="fas fa-sign-in-alt mr-2"></i> Check In from Break';
elements.checkOutBtn.classList.remove('bg-red-500', 'hover:bg-red-600');
elements.checkOutBtn.classList.add('bg-green-500', 'hover:bg-green-600');
} else {
elements.statusIndicator.className = 'w-3 h-3 rounded-full mr-2 bg-green-500';
elements.statusText.textContent = 'Working';
elements.checkOutBtn.innerHTML = '<i class="fas fa-sign-out-alt mr-2"></i> Check Out for Break';
elements.checkOutBtn.classList.remove('bg-green-500', 'hover:bg-green-600');
elements.checkOutBtn.classList.add('bg-red-500', 'hover:bg-red-600');
}
// Break type display
if (state.currentBreakType) {
elements.breakType.textContent = state.breakRules[state.currentBreakType].name;
elements.breakType.classList.add(`text-${state.breakRules[state.currentBreakType].color}-600`);
} else {
elements.breakType.textContent = 'None';
elements.breakType.className = 'font-mono font-bold';
}
// Total break time display
const totalMinutes = Math.floor(state.totalBreakTime / 60000);
const totalSeconds = Math.floor((state.totalBreakTime % 60000) / 1000);
elements.totalBreakTime.textContent = `${totalMinutes.toString().padStart(2, '0')}:${totalSeconds.toString().padStart(2, '0')}`;
// Reset current break time if not in break
if (!state.currentBreak) {
elements.currentBreakTime.textContent = '00:00';
elements.breakProgressBar.style.width = '0%';
elements.breakProgressText.textContent = '0%';
elements.breakProgressBar.classList.remove('bg-red-600');
elements.breakProgressBar.classList.add('bg-blue-600');
}
}
// Update break history table
function updateBreakHistory() {
elements.breakHistory.innerHTML = '';
state.breakHistory.forEach(breakItem => {
const row = document.createElement('tr');
const typeCell = document.createElement('td');
typeCell.className = 'px-4 py-3 whitespace-nowrap text-sm font-medium text-gray-900';
typeCell.textContent = breakItem.type ? state.breakRules[breakItem.type].name : 'Shift Start';
const startCell = document.createElement('td');
startCell.className = 'px-4 py-3 whitespace-nowrap text-sm text-gray-500';
startCell.textContent = breakItem.startTime.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' });
const endCell = document.createElement('td');
endCell.className = 'px-4 py-3 whitespace-nowrap text-sm text-gray-500';
endCell.textContent = breakItem.endTime ? breakItem.endTime.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' }) : '--:-- --';
const durationCell = document.createElement('td');
durationCell.className = 'px-4 py-3 whitespace-nowrap text-sm text-gray-500';
if (breakItem.duration) {
const minutes = Math.floor(breakItem.duration / 60000);
const seconds = Math.floor((breakItem.duration % 60000) / 1000);
durationCell.textContent = `${minutes}m ${seconds}s`;
} else {
durationCell.textContent = '--';
}
const statusCell = document.createElement('td');
statusCell.className = 'px-4 py-3 whitespace-nowrap text-sm';
if (breakItem.endTime) {
const expectedDuration = breakItem.type ? state.breakRules[breakItem.type].duration : 0;
const isCorrect = breakItem.type ? Math.abs(breakItem.duration - expectedDuration) < 30000 : true;
if (isCorrect) {
statusCell.innerHTML = '<span class="px-2 py-1 rounded-full text-xs font-semibold bg-green-100 text-green-800">Completed</span>';
} else {
statusCell.innerHTML = '<span class="px-2 py-1 rounded-full text-xs font-semibold bg-yellow-100 text-yellow-800">Incorrect Duration</span>';
}
} else if (breakItem.type) {
statusCell.innerHTML = '<span class="px-2 py-1 rounded-full text-xs font-semibold bg-blue-100 text-blue-800">In Progress</span>';
} else {
statusCell.innerHTML = '<span class="px-2 py-1 rounded-full text-xs font-semibold bg-gray-100 text-gray-800">Shift Active</span>';
}
row.appendChild(typeCell);
row.appendChild(startCell);
row.appendChild(endCell);
row.appendChild(durationCell);
row.appendChild(statusCell);
elements.breakHistory.appendChild(row);
});
}
// Show location warning
function showLocationWarning() {
elements.locationWarning.classList.remove('hidden');
setTimeout(() => {
elements.locationWarning.classList.add('hidden');
}, 5000);
}
// Show success modal
function showSuccessModal(title, message) {
elements.modalTitle.textContent = title;
elements.modalMessage.textContent = message;
elements.successModal.classList.remove('hidden');
}
// Simulate location check (in a real app, this would use Geolocation API)
function simulateLocationCheck() {
// Randomly toggle location status for demo purposes
setInterval(() => {
state.inLocation = Math.random() > 0.2; // 80% chance of being in location
if (!state.inLocation) {
elements.checkInBtn.classList.add('hidden');
elements.checkOutBtn.classList.add('hidden');
showLocationWarning();
} else {
updateUI(); // Show buttons again if in location
}
}, 10000);
}
// Initialize the app when DOM is loaded
document.addEventListener('DOMContentLoaded', init);
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=ivanhoang/break-plan" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |