coffee-can-tracker / index.html
RedMoe's picture
empty in intervals - Initial Deployment
e4d5011 verified
Raw History Blame Contribute Delete
16 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Coffee Can 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">
<script>
tailwind.config = {
theme: {
extend: {
colors: {
coffee: {
50: '#f8f3e9',
100: '#efe0c8',
200: '#e0c69c',
300: '#d0a76a',
400: '#c18d45',
500: '#b77c38',
600: '#9d6330',
700: '#7e4c2a',
800: '#683f28',
900: '#573525',
}
}
}
}
}
</script>
<style>
@keyframes fillCoffee {
0% { height: 0; }
100% { height: 80%; }
}
@keyframes emptyCoffee {
0% { height: 80%; }
100% { height: 0; }
}
.coffee-fill {
animation: fillCoffee 0.5s ease-out forwards;
}
.coffee-empty {
animation: emptyCoffee 0.5s ease-out forwards;
}
.pulse {
animation: pulse 2s infinite;
}
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.05); }
100% { transform: scale(1); }
}
@keyframes steam1 {
0% { transform: translateY(0) scale(1); opacity: 0.3; }
100% { transform: translateY(-20px) scale(1.5); opacity: 0; }
}
@keyframes steam2 {
0% { transform: translateY(0) scale(1); opacity: 0.4; }
50% { transform: translateY(-15px) scale(1.3); opacity: 0.2; }
100% { transform: translateY(-30px) scale(1.8); opacity: 0; }
}
@keyframes steam3 {
0% { transform: translateY(0) scale(1); opacity: 0.2; }
100% { transform: translateY(-25px) scale(1.6); opacity: 0; }
}
.animate-steam1 {
animation: steam1 2s ease-out infinite;
}
.animate-steam2 {
animation: steam2 2.5s ease-out infinite;
animation-delay: 0.3s;
}
.animate-steam3 {
animation: steam3 3s ease-out infinite;
animation-delay: 0.6s;
}
@keyframes buttonPress {
0% { transform: scale(1); }
50% { transform: scale(0.95); }
100% { transform: scale(1); }
}
.button-press {
animation: buttonPress 0.3s ease;
}
</style>
</head>
<body class="bg-gradient-to-br from-coffee-50 to-coffee-100 min-h-screen flex flex-col">
<!-- Header -->
<header class="bg-coffee-800 text-coffee-50 py-6 shadow-lg">
<div class="container mx-auto px-4 flex flex-col md:flex-row justify-between items-center">
<div class="flex items-center mb-4 md:mb-0">
<i class="fas fa-mug-hot text-3xl mr-3"></i>
<h1 class="text-2xl md:text-3xl font-bold">Coffee Can Tracker</h1>
</div>
<div class="flex items-center space-x-2">
<div class="bg-coffee-700 px-3 py-1 rounded-full flex items-center">
<span class="hidden sm:inline">Status:</span>
<span id="status-indicator" class="ml-1 font-semibold">Loading...</span>
</div>
<div class="bg-coffee-600 px-3 py-1 rounded-full">
<i class="fas fa-users mr-1"></i>
<span id="user-count">0</span> online
</div>
</div>
</div>
</header>
<!-- Main Content -->
<main class="flex-grow container mx-auto px-4 py-8 flex flex-col items-center">
<!-- Coffee Can Visualization -->
<div class="relative w-64 h-80 mb-10">
<!-- Can Top -->
<div class="absolute top-0 left-1/2 transform -translate-x-1/2 w-48 h-8 bg-coffee-300 rounded-t-lg z-10"></div>
<!-- Can Body -->
<div class="absolute top-8 left-1/2 transform -translate-x-1/2 w-40 h-64 bg-coffee-200 rounded-lg border-4 border-coffee-300 overflow-hidden">
<!-- Coffee Level -->
<div id="coffee-level" class="absolute bottom-0 w-full bg-coffee-700"></div>
<!-- Can Details -->
<div class="absolute top-4 left-1/2 transform -translate-x-1/2 w-32 h-12 bg-coffee-100 rounded-md flex items-center justify-center">
<span class="text-coffee-800 font-bold">COFFEE</span>
</div>
</div>
<!-- Can Bottom -->
<div class="absolute bottom-0 left-1/2 transform -translate-x-1/2 w-44 h-4 bg-coffee-300 rounded-b-lg"></div>
<!-- Steam Animation -->
<div id="steam" class="hidden absolute top-0 left-1/2 transform -translate-x-1/2 -translate-y-full">
<div class="flex space-x-4">
<div class="w-3 h-12 bg-white/40 rounded-full animate-steam1"></div>
<div class="w-4 h-16 bg-white/50 rounded-full animate-steam2"></div>
<div class="w-3 h-10 bg-white/30 rounded-full animate-steam3"></div>
</div>
</div>
</div>
<!-- Status Card -->
<div class="bg-white rounded-xl shadow-lg p-6 w-full max-w-md mb-8">
<div class="text-center mb-6">
<h2 class="text-xl font-bold text-coffee-800 mb-2">Current Status</h2>
<div id="status-display" class="text-2xl font-bold py-3 px-6 rounded-lg inline-block">
Loading...
</div>
</div>
<div class="flex justify-center space-x-4">
<button id="btn-fill" class="bg-coffee-600 hover:bg-coffee-700 text-white font-bold py-3 px-6 rounded-lg transition transform hover:scale-105 focus:outline-none focus:ring-2 focus:ring-coffee-500 focus:ring-opacity-50">
<i class="fas fa-fill-drip mr-2"></i>Fill Can
</button>
<button id="btn-empty" class="bg-gray-600 hover:bg-gray-700 text-white font-bold py-3 px-6 rounded-lg transition transform hover:scale-105 focus:outline-none focus:ring-2 focus:ring-gray-500 focus:ring-opacity-50">
<i class="fas fa-trash-alt mr-2"></i>Empty Can
</button>
</div>
</div>
<!-- Activity Feed -->
<div class="bg-white rounded-xl shadow-lg p-6 w-full max-w-2xl">
<h2 class="text-xl font-bold text-coffee-800 mb-4">Recent Activity</h2>
<div id="activity-feed" class="space-y-3 max-h-60 overflow-y-auto">
<div class="text-center py-4 text-gray-500">
<i class="fas fa-coffee text-2xl mb-2"></i>
<p>No activity yet. Be the first to update the coffee status!</p>
</div>
</div>
</div>
</main>
<!-- Footer -->
<footer class="bg-coffee-900 text-coffee-200 py-6">
<div class="container mx-auto px-4 text-center">
<p>Coffee Can Tracker &copy; 2023 | Synchronized in real-time across all devices</p>
<p class="mt-2 text-sm text-coffee-400">Click "Fill Can" or "Empty Can" to update the status for everyone</p>
</div>
</footer>
<!-- Firebase SDK -->
<script src="https://www.gstatic.com/firebasejs/9.0.2/firebase-app-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.0.2/firebase-database-compat.js"></script>
<script>
// Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyDdJg8QdJQjQdJQjQdJQjQdJQjQdJQjQdJQ",
authDomain: "coffee-can-tracker.firebaseapp.com",
databaseURL: "https://coffee-can-tracker-default-rtdb.firebaseio.com",
projectId: "coffee-can-tracker",
storageBucket: "coffee-can-tracker.appspot.com",
messagingSenderId: "123456789012",
appId: "1:123456789012:web:abcdefghijklmnopqrstuv"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
const database = firebase.database();
// DOM Elements
const coffeeLevel = document.getElementById('coffee-level');
const statusDisplay = document.getElementById('status-display');
const statusIndicator = document.getElementById('status-indicator');
const btnFill = document.getElementById('btn-fill');
const btnEmpty = document.getElementById('btn-empty');
const activityFeed = document.getElementById('activity-feed');
const steam = document.getElementById('steam');
const userCountElement = document.getElementById('user-count');
// References
const coffeeStatusRef = database.ref('coffeeStatus');
const activityRef = database.ref('activity');
const usersRef = database.ref('users');
// Generate unique user ID
const userId = 'user_' + Math.random().toString(36).substr(2, 9);
let userName = `User${Math.floor(Math.random() * 1000)}`;
// Update user count
usersRef.on('value', (snapshot) => {
const userCount = snapshot.numChildren();
userCountElement.textContent = userCount;
});
// Register user
const userRef = usersRef.child(userId);
userRef.set({
name: userName,
lastActive: firebase.database.ServerValue.TIMESTAMP
});
// Remove user when they leave
window.addEventListener('beforeunload', () => {
userRef.remove();
});
// Update coffee status
coffeeStatusRef.on('value', (snapshot) => {
const status = snapshot.val();
updateCoffeeStatus(status);
});
// Update activity feed
activityRef.limitToLast(5).on('value', (snapshot) => {
activityFeed.innerHTML = '';
const activities = [];
snapshot.forEach((childSnapshot) => {
activities.push(childSnapshot.val());
});
// Reverse to show latest first
activities.reverse().forEach(activity => {
const activityElement = document.createElement('div');
activityElement.className = 'flex items-center py-2 px-4 bg-coffee-50 rounded-lg';
const icon = activity.status ?
'<i class="fas fa-fill-drip text-coffee-600 text-xl mr-3"></i>' :
'<i class="fas fa-trash-alt text-gray-600 text-xl mr-3"></i>';
const statusText = activity.status ?
'<span class="font-bold text-coffee-700">filled</span>' :
'<span class="font-bold text-gray-700">emptied</span>';
activityElement.innerHTML = `
${icon}
<div>
<span class="font-semibold">${activity.userName}</span> ${statusText} the coffee can
<div class="text-xs text-gray-500">${formatTime(activity.timestamp)}</div>
</div>
`;
activityFeed.appendChild(activityElement);
});
if (activities.length === 0) {
activityFeed.innerHTML = `
<div class="text-center py-4 text-gray-500">
<i class="fas fa-coffee text-2xl mb-2"></i>
<p>No activity yet. Be the first to update the coffee status!</p>
</div>
`;
}
});
// Button event listeners
btnFill.addEventListener('click', () => {
btnFill.classList.add('button-press');
setTimeout(() => btnFill.classList.remove('button-press'), 300);
updateStatus(true);
});
btnEmpty.addEventListener('click', () => {
btnEmpty.classList.add('button-press');
setTimeout(() => btnEmpty.classList.remove('button-press'), 300);
updateStatus(false);
});
// Update coffee status function
function updateCoffeeStatus(status) {
if (status === null || status === undefined) return;
coffeeLevel.classList.remove('coffee-fill', 'coffee-empty');
if (status) {
coffeeLevel.className = 'absolute bottom-0 w-full bg-coffee-700 coffee-fill';
coffeeLevel.style.height = '80%';
statusDisplay.textContent = 'FULL';
statusDisplay.className = 'text-2xl font-bold py-3 px-6 rounded-lg inline-block bg-coffee-100 text-coffee-800 transform transition duration-300 hover:scale-105';
statusIndicator.textContent = 'Full';
steam.classList.remove('hidden');
} else {
coffeeLevel.className = 'absolute bottom-0 w-full bg-coffee-700 coffee-empty';
coffeeLevel.style.height = '0%';
statusDisplay.textContent = 'EMPTY';
statusDisplay.className = 'text-2xl font-bold py-3 px-6 rounded-lg inline-block bg-gray-200 text-gray-700 transform transition duration-300 hover:scale-105';
statusIndicator.textContent = 'Empty';
steam.classList.add('hidden');
}
}
// Update status in database
function updateStatus(isFull) {
coffeeStatusRef.set(isFull);
// Add to activity feed
const newActivityRef = activityRef.push();
newActivityRef.set({
userId: userId,
userName: userName,
status: isFull,
timestamp: firebase.database.ServerValue.TIMESTAMP
});
// Visual feedback
const button = isFull ? btnFill : btnEmpty;
button.classList.add('pulse');
setTimeout(() => {
button.classList.remove('pulse');
}, 2000);
}
// Format timestamp
function formatTime(timestamp) {
const date = new Date(timestamp);
return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
}
// Initialize with empty status
coffeeStatusRef.once('value', (snapshot) => {
if (snapshot.val() === null) {
coffeeStatusRef.set(false);
}
});
</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=RedMoe/coffee-can-tracker" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>