Spaces:
Running
Running
Download index.html from binneht3/tracking-page: direct link, hf CLI and curl.
- Browser
- Download file 23.9 kB
-
https://huggingface.co/spaces/binneht3/tracking-page/resolve/main/index.html
- Command line
-
hf download hf://spaces/binneht3/tracking-page/index.html
-
curl -L -o index.html https://huggingface.co/spaces/binneht3/tracking-page/resolve/main/index.html
23.9 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Advanced Expense 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 src="https://cdn.jsdelivr.net/npm/chart.js"></script> | |
| <style> | |
| .fade-in { | |
| animation: fadeIn 0.3s ease-in-out; | |
| } | |
| @keyframes fadeIn { | |
| from { opacity: 0; transform: translateY(10px); } | |
| to { opacity: 1; transform: translateY(0); } | |
| } | |
| .shake { | |
| animation: shake 0.5s ease-in-out; | |
| } | |
| @keyframes shake { | |
| 0%, 100% { transform: translateX(0); } | |
| 20%, 60% { transform: translateX(-5px); } | |
| 40%, 80% { transform: translateX(5px); } | |
| } | |
| .chart-container { | |
| position: relative; | |
| height: 300px; | |
| width: 100%; | |
| } | |
| @media (max-width: 640px) { | |
| .chart-container { | |
| height: 250px; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gray-50 min-h-screen"> | |
| <div class="container mx-auto px-4 py-8"> | |
| <!-- Header --> | |
| <header class="mb-8 text-center"> | |
| <h1 class="text-3xl md:text-4xl font-bold text-indigo-700 mb-2">Expense Tracker</h1> | |
| <p class="text-gray-600">Track your spending and stay within budget</p> | |
| </header> | |
| <!-- Budget Display and Edit --> | |
| <div class="bg-white rounded-lg shadow-md p-6 mb-6"> | |
| <div class="flex flex-col md:flex-row md:items-center md:justify-between"> | |
| <div class="mb-4 md:mb-0"> | |
| <h2 class="text-xl font-semibold text-gray-800">Monthly Budget</h2> | |
| <div id="budget-display" class="text-2xl font-bold text-indigo-600 mt-1"></div> | |
| </div> | |
| <button id="edit-budget-btn" class="bg-indigo-100 text-indigo-700 px-4 py-2 rounded-lg hover:bg-indigo-200 transition flex items-center"> | |
| <i class="fas fa-edit mr-2"></i> Edit Budget | |
| </button> | |
| </div> | |
| <!-- Budget Edit Form (Hidden by default) --> | |
| <div id="budget-edit-form" class="hidden mt-4 fade-in"> | |
| <div class="flex flex-col md:flex-row gap-4"> | |
| <input type="number" id="new-budget" placeholder="Enter new budget" class="flex-1 px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500"> | |
| <button id="save-budget-btn" class="bg-indigo-600 text-white px-4 py-2 rounded-lg hover:bg-indigo-700 transition">Save</button> | |
| <button id="cancel-budget-btn" class="bg-gray-200 text-gray-700 px-4 py-2 rounded-lg hover:bg-gray-300 transition">Cancel</button> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Summary Cards --> | |
| <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6"> | |
| <div class="bg-white rounded-lg shadow-md p-4"> | |
| <div class="flex items-center justify-between"> | |
| <div> | |
| <p class="text-gray-600">Total Spent</p> | |
| <p id="total-spent" class="text-2xl font-bold text-gray-800">$0</p> | |
| </div> | |
| <div class="bg-indigo-100 p-3 rounded-full"> | |
| <i class="fas fa-wallet text-indigo-600"></i> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="bg-white rounded-lg shadow-md p-4"> | |
| <div class="flex items-center justify-between"> | |
| <div> | |
| <p class="text-gray-600">Remaining</p> | |
| <p id="remaining-budget" class="text-2xl font-bold text-green-600">$0</p> | |
| </div> | |
| <div class="bg-green-100 p-3 rounded-full"> | |
| <i class="fas fa-piggy-bank text-green-600"></i> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="bg-white rounded-lg shadow-md p-4"> | |
| <div class="flex items-center justify-between"> | |
| <div> | |
| <p class="text-gray-600">Expense Count</p> | |
| <p id="expense-count" class="text-2xl font-bold text-gray-800">0</p> | |
| </div> | |
| <div class="bg-blue-100 p-3 rounded-full"> | |
| <i class="fas fa-receipt text-blue-600"></i> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Budget Alert --> | |
| <div id="budget-alert" class="hidden mb-6 fade-in"> | |
| <div class="bg-red-100 border-l-4 border-red-500 text-red-700 p-4 rounded-lg"> | |
| <div class="flex items-center"> | |
| <i class="fas fa-exclamation-circle mr-3 text-xl"></i> | |
| <div> | |
| <p class="font-bold">Budget Exceeded!</p> | |
| <p>You've spent more than your budget. Consider reviewing your expenses.</p> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Chart Section --> | |
| <div class="bg-white rounded-lg shadow-md p-6 mb-6"> | |
| <h2 class="text-xl font-semibold text-gray-800 mb-4">Expense Breakdown</h2> | |
| <div class="chart-container"> | |
| <canvas id="expense-chart"></canvas> | |
| </div> | |
| </div> | |
| <!-- Add Expense Form --> | |
| <div class="bg-white rounded-lg shadow-md p-6 mb-6"> | |
| <h2 class="text-xl font-semibold text-gray-800 mb-4">Add New Expense</h2> | |
| <form id="expense-form" class="space-y-4"> | |
| <div class="grid grid-cols-1 md:grid-cols-3 gap-4"> | |
| <div> | |
| <label for="expense-name" class="block text-sm font-medium text-gray-700 mb-1">Expense Name</label> | |
| <input type="text" id="expense-name" required class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500"> | |
| </div> | |
| <div> | |
| <label for="expense-amount" class="block text-sm font-medium text-gray-700 mb-1">Amount ($)</label> | |
| <input type="number" id="expense-amount" min="0.01" step="0.01" required class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500"> | |
| </div> | |
| <div> | |
| <label for="expense-category" class="block text-sm font-medium text-gray-700 mb-1">Category</label> | |
| <select id="expense-category" required class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500"> | |
| <option value="">Select a category</option> | |
| <option value="Food">Food</option> | |
| <option value="Transportation">Transportation</option> | |
| <option value="Housing">Housing</option> | |
| <option value="Entertainment">Entertainment</option> | |
| <option value="Utilities">Utilities</option> | |
| <option value="Healthcare">Healthcare</option> | |
| <option value="Shopping">Shopping</option> | |
| <option value="Other">Other</option> | |
| </select> | |
| </div> | |
| </div> | |
| <div class="flex justify-end"> | |
| <button type="submit" class="bg-indigo-600 text-white px-6 py-2 rounded-lg hover:bg-indigo-700 transition flex items-center"> | |
| <i class="fas fa-plus mr-2"></i> Add Expense | |
| </button> | |
| </div> | |
| </form> | |
| </div> | |
| <!-- Expense History --> | |
| <div class="bg-white rounded-lg shadow-md p-6"> | |
| <div class="flex justify-between items-center mb-4"> | |
| <h2 class="text-xl font-semibold text-gray-800">Expense History</h2> | |
| <button id="clear-all-btn" class="text-red-600 hover:text-red-800 text-sm font-medium flex items-center"> | |
| <i class="fas fa-trash-alt mr-1"></i> Clear All | |
| </button> | |
| </div> | |
| <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-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Name</th> | |
| <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Amount</th> | |
| <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Category</th> | |
| <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Date</th> | |
| <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th> | |
| </tr> | |
| </thead> | |
| <tbody id="expense-table-body" class="bg-white divide-y divide-gray-200"> | |
| <!-- Expenses will be added here dynamically --> | |
| </tbody> | |
| </table> | |
| <div id="no-expenses-message" class="text-center py-8 text-gray-500"> | |
| <i class="fas fa-receipt text-4xl mb-2 opacity-30"></i> | |
| <p>No expenses added yet. Start by adding your first expense!</p> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| // DOM Elements | |
| const budgetDisplay = document.getElementById('budget-display'); | |
| const editBudgetBtn = document.getElementById('edit-budget-btn'); | |
| const budgetEditForm = document.getElementById('budget-edit-form'); | |
| const newBudgetInput = document.getElementById('new-budget'); | |
| const saveBudgetBtn = document.getElementById('save-budget-btn'); | |
| const cancelBudgetBtn = document.getElementById('cancel-budget-btn'); | |
| const totalSpentDisplay = document.getElementById('total-spent'); | |
| const remainingBudgetDisplay = document.getElementById('remaining-budget'); | |
| const expenseCountDisplay = document.getElementById('expense-count'); | |
| const budgetAlert = document.getElementById('budget-alert'); | |
| const expenseForm = document.getElementById('expense-form'); | |
| const expenseTableBody = document.getElementById('expense-table-body'); | |
| const noExpensesMessage = document.getElementById('no-expenses-message'); | |
| const clearAllBtn = document.getElementById('clear-all-btn'); | |
| // Chart setup | |
| let expenseChart; | |
| const chartCtx = document.getElementById('expense-chart').getContext('2d'); | |
| // Initial Data | |
| let budget = 1000; | |
| let expenses = []; | |
| let categories = ['Food', 'Transportation', 'Housing', 'Entertainment', 'Utilities', 'Healthcare', 'Shopping', 'Other']; | |
| // Initialize the app | |
| function init() { | |
| loadFromLocalStorage(); | |
| updateBudgetDisplay(); | |
| updateSummary(); | |
| renderExpenseTable(); | |
| renderChart(); | |
| // Set up event listeners | |
| editBudgetBtn.addEventListener('click', showBudgetEditForm); | |
| saveBudgetBtn.addEventListener('click', saveBudget); | |
| cancelBudgetBtn.addEventListener('click', hideBudgetEditForm); | |
| expenseForm.addEventListener('submit', addExpense); | |
| clearAllBtn.addEventListener('click', clearAllExpenses); | |
| } | |
| // Load data from localStorage | |
| function loadFromLocalStorage() { | |
| const savedBudget = localStorage.getItem('expenseTracker_budget'); | |
| const savedExpenses = localStorage.getItem('expenseTracker_expenses'); | |
| if (savedBudget) { | |
| budget = parseFloat(savedBudget); | |
| } | |
| if (savedExpenses) { | |
| expenses = JSON.parse(savedExpenses); | |
| } | |
| } | |
| // Save data to localStorage | |
| function saveToLocalStorage() { | |
| localStorage.setItem('expenseTracker_budget', budget.toString()); | |
| localStorage.setItem('expenseTracker_expenses', JSON.stringify(expenses)); | |
| } | |
| // Update budget display | |
| function updateBudgetDisplay() { | |
| budgetDisplay.textContent = `$${budget.toFixed(2)}`; | |
| } | |
| // Show budget edit form | |
| function showBudgetEditForm() { | |
| newBudgetInput.value = budget; | |
| budgetEditForm.classList.remove('hidden'); | |
| editBudgetBtn.classList.add('hidden'); | |
| } | |
| // Hide budget edit form | |
| function hideBudgetEditForm() { | |
| budgetEditForm.classList.add('hidden'); | |
| editBudgetBtn.classList.remove('hidden'); | |
| } | |
| // Save new budget | |
| function saveBudget() { | |
| const newBudget = parseFloat(newBudgetInput.value); | |
| if (isNaN(newBudget) || newBudget <= 0) { | |
| alert('Please enter a valid budget amount'); | |
| newBudgetInput.classList.add('shake'); | |
| setTimeout(() => newBudgetInput.classList.remove('shake'), 500); | |
| return; | |
| } | |
| budget = newBudget; | |
| updateBudgetDisplay(); | |
| updateSummary(); | |
| hideBudgetEditForm(); | |
| saveToLocalStorage(); | |
| } | |
| // Update summary cards | |
| function updateSummary() { | |
| const totalSpent = expenses.reduce((sum, expense) => sum + expense.amount, 0); | |
| const remaining = budget - totalSpent; | |
| const expenseCount = expenses.length; | |
| totalSpentDisplay.textContent = `$${totalSpent.toFixed(2)}`; | |
| remainingBudgetDisplay.textContent = `$${remaining.toFixed(2)}`; | |
| expenseCountDisplay.textContent = expenseCount; | |
| // Update colors based on budget status | |
| if (remaining < 0) { | |
| remainingBudgetDisplay.classList.remove('text-green-600'); | |
| remainingBudgetDisplay.classList.add('text-red-600'); | |
| budgetAlert.classList.remove('hidden'); | |
| } else { | |
| remainingBudgetDisplay.classList.remove('text-red-600'); | |
| remainingBudgetDisplay.classList.add('text-green-600'); | |
| budgetAlert.classList.add('hidden'); | |
| } | |
| } | |
| // Add new expense | |
| function addExpense(e) { | |
| e.preventDefault(); | |
| const name = document.getElementById('expense-name').value.trim(); | |
| const amount = parseFloat(document.getElementById('expense-amount').value); | |
| const category = document.getElementById('expense-category').value; | |
| if (!name || isNaN(amount) || amount <= 0 || !category) { | |
| alert('Please fill in all fields with valid values'); | |
| return; | |
| } | |
| const newExpense = { | |
| id: Date.now(), | |
| name, | |
| amount, | |
| category, | |
| date: new Date().toLocaleDateString() | |
| }; | |
| expenses.push(newExpense); | |
| saveToLocalStorage(); | |
| updateSummary(); | |
| renderExpenseTable(); | |
| renderChart(); | |
| // Reset form | |
| expenseForm.reset(); | |
| // Show success animation | |
| const submitBtn = expenseForm.querySelector('button[type="submit"]'); | |
| submitBtn.innerHTML = '<i class="fas fa-check mr-2"></i> Added!'; | |
| submitBtn.classList.remove('bg-indigo-600'); | |
| submitBtn.classList.add('bg-green-500'); | |
| setTimeout(() => { | |
| submitBtn.innerHTML = '<i class="fas fa-plus mr-2"></i> Add Expense'; | |
| submitBtn.classList.remove('bg-green-500'); | |
| submitBtn.classList.add('bg-indigo-600'); | |
| }, 1500); | |
| } | |
| // Delete expense | |
| function deleteExpense(id) { | |
| expenses = expenses.filter(expense => expense.id !== id); | |
| saveToLocalStorage(); | |
| updateSummary(); | |
| renderExpenseTable(); | |
| renderChart(); | |
| } | |
| // Clear all expenses | |
| function clearAllExpenses() { | |
| if (expenses.length === 0 || !confirm('Are you sure you want to delete all expenses?')) { | |
| return; | |
| } | |
| expenses = []; | |
| saveToLocalStorage(); | |
| updateSummary(); | |
| renderExpenseTable(); | |
| renderChart(); | |
| } | |
| // Render expense table | |
| function renderExpenseTable() { | |
| if (expenses.length === 0) { | |
| expenseTableBody.innerHTML = ''; | |
| noExpensesMessage.classList.remove('hidden'); | |
| return; | |
| } | |
| noExpensesMessage.classList.add('hidden'); | |
| expenseTableBody.innerHTML = expenses.map(expense => ` | |
| <tr class="hover:bg-gray-50 fade-in"> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${expense.name}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">$${expense.amount.toFixed(2)}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500"> | |
| <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${getCategoryColorClass(expense.category)}"> | |
| ${expense.category} | |
| </span> | |
| </td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${expense.date}</td> | |
| <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500"> | |
| <button onclick="deleteExpense(${expense.id})" class="text-red-600 hover:text-red-900"> | |
| <i class="fas fa-trash-alt"></i> | |
| </button> | |
| </td> | |
| </tr> | |
| `).join(''); | |
| } | |
| // Get color class for category badge | |
| function getCategoryColorClass(category) { | |
| const colors = { | |
| 'Food': 'bg-green-100 text-green-800', | |
| 'Transportation': 'bg-blue-100 text-blue-800', | |
| 'Housing': 'bg-purple-100 text-purple-800', | |
| 'Entertainment': 'bg-yellow-100 text-yellow-800', | |
| 'Utilities': 'bg-indigo-100 text-indigo-800', | |
| 'Healthcare': 'bg-pink-100 text-pink-800', | |
| 'Shopping': 'bg-red-100 text-red-800', | |
| 'Other': 'bg-gray-100 text-gray-800' | |
| }; | |
| return colors[category] || 'bg-gray-100 text-gray-800'; | |
| } | |
| // Render chart | |
| function renderChart() { | |
| // Calculate category totals | |
| const categoryTotals = {}; | |
| categories.forEach(cat => { | |
| categoryTotals[cat] = 0; | |
| }); | |
| expenses.forEach(expense => { | |
| categoryTotals[expense.category] += expense.amount; | |
| }); | |
| // Prepare data for chart | |
| const labels = categories; | |
| const data = categories.map(cat => categoryTotals[cat]); | |
| const backgroundColors = [ | |
| 'rgba(16, 185, 129, 0.6)', // Food - green | |
| 'rgba(59, 130, 246, 0.6)', // Transportation - blue | |
| 'rgba(168, 85, 247, 0.6)', // Housing - purple | |
| 'rgba(234, 179, 8, 0.6)', // Entertainment - yellow | |
| 'rgba(99, 102, 241, 0.6)', // Utilities - indigo | |
| 'rgba(236, 72, 153, 0.6)', // Healthcare - pink | |
| 'rgba(239, 68, 68, 0.6)', // Shopping - red | |
| 'rgba(156, 163, 175, 0.6)' // Other - gray | |
| ]; | |
| // Destroy previous chart if it exists | |
| if (expenseChart) { | |
| expenseChart.destroy(); | |
| } | |
| // Create new chart | |
| expenseChart = new Chart(chartCtx, { | |
| type: 'doughnut', | |
| data: { | |
| labels: labels, | |
| datasets: [{ | |
| data: data, | |
| backgroundColor: backgroundColors, | |
| borderWidth: 1, | |
| hoverOffset: 10 | |
| }] | |
| }, | |
| options: { | |
| responsive: true, | |
| maintainAspectRatio: false, | |
| plugins: { | |
| legend: { | |
| position: 'right', | |
| labels: { | |
| boxWidth: 12, | |
| padding: 20, | |
| usePointStyle: true, | |
| pointStyle: 'circle' | |
| } | |
| }, | |
| tooltip: { | |
| callbacks: { | |
| label: function(context) { | |
| const label = context.label || ''; | |
| const value = context.raw || 0; | |
| const total = context.dataset.data.reduce((acc, curr) => acc + curr, 0); | |
| const percentage = total > 0 ? Math.round((value / total) * 100) : 0; | |
| return `${label}: $${value.toFixed(2)} (${percentage}%)`; | |
| } | |
| } | |
| } | |
| }, | |
| cutout: '65%', | |
| animation: { | |
| animateScale: true, | |
| animateRotate: true | |
| } | |
| } | |
| }); | |
| } | |
| // 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=binneht3/tracking-page" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> | |
| </html> |