countdownsync-pro / index.html
managerbhingong's picture
timer tidak berjalan, tolong perbaiki
5fa4bd0 verified
Raw History Blame Contribute Delete
11.7 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CountdownSync Pro</title>
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<script src="https://unpkg.com/feather-icons"></script>
<script src="https://cdn.socket.io/4.5.4/socket.io.min.js"></script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
body {
font-family: 'Inter', sans-serif;
}
.timer-container {
background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
backdrop-filter: blur(10px);
}
.timer-display {
font-feature-settings: "tnum";
font-variant-numeric: tabular-nums;
}
.settings-panel {
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.pulse-animation {
animation: pulse 2s infinite;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.7; }
}
</style>
</head>
<body class="bg-gray-50 min-h-screen flex items-center justify-center">
<div class="container mx-auto px-4">
<!-- Main Timer Section -->
<div class="max-w-md mx-auto">
<div class="timer-container rounded-3xl shadow-2xl p-8 border border-red-100">
<!-- Timer Display -->
<div class="text-center mb-8">
<h1 class="text-3xl font-bold text-red-600 mb-2">CountdownSync Pro</h1>
<p class="text-gray-600 mb-6">Real-time synchronized countdown</p>
<div class="timer-display text-7xl font-bold text-red-600 mb-8 bg-white rounded-2xl py-6 px-8 shadow-inner border border-red-200">
<span id="minutes">00</span>:<span id="seconds">00</span>
</div>
<div class="text-sm text-gray-500 mb-2" id="status">
Ready to start
</div>
</div>
<!-- Control Buttons -->
<div class="flex justify-center space-x-4">
<button id="resetBtn" class="bg-red-500 hover:bg-red-600 text-white px-6 py-3 rounded-xl font-semibold shadow-lg transition-all duration-300 transform hover:scale-105 flex items-center space-x-2">
<i data-feather="refresh-cw"></i>
<span>Reset Timer</span>
</button>
<button id="settingsBtn" class="bg-gray-700 hover:bg-gray-800 text-white px-6 py-3 rounded-xl font-semibold shadow-lg transition-all duration-300 transform hover:scale-105 flex items-center space-x-2">
<i data-feather="settings"></i>
<span>Settings</span>
</button>
</div>
</div>
</div>
<!-- Settings Panel -->
<div id="settingsPanel" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 hidden z-50">
<div class="bg-white rounded-3xl shadow-2xl p-8 max-w-sm w-full mx-auto transform transition-all duration-300 scale-95">
<div class="flex justify-between items-center mb-6">
<h2 class="text-2xl font-bold text-gray-800">Timer Settings</h2>
<button id="closeSettings" class="text-gray-500 hover:text-gray-700 transition-colors">
<i data-feather="x"></i>
</button>
</div>
<div class="space-y-6">
<div>
<label class="block text-sm font-medium text-gray-700 mb-2">
Duration (minutes)
</label>
<input type="number" id="durationInput" min="1" max="120" value="5"
class="w-full px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:ring-red-500 focus:border-red-500 transition-all duration-300">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-2">
Alert Sound
</label>
<select id="soundSelect" class="w-full px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:ring-red-500 focus:border-red-500 transition-all duration-300">
<option value="beep">Beep</option>
<option value="bell">Bell</option>
<option value="alarm">Alarm</option>
</select>
</div>
<button id="saveSettings" class="w-full bg-red-500 hover:bg-red-600 text-white py-3 rounded-xl font-semibold shadow-lg transition-all duration-300 transform hover:scale-105">
Start Countdown
</button>
</div>
</div>
</div>
<!-- Connection Status -->
<div class="fixed bottom-4 right-4 flex items-center space-x-2 bg-white rounded-full px-4 py-2 shadow-lg border">
<div id="connectionStatus" class="w-3 h-3 bg-green-500 rounded-full"></div>
<span class="text-sm text-gray-600" id="connectionText">Connected</span>
</div>
</div>
<audio id="alertSound" preload="auto">
<source src="https://assets.mixkit.co/sfx/preview/mixkit-alarm-digital-clock-beep-989.mp3" type="audio/mpeg">
</audio>
<script>
// Socket.io connection
const socket = io('https://countdown-sync-server.glitch.me');
// DOM Elements
const minutesElement = document.getElementById('minutes');
const secondsElement = document.getElementById('seconds');
const resetBtn = document.getElementById('resetBtn');
const settingsBtn = document.getElementById('settingsBtn');
const settingsPanel = document.getElementById('settingsPanel');
const closeSettings = document.getElementById('closeSettings');
const durationInput = document.getElementById('durationInput');
const soundSelect = document.getElementById('soundSelect');
const saveSettings = document.getElementById('saveSettings');
const statusElement = document.getElementById('status');
const connectionStatus = document.getElementById('connectionStatus');
const connectionText = document.getElementById('connectionText');
const alertSound = document.getElementById('alertSound');
// Timer state
let countdown;
let totalSeconds = 0;
let isRunning = false;
// Add new event listener for timer state
socket.on('timerState', (data) => {
totalSeconds = data.remainingSeconds;
isRunning = data.isRunning;
updateTimerDisplay(totalSeconds);
updateStatus();
// Start local countdown if timer is running
if (isRunning && totalSeconds > 0) {
startLocalCountdown();
}
});
// Socket event listeners
socket.on('connect', () => {
connectionStatus.className = 'w-3 h-3 bg-green-500 rounded-full pulse-animation';
connectionText.textContent = 'Connected';
// Request current timer state when connecting
socket.emit('getTimerState');
});
socket.on('disconnect', () => {
connectionStatus.className = 'w-3 h-3 bg-red-500 rounded-full';
connectionText.textContent = 'Disconnected';
});
socket.on('timerUpdate', (data) => {
totalSeconds = data.remainingSeconds;
updateTimerDisplay(totalSeconds);
isRunning = data.isRunning;
updateStatus();
});
socket.on('timerComplete', () => {
playAlertSound();
isRunning = false;
totalSeconds = 0;
updateTimerDisplay(totalSeconds);
statusElement.textContent = 'Timer completed!';
statusElement.className = 'text-sm text-red-600 font-semibold';
});
socket.on('timerReset', (data) => {
totalSeconds = data.duration * 60;
updateTimerDisplay(totalSeconds);
isRunning = false;
statusElement.textContent = 'Timer reset';
statusElement.className = 'text-sm text-gray-600';
});
// Event Listeners
resetBtn.addEventListener('click', () => {
socket.emit('resetTimer');
});
settingsBtn.addEventListener('click', () => {
settingsPanel.classList.remove('hidden');
setTimeout(() => {
settingsPanel.querySelector('div').classList.remove('scale-95');
}, 10);
});
closeSettings.addEventListener('click', closeSettingsPanel);
saveSettings.addEventListener('click', saveTimerSettings);
// Functions
function updateTimerDisplay(totalSeconds) {
const minutes = Math.floor(totalSeconds / 60);
const seconds = totalSeconds % 60;
minutesElement.textContent = minutes.toString().padStart(2, '0');
secondsElement.textContent = seconds.toString().padStart(2, '0');
}
function startLocalCountdown() {
// Clear any existing countdown
if (countdown) {
clearInterval(countdown);
}
// Start local countdown
countdown = setInterval(() => {
if (totalSeconds > 0 && isRunning) {
totalSeconds--;
updateTimerDisplay(totalSeconds);
} else {
clearInterval(countdown);
isRunning = false;
updateStatus();
}
}, 1000);
}
function closeSettingsPanel() {
settingsPanel.querySelector('div').classList.add('scale-95');
setTimeout(() => {
settingsPanel.classList.add('hidden');
}, 300);
}
function saveTimerSettings() {
const duration = parseInt(durationInput.value);
if (duration > 0) {
socket.emit('startTimer', { duration });
closeSettingsPanel();
startLocalCountdown();
}
}
function playAlertSound() {
alertSound.currentTime = 0;
alertSound.play().catch(e => console.log('Audio play failed:', e));
}
function updateStatus() {
if (isRunning) {
statusElement.textContent = 'Counting down...';
statusElement.className = 'text-sm text-green-600 font-semibold';
} else {
statusElement.textContent = 'Ready to start';
statusElement.className = 'text-sm text-gray-600';
}
}
// Initialize
feather.replace();
updateTimerDisplay(0);
// Check if socket is connected and request state
if (socket.connected) {
socket.emit('getTimerState');
}
</script>
</body>
</html>