Spaces:
Running
Running
Download index.html from atlkaran635/codes: direct link, hf CLI and curl.
- Browser
- Download file 52.5 kB
-
https://huggingface.co/spaces/atlkaran635/codes/resolve/main/index.html
- Command line
-
hf download hf://spaces/atlkaran635/codes/index.html
-
curl -L -o index.html https://huggingface.co/spaces/atlkaran635/codes/resolve/main/index.html
52.5 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Expenses 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: {
primary: '#007AFF',
secondary: '#34C759',
danger: '#FF3B30',
warning: '#FF9500',
dark: '#1C1C1E',
light: '#F2F2F7',
gray: {
100: '#F2F2F7',
200: '#E5E5EA',
300: '#D1D1D6',
400: '#C7C7CC',
500: '#AEAEB2',
600: '#8E8E93',
700: '#636366',
800: '#48484A',
900: '#3A3A3C'
}
},
animation: {
'fade-in': 'fadeIn 0.3s ease-out forwards',
'slide-up': 'slideUp 0.5s cubic-bezier(0.23, 1, 0.32, 1) forwards',
'slide-down': 'slideDown 0.5s cubic-bezier(0.23, 1, 0.32, 1) forwards',
'scale-in': 'scaleIn 0.3s cubic-bezier(0.23, 1, 0.32, 1) forwards',
'scale-out': 'scaleOut 0.3s cubic-bezier(0.23, 1, 0.32, 1) forwards',
'pulse-slow': 'pulse 3s cubic-bezier(0.4, 0, 0.6, 1) infinite'
},
keyframes: {
fadeIn: {
'0%': { opacity: '0' },
'100%': { opacity: '1' }
},
slideUp: {
'0%': { transform: 'translateY(50px)', opacity: '0' },
'100%': { transform: 'translateY(0)', opacity: '1' }
},
slideDown: {
'0%': { transform: 'translateY(-50px)', opacity: '0' },
'100%': { transform: 'translateY(0)', opacity: '1' }
},
scaleIn: {
'0%': { transform: 'scale(0.95)', opacity: '0' },
'100%': { transform: 'scale(1)', opacity: '1' }
},
scaleOut: {
'0%': { transform: 'scale(1)', opacity: '1' },
'100%': { transform: 'scale(0.95)', opacity: '0' }
}
}
}
}
}
</script>
<style>
@import url('https://fonts.googleapis.com/css2?family=SF+Pro+Display:wght@300;400;500;600;700&display=swap');
body {
font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, sans-serif;
background-color: #F2F2F7;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
/* iOS-like scrollbar */
::-webkit-scrollbar {
width: 6px;
height: 6px;
}
::-webkit-scrollbar-thumb {
background-color: rgba(0, 0, 0, 0.2);
border-radius: 3px;
}
::-webkit-scrollbar-track {
background-color: transparent;
}
.card {
border-radius: 14px;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
}
.transaction-item {
transition: transform 0.3s cubic-bezier(0.23, 1, 0.32, 1);
}
.transaction-item:hover {
transform: translateX(8px);
}
.progress-bar {
transition: width 0.8s cubic-bezier(0.23, 1, 0.32, 1);
}
.floating-btn {
box-shadow: 0 6px 20px rgba(0, 122, 255, 0.3);
transition: all 0.3s cubic-bezier(0.23, 1, 0.32, 1);
}
.floating-btn:hover {
transform: scale(1.1);
box-shadow: 0 8px 25px rgba(0, 122, 255, 0.4);
}
.modal-overlay {
background: rgba(0, 0, 0, 0.5);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
}
.ios-select {
appearance: none;
-webkit-appearance: none;
background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%238E8E93'%3e%3cpath d='M7 10l5 5 5-5z'/%3e%3c/svg%3e");
background-repeat: no-repeat;
background-position: right 10px center;
background-size: 12px;
}
/* iOS-like switch */
.ios-switch {
position: relative;
display: inline-block;
width: 44px;
height: 28px;
}
.ios-switch input {
opacity: 0;
width: 0;
height: 0;
}
.ios-slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #E5E5EA;
transition: .4s;
border-radius: 34px;
}
.ios-slider:before {
position: absolute;
content: "";
height: 24px;
width: 24px;
left: 2px;
bottom: 2px;
background-color: white;
transition: .4s;
border-radius: 50%;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}
input:checked + .ios-slider {
background-color: #34C759;
}
input:checked + .ios-slider:before {
transform: translateX(16px);
}
/* iOS-like segmented control */
.segmented-control {
display: flex;
border-radius: 8px;
background-color: #E5E5EA;
padding: 3px;
}
.segmented-control input[type="radio"] {
display: none;
}
.segmented-control label {
flex: 1;
text-align: center;
padding: 8px 12px;
border-radius: 6px;
cursor: pointer;
transition: all 0.3s ease;
}
.segmented-control input[type="radio"]:checked + label {
background-color: white;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body class="min-h-screen">
<div class="container mx-auto px-4 py-6 max-w-6xl">
<!-- Header -->
<header class="flex justify-between items-center mb-6 animate-fade-in">
<div>
<h1 class="text-2xl font-semibold text-dark">Expenses Tracker</h1>
<p class="text-gray-600 text-sm">Track your daily spending</p>
</div>
<div class="flex items-center space-x-3">
<button id="settings-btn" class="p-2 rounded-full hover:bg-gray-200 transition">
<i class="fas fa-cog text-gray-600"></i>
</button>
<div class="h-9 w-9 rounded-full bg-primary flex items-center justify-center text-white font-medium">
<i class="fas fa-user"></i>
</div>
</div>
</header>
<!-- Summary Cards -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
<!-- Balance Card -->
<div class="bg-white card p-5 animate-slide-up">
<div class="flex justify-between items-start">
<div>
<p class="text-gray-600 text-sm">Total Balance</p>
<h2 id="total-balance" class="text-2xl font-bold mt-1">$0.00</h2>
</div>
<div class="p-2 rounded-lg bg-blue-50 text-primary">
<i class="fas fa-wallet text-lg"></i>
</div>
</div>
<div class="mt-4 flex justify-between text-xs">
<div>
<p class="text-gray-600">Income</p>
<p id="total-income" class="font-medium text-secondary">$0.00</p>
</div>
<div>
<p class="text-gray-600">Expenses</p>
<p id="total-expenses" class="font-medium text-danger">$0.00</p>
</div>
</div>
</div>
<!-- Budget Card -->
<div class="bg-white card p-5 animate-slide-up" style="animation-delay: 0.1s">
<div class="flex justify-between items-start">
<div>
<p class="text-gray-600 text-sm">Monthly Budget</p>
<h2 id="monthly-budget" class="text-2xl font-bold mt-1">$0.00</h2>
</div>
<div class="p-2 rounded-lg bg-green-50 text-secondary">
<i class="fas fa-chart-pie text-lg"></i>
</div>
</div>
<div class="mt-4">
<p class="text-gray-600 text-xs mb-1">Spent: <span id="budget-spent">$0.00</span> (<span id="budget-percentage">0</span>%)</p>
<div class="w-full bg-gray-200 rounded-full h-2">
<div id="budget-progress" class="bg-secondary h-2 rounded-full progress-bar" style="width: 0%"></div>
</div>
</div>
</div>
<!-- Savings Goal -->
<div class="bg-white card p-5 animate-slide-up" style="animation-delay: 0.2s">
<div class="flex justify-between items-start">
<div>
<p class="text-gray-600 text-sm">Savings Goal</p>
<h2 id="savings-goal" class="text-2xl font-bold mt-1">$0.00</h2>
</div>
<div class="p-2 rounded-lg bg-green-50 text-secondary">
<i class="fas fa-piggy-bank text-lg"></i>
</div>
</div>
<div class="mt-4">
<p class="text-gray-600 text-xs mb-1">Saved: <span id="savings-amount">$0.00</span> (<span id="savings-percentage">0</span>%)</p>
<div class="w-full bg-gray-200 rounded-full h-2">
<div id="savings-progress" class="bg-secondary h-2 rounded-full progress-bar" style="width: 0%"></div>
</div>
</div>
</div>
</div>
<!-- Main Content -->
<div class="grid grid-cols-1 lg:grid-cols-3 gap-4">
<!-- Transactions Section -->
<div class="lg:col-span-2">
<div class="bg-white card p-5 mb-4 animate-fade-in">
<div class="flex justify-between items-center mb-4">
<h2 class="text-lg font-semibold">Recent Transactions</h2>
<div class="flex space-x-2">
<button id="filter-btn" class="text-sm text-primary bg-blue-50 px-3 py-1 rounded-lg">
<i class="fas fa-filter mr-1"></i> Filter
</button>
<button id="add-manual-btn" class="text-sm text-white bg-primary px-3 py-1 rounded-lg">
<i class="fas fa-plus mr-1"></i> Add
</button>
</div>
</div>
<div id="transactions-container" class="space-y-3 max-h-96 overflow-y-auto pr-2">
<!-- Transactions will be loaded here -->
</div>
<button id="view-all-btn" class="w-full mt-4 py-2 text-primary font-medium rounded-lg border border-gray-200 hover:bg-gray-50 transition text-sm">
View All Transactions
</button>
</div>
<!-- Spending Chart -->
<div class="bg-white card p-5 animate-fade-in">
<div class="flex justify-between items-center mb-4">
<h2 class="text-lg font-semibold">Spending Analytics</h2>
<select id="chart-period" class="bg-gray-100 border-0 text-gray-700 rounded-lg px-3 py-1 text-sm ios-select">
<option value="week">This Week</option>
<option value="month" selected>This Month</option>
<option value="year">This Year</option>
</select>
</div>
<div class="chart-container h-48 mt-4">
<canvas id="spending-chart"></canvas>
</div>
</div>
</div>
<!-- Categories Breakdown -->
<div class="lg:col-span-1">
<div class="bg-white card p-5 mb-4 animate-fade-in">
<h2 class="text-lg font-semibold mb-4">Categories</h2>
<div id="categories-container" class="space-y-3 max-h-64 overflow-y-auto pr-2">
<!-- Categories will be loaded here -->
</div>
<button id="manage-categories-btn" class="w-full mt-4 py-2 text-gray-600 font-medium rounded-lg border border-gray-200 hover:bg-gray-50 transition text-sm">
Manage Categories
</button>
</div>
<!-- Budget Settings -->
<div class="bg-white card p-5 animate-fade-in">
<h2 class="text-lg font-semibold mb-4">Budget Settings</h2>
<div class="space-y-4">
<div>
<div class="flex justify-between items-center mb-1">
<span class="text-sm font-medium">Monthly Budget</span>
<input type="number" id="set-budget-input" class="w-24 px-2 py-1 rounded-lg border border-gray-200 text-right" placeholder="0.00">
</div>
<div class="text-xs text-gray-500">Set your monthly spending limit</div>
</div>
<div>
<div class="flex justify-between items-center mb-1">
<span class="text-sm font-medium">Savings Goal</span>
<input type="number" id="set-savings-input" class="w-24 px-2 py-1 rounded-lg border border-gray-200 text-right" placeholder="0.00">
</div>
<div class="text-xs text-gray-500">Set your monthly savings target</div>
</div>
<div class="flex justify-between items-center">
<span class="text-sm font-medium">Notifications</span>
<label class="ios-switch">
<input type="checkbox" id="notifications-toggle" checked>
<span class="ios-slider"></span>
</label>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Add Transaction Button -->
<button id="add-transaction-btn" class="fixed bottom-6 right-6 h-14 w-14 rounded-full bg-primary text-white text-xl flex items-center justify-center floating-btn">
<i class="fas fa-plus"></i>
</button>
<!-- Add Transaction Modal -->
<div id="transaction-modal" class="fixed inset-0 z-50 flex items-center justify-center hidden">
<div class="modal-overlay absolute inset-0" id="modal-overlay"></div>
<div class="bg-white rounded-xl w-full max-w-md mx-4 z-10 animate-scale-in" style="max-height: 90vh; overflow-y: auto;">
<div class="p-6">
<div class="flex justify-between items-center mb-4 sticky top-0 bg-white pt-2 pb-4">
<h3 class="text-xl font-semibold">Add Transaction</h3>
<button id="close-modal" class="text-gray-500 hover:text-gray-700 p-1">
<i class="fas fa-times text-lg"></i>
</button>
</div>
<form id="transaction-form">
<div class="space-y-5">
<div>
<label class="block text-sm font-medium text-gray-700 mb-2">Transaction Type</label>
<div class="segmented-control">
<input type="radio" id="type-expense" name="transaction-type" value="expense" checked>
<label for="type-expense" class="text-sm">Expense</label>
<input type="radio" id="type-income" name="transaction-type" value="income">
<label for="type-income" class="text-sm">Income</label>
</div>
</div>
<div>
<label for="amount" class="block text-sm font-medium text-gray-700 mb-1">Amount</label>
<div class="relative">
<span class="absolute inset-y-0 left-0 flex items-center pl-3 text-gray-500">$</span>
<input type="number" id="amount" class="w-full pl-8 pr-4 py-3 rounded-lg border border-gray-200 focus:ring-2 focus:ring-primary focus:border-transparent" placeholder="0.00" step="0.01" min="0">
</div>
</div>
<div>
<label for="category" class="block text-sm font-medium text-gray-700 mb-1">Category</label>
<select id="category" class="w-full px-4 py-3 rounded-lg border border-gray-200 focus:ring-2 focus:ring-primary focus:border-transparent ios-select">
<option value="">Select a category</option>
<!-- Categories will be loaded here -->
</select>
</div>
<div>
<label for="date" class="block text-sm font-medium text-gray-700 mb-1">Date</label>
<input type="date" id="date" class="w-full px-4 py-3 rounded-lg border border-gray-200 focus:ring-2 focus:ring-primary focus:border-transparent">
</div>
<div>
<label for="description" class="block text-sm font-medium text-gray-700 mb-1">Description (Optional)</label>
<input type="text" id="description" class="w-full px-4 py-3 rounded-lg border border-gray-200 focus:ring-2 focus:ring-primary focus:border-transparent" placeholder="e.g. Grocery shopping">
</div>
</div>
<div class="mt-6 flex space-x-3 sticky bottom-0 bg-white pt-4 pb-2">
<button type="button" id="cancel-transaction" class="flex-1 py-3 px-4 rounded-lg border border-gray-200 text-gray-700 font-medium hover:bg-gray-50 transition text-sm">
Cancel
</button>
<button type="submit" class="flex-1 py-3 px-4 rounded-lg bg-primary text-white font-medium hover:bg-blue-600 transition text-sm">
Add Transaction
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Settings Modal -->
<div id="settings-modal" class="fixed inset-0 z-50 flex items-center justify-center hidden">
<div class="modal-overlay absolute inset-0" id="settings-overlay"></div>
<div class="bg-white rounded-xl w-full max-w-md mx-4 z-10 animate-scale-in" style="max-height: 90vh; overflow-y: auto;">
<div class="p-6">
<div class="flex justify-between items-center mb-6 sticky top-0 bg-white pt-2 pb-4">
<h3 class="text-xl font-semibold">Settings</h3>
<button id="close-settings" class="text-gray-500 hover:text-gray-700 p-1">
<i class="fas fa-times text-lg"></i>
</button>
</div>
<div class="space-y-6">
<div>
<h4 class="font-medium text-gray-800 mb-3">General</h4>
<div class="space-y-4">
<div class="flex justify-between items-center">
<span class="text-sm">Currency</span>
<select id="currency-select" class="bg-gray-100 border-0 text-gray-700 rounded-lg px-3 py-1 text-sm ios-select">
<option value="USD">USD ($)</option>
<option value="EUR">EUR (€)</option>
<option value="GBP">GBP (£)</option>
<option value="JPY">JPY (¥)</option>
</select>
</div>
<div class="flex justify-between items-center">
<span class="text-sm">Dark Mode</span>
<label class="ios-switch">
<input type="checkbox" id="dark-mode-toggle">
<span class="ios-slider"></span>
</label>
</div>
</div>
</div>
<div>
<h4 class="font-medium text-gray-800 mb-3">Data</h4>
<div class="space-y-3">
<button id="export-data" class="w-full text-left py-2 px-3 rounded-lg bg-gray-100 hover:bg-gray-200 transition text-sm flex items-center">
<i class="fas fa-file-export text-gray-600 mr-2"></i>
Export Data
</button>
<button id="import-data" class="w-full text-left py-2 px-3 rounded-lg bg-gray-100 hover:bg-gray-200 transition text-sm flex items-center">
<i class="fas fa-file-import text-gray-600 mr-2"></i>
Import Data
</button>
<button id="reset-data" class="w-full text-left py-2 px-3 rounded-lg bg-red-50 hover:bg-red-100 transition text-sm flex items-center text-danger">
<i class="fas fa-trash-alt mr-2"></i>
Reset All Data
</button>
</div>
</div>
<div>
<h4 class="font-medium text-gray-800 mb-3">About</h4>
<div class="text-sm text-gray-600 space-y-2">
<p>Expenses Tracker v1.0.0</p>
<p>© 2023 Expenses Tracker. All rights reserved.</p>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Chart.js for analytics -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
// DOM Elements
const addTransactionBtn = document.getElementById('add-transaction-btn');
const addManualBtn = document.getElementById('add-manual-btn');
const transactionModal = document.getElementById('transaction-modal');
const modalOverlay = document.getElementById('modal-overlay');
const closeModalBtn = document.getElementById('close-modal');
const cancelTransactionBtn = document.getElementById('cancel-transaction');
const transactionForm = document.getElementById('transaction-form');
const settingsBtn = document.getElementById('settings-btn');
const settingsModal = document.getElementById('settings-modal');
const settingsOverlay = document.getElementById('settings-overlay');
const closeSettingsBtn = document.getElementById('close-settings');
const viewAllBtn = document.getElementById('view-all-btn');
const manageCategoriesBtn = document.getElementById('manage-categories-btn');
// Data elements
const totalBalanceEl = document.getElementById('total-balance');
const totalIncomeEl = document.getElementById('total-income');
const totalExpensesEl = document.getElementById('total-expenses');
const monthlyBudgetEl = document.getElementById('monthly-budget');
const budgetSpentEl = document.getElementById('budget-spent');
const budgetPercentageEl = document.getElementById('budget-percentage');
const budgetProgressEl = document.getElementById('budget-progress');
const savingsGoalEl = document.getElementById('savings-goal');
const savingsAmountEl = document.getElementById('savings-amount');
const savingsPercentageEl = document.getElementById('savings-percentage');
const savingsProgressEl = document.getElementById('savings-progress');
const setBudgetInput = document.getElementById('set-budget-input');
const setSavingsInput = document.getElementById('set-savings-input');
const notificationsToggle = document.getElementById('notifications-toggle');
const darkModeToggle = document.getElementById('dark-mode-toggle');
const currencySelect = document.getElementById('currency-select');
const exportDataBtn = document.getElementById('export-data');
const importDataBtn = document.getElementById('import-data');
const resetDataBtn = document.getElementById('reset-data');
// Initialize app data
let transactions = JSON.parse(localStorage.getItem('transactions')) || [];
let categories = JSON.parse(localStorage.getItem('categories')) || [
{ id: 1, name: 'Food & Dining', icon: 'utensils', color: 'bg-red-100', textColor: 'text-red-500' },
{ id: 2, name: 'Transportation', icon: 'subway', color: 'bg-blue-100', textColor: 'text-blue-500' },
{ id: 3, name: 'Shopping', icon: 'shopping-bag', color: 'bg-purple-100', textColor: 'text-purple-500' },
{ id: 4, name: 'Entertainment', icon: 'film', color: 'bg-yellow-100', textColor: 'text-yellow-500' },
{ id: 5, name: 'Utilities', icon: 'bolt', color: 'bg-green-100', textColor: 'text-green-500' },
{ id: 6, name: 'Health', icon: 'heartbeat', color: 'bg-pink-100', textColor: 'text-pink-500' },
{ id: 7, name: 'Education', icon: 'book', color: 'bg-indigo-100', textColor: 'text-indigo-500' },
{ id: 8, name: 'Salary', icon: 'money-bill-wave', color: 'bg-green-100', textColor: 'text-green-500' },
{ id: 9, name: 'Investment', icon: 'chart-line', color: 'bg-teal-100', textColor: 'text-teal-500' },
{ id: 10, name: 'Other', icon: 'ellipsis-h', color: 'bg-gray-100', textColor: 'text-gray-500' }
];
let settings = JSON.parse(localStorage.getItem('settings')) || {
monthlyBudget: 0,
savingsGoal: 0,
notifications: true,
darkMode: false,
currency: 'USD'
};
// Initialize Chart
let spendingChart;
// Event Listeners
document.addEventListener('DOMContentLoaded', () => {
loadSettings();
loadCategories();
loadTransactions();
updateSummary();
initChart();
// Set current date as default
document.getElementById('date').valueAsDate = new Date();
});
addTransactionBtn.addEventListener('click', openTransactionModal);
addManualBtn.addEventListener('click', openTransactionModal);
modalOverlay.addEventListener('click', closeTransactionModal);
closeModalBtn.addEventListener('click', closeTransactionModal);
cancelTransactionBtn.addEventListener('click', closeTransactionModal);
transactionForm.addEventListener('submit', addTransaction);
settingsBtn.addEventListener('click', openSettingsModal);
settingsOverlay.addEventListener('click', closeSettingsModal);
closeSettingsBtn.addEventListener('click', closeSettingsModal);
viewAllBtn.addEventListener('click', () => {
// In a real app, this would show all transactions
alert('Showing all transactions');
});
manageCategoriesBtn.addEventListener('click', () => {
// In a real app, this would manage categories
alert('Manage categories feature');
});
setBudgetInput.addEventListener('change', updateBudget);
setSavingsInput.addEventListener('change', updateSavingsGoal);
notificationsToggle.addEventListener('change', toggleNotifications);
// Settings event listeners
darkModeToggle.addEventListener('change', toggleDarkMode);
currencySelect.addEventListener('change', updateCurrency);
exportDataBtn.addEventListener('click', exportData);
importDataBtn.addEventListener('click', () => {
document.getElementById('import-file').click();
});
resetDataBtn.addEventListener('click', resetData);
// Functions
function openTransactionModal() {
transactionModal.classList.remove('hidden');
document.body.style.overflow = 'hidden';
}
function closeTransactionModal() {
transactionModal.classList.add('hidden');
document.body.style.overflow = 'auto';
transactionForm.reset();
document.getElementById('type-expense').checked = true;
document.getElementById('date').valueAsDate = new Date();
}
function openSettingsModal() {
settingsModal.classList.remove('hidden');
document.body.style.overflow = 'hidden';
}
function closeSettingsModal() {
settingsModal.classList.add('hidden');
document.body.style.overflow = 'auto';
}
function loadSettings() {
setBudgetInput.value = settings.monthlyBudget;
setSavingsInput.value = settings.savingsGoal;
notificationsToggle.checked = settings.notifications;
darkModeToggle.checked = settings.darkMode;
currencySelect.value = settings.currency;
if (settings.darkMode) {
document.documentElement.classList.add('dark');
}
}
function loadCategories() {
const categorySelect = document.getElementById('category');
categorySelect.innerHTML = '<option value="">Select a category</option>';
categories.forEach(category => {
const option = document.createElement('option');
option.value = category.id;
option.textContent = category.name;
categorySelect.appendChild(option);
});
// Load categories for display
const categoriesContainer = document.getElementById('categories-container');
categoriesContainer.innerHTML = '';
// Calculate expenses by category
const expensesByCategory = {};
transactions.forEach(transaction => {
if (transaction.type === 'expense') {
if (!expensesByCategory[transaction.category]) {
expensesByCategory[transaction.category] = 0;
}
expensesByCategory[transaction.category] += transaction.amount;
}
});
// Display top 5 categories
const topCategories = categories
.filter(cat => expensesByCategory[cat.id])
.sort((a, b) => (expensesByCategory[b.id] || 0) - (expensesByCategory[a.id] || 0))
.slice(0, 5);
if (topCategories.length === 0) {
categoriesContainer.innerHTML = '<p class="text-gray-500 text-sm">No expenses yet</p>';
return;
}
topCategories.forEach(category => {
const amount = expensesByCategory[category.id] || 0;
const totalExpenses = transactions
.filter(t => t.type === 'expense')
.reduce((sum, t) => sum + t.amount, 0);
const percentage = totalExpenses > 0 ? Math.round((amount / totalExpenses) * 100) : 0;
const categoryEl = document.createElement('div');
categoryEl.className = 'animate-fade-in';
categoryEl.innerHTML = `
<div class="flex items-center justify-between">
<div class="flex items-center">
<div class="${category.color} ${category.textColor} h-8 w-8 rounded-full flex items-center justify-center mr-3">
<i class="fas fa-${category.icon} text-sm"></i>
</div>
<span class="text-sm font-medium">${category.name}</span>
</div>
<span class="text-sm font-medium">$${amount.toFixed(2)}</span>
</div>
<div class="mt-1">
<div class="w-full bg-gray-200 rounded-full h-1.5">
<div class="${category.color.replace('bg-', 'bg-').replace('100', '500')} h-1.5 rounded-full progress-bar" style="width: ${percentage}%"></div>
</div>
</div>
`;
categoriesContainer.appendChild(categoryEl);
});
}
function loadTransactions() {
const transactionsContainer = document.getElementById('transactions-container');
transactionsContainer.innerHTML = '';
if (transactions.length === 0) {
transactionsContainer.innerHTML = `
<div class="text-center py-8 animate-fade-in">
<i class="fas fa-receipt text-3xl text-gray-300 mb-2"></i>
<p class="text-gray-500">No transactions yet</p>
<button id="add-first-btn" class="mt-4 text-primary font-medium text-sm">
Add your first transaction
</button>
</div>
`;
document.getElementById('add-first-btn').addEventListener('click', openTransactionModal);
return;
}
// Show last 5 transactions
const recentTransactions = [...transactions]
.sort((a, b) => new Date(b.date) - new Date(a.date))
.slice(0, 5);
recentTransactions.forEach(transaction => {
const category = categories.find(c => c.id === transaction.category) || {
name: 'Unknown',
icon: 'question',
color: 'bg-gray-100',
textColor: 'text-gray-500'
};
const transactionEl = document.createElement('div');
transactionEl.className = 'transaction-item bg-gray-50 p-3 rounded-lg animate-fade-in';
transactionEl.innerHTML = `
<div class="flex items-center justify-between">
<div class="flex items-center">
<div class="${category.color} ${category.textColor} h-10 w-10 rounded-full flex items-center justify-center mr-3">
<i class="fas fa-${category.icon}"></i>
</div>
<div>
<p class="font-medium text-sm">${transaction.description || category.name}</p>
<p class="text-xs text-gray-500">${formatDate(transaction.date)}</p>
</div>
</div>
<div class="text-right">
<p class="font-medium text-sm ${transaction.type === 'income' ? 'text-secondary' : 'text-danger'}">
${transaction.type === 'income' ? '+' : '-'}$${transaction.amount.toFixed(2)}
</p>
<p class="text-xs text-gray-500">${category.name}</p>
</div>
</div>
`;
transactionsContainer.appendChild(transactionEl);
});
}
function addTransaction(e) {
e.preventDefault();
const type = document.querySelector('input[name="transaction-type"]:checked').value;
const amount = parseFloat(document.getElementById('amount').value);
const category = parseInt(document.getElementById('category').value);
const date = document.getElementById('date').value;
const description = document.getElementById('description').value;
if (!amount || amount <= 0) {
alert('Please enter a valid amount');
return;
}
if (!category) {
alert('Please select a category');
return;
}
if (!date) {
alert('Please select a date');
return;
}
const newTransaction = {
id: Date.now(),
type,
amount,
category,
date,
description,
createdAt: new Date().toISOString()
};
transactions.unshift(newTransaction);
saveData();
// Update UI
loadTransactions();
updateSummary();
loadCategories();
updateChart();
// Close modal and reset form
closeTransactionModal();
// Show success feedback (iOS-like toast)
showToast('Transaction added successfully');
}
function updateSummary() {
const totalIncome = transactions
.filter(t => t.type === 'income')
.reduce((sum, t) => sum + t.amount, 0);
const totalExpenses = transactions
.filter(t => t.type === 'expense')
.reduce((sum, t) => sum + t.amount, 0);
const balance = totalIncome - totalExpenses;
const budget = settings.monthlyBudget;
const savings = settings.savingsGoal;
const budgetPercentage = budget > 0 ? Math.round((totalExpenses / budget) * 100) : 0;
const savingsPercentage = savings > 0 ? Math.round((balance / savings) * 100) : 0;
// Update DOM
totalBalanceEl.textContent = `$${balance.toFixed(2)}`;
totalIncomeEl.textContent = `$${totalIncome.toFixed(2)}`;
totalExpensesEl.textContent = `$${totalExpenses.toFixed(2)}`;
monthlyBudgetEl.textContent = `$${budget.toFixed(2)}`;
budgetSpentEl.textContent = `$${totalExpenses.toFixed(2)}`;
budgetPercentageEl.textContent = budgetPercentage;
budgetProgressEl.style.width = `${Math.min(budgetPercentage, 100)}%`;
savingsGoalEl.textContent = `$${savings.toFixed(2)}`;
savingsAmountEl.textContent = `$${Math.max(balance, 0).toFixed(2)}`;
savingsPercentageEl.textContent = savingsPercentage;
savingsProgressEl.style.width = `${Math.min(savingsPercentage, 100)}%`;
// Update progress bar colors based on percentage
if (budgetPercentage > 80) {
budgetProgressEl.classList.remove('bg-secondary');
budgetProgressEl.classList.add('bg-danger');
} else {
budgetProgressEl.classList.remove('bg-danger');
budgetProgressEl.classList.add('bg-secondary');
}
}
function updateBudget() {
settings.monthlyBudget = parseFloat(setBudgetInput.value) || 0;
saveSettings();
updateSummary();
showToast('Budget updated');
}
function updateSavingsGoal() {
settings.savingsGoal = parseFloat(setSavingsInput.value) || 0;
saveSettings();
updateSummary();
showToast('Savings goal updated');
}
function toggleNotifications() {
settings.notifications = notificationsToggle.checked;
saveSettings();
showToast(`Notifications ${settings.notifications ? 'enabled' : 'disabled'}`);
}
function toggleDarkMode() {
settings.darkMode = darkModeToggle.checked;
saveSettings();
if (settings.darkMode) {
document.documentElement.classList.add('dark');
document.body.style.backgroundColor = '#1C1C1E';
} else {
document.documentElement.classList.remove('dark');
document.body.style.backgroundColor = '#F2F2F7';
}
}
function updateCurrency() {
settings.currency = currencySelect.value;
saveSettings();
showToast(`Currency set to ${settings.currency}`);
// In a real app, we would update all currency displays
}
function exportData() {
const data = {
transactions,
categories,
settings,
exportedAt: new Date().toISOString()
};
const dataStr = JSON.stringify(data, null, 2);
const dataUri = 'data:application/json;charset=utf-8,' + encodeURIComponent(dataStr);
const exportFileDefaultName = `expenses-tracker-export-${new Date().toISOString().slice(0, 10)}.json`;
const linkElement = document.createElement('a');
linkElement.setAttribute('href', dataUri);
linkElement.setAttribute('download', exportFileDefaultName);
linkElement.click();
showToast('Data exported successfully');
}
function importData(e) {
const file = e.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function(e) {
try {
const data = JSON.parse(e.target.result);
if (confirm('This will replace all your current data. Are you sure?')) {
transactions = data.transactions || [];
categories = data.categories || [];
settings = data.settings || {
monthlyBudget: 0,
savingsGoal: 0,
notifications: true,
darkMode: false,
currency: 'USD'
};
saveData();
saveSettings();
loadSettings();
loadCategories();
loadTransactions();
updateSummary();
updateChart();
showToast('Data imported successfully');
}
} catch (error) {
alert('Error importing data. The file may be corrupted.');
console.error(error);
}
};
reader.readAsText(file);
// Reset input to allow re-importing the same file
e.target.value = '';
}
function resetData() {
if (confirm('Are you sure you want to reset all data? This cannot be undone.')) {
transactions = [];
settings.monthlyBudget = 0;
settings.savingsGoal = 0;
saveData();
saveSettings();
loadSettings();
loadCategories();
loadTransactions();
updateSummary();
updateChart();
showToast('All data has been reset');
}
}
function saveData() {
localStorage.setItem('transactions', JSON.stringify(transactions));
localStorage.setItem('categories', JSON.stringify(categories));
}
function saveSettings() {
localStorage.setItem('settings', JSON.stringify(settings));
}
function formatDate(dateString) {
const date = new Date(dateString);
return date.toLocaleDateString('en-US', { month: 'short', day: 'numeric' });
}
function showToast(message) {
if (!settings.notifications) return;
const toast = document.createElement('div');
toast.className = 'fixed bottom-20 left-1/2 transform -translate-x-1/2 bg-gray-800 text-white px-4 py-2 rounded-lg text-sm animate-slide-up';
toast.textContent = message;
document.body.appendChild(toast);
setTimeout(() => {
toast.classList.remove('animate-slide-up');
toast.classList.add('animate-slide-down');
setTimeout(() => {
toast.remove();
}, 300);
}, 3000);
}
function initChart() {
const ctx = document.getElementById('spending-chart').getContext('2d');
spendingChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
datasets: [{
label: 'Expenses',
data: [65, 59, 80, 81, 56, 55, 40],
backgroundColor: '#007AFF',
borderRadius: 6,
borderSkipped: false,
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
display: false
},
tooltip: {
backgroundColor: '#1C1C1E',
titleFont: {
family: 'SF Pro Display'
},
bodyFont: {
family: 'SF Pro Display'
},
cornerRadius: 8,
displayColors: false
}
},
scales: {
x: {
grid: {
display: false,
drawBorder: false
},
ticks: {
font: {
family: 'SF Pro Display'
}
}
},
y: {
grid: {
color: '#E5E5EA',
drawBorder: false
},
ticks: {
font: {
family: 'SF Pro Display'
},
callback: function(value) {
return '$' + value;
}
}
}
}
}
});
}
function updateChart() {
// In a real app, we would calculate actual weekly data
const period = document.getElementById('chart-period').value;
let labels, data;
if (period === 'week') {
labels = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
data = [65, 59, 80, 81, 56, 55, 40];
} else if (period === 'month') {
labels = ['Week 1', 'Week 2', 'Week 3', 'Week 4'];
data = [300, 450, 280, 320];
} else { // year
labels = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
data = [1200, 1100, 900, 1000, 800, 950, 1100, 1050, 1150, 1200, 1300, 1400];
}
spendingChart.data.labels = labels;
spendingChart.data.datasets[0].data = data;
spendingChart.update();
}
// Add hidden file input for import
const importFileInput = document.createElement('input');
importFileInput.type = 'file';
importFileInput.id = 'import-file';
importFileInput.accept = '.json';
importFileInput.style.display = 'none';
importFileInput.addEventListener('change', importData);
document.body.appendChild(importFileInput);
// Update chart when period changes
document.getElementById('chart-period').addEventListener('change', updateChart);
</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=atlkaran635/codes" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Expenses 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: {
primary: '#007AFF',
secondary: '#34C759',
danger: '#FF3B30',
warning: '#FF9500',
dark: '#1C1C1E',
light: '#F2F2F7',
gray: {
100: '#F2F2F7',
200: '#E5E5EA',
300: '#D1D1D6',
400: '#C7C7CC',
500: '#AEAEB2',
600: '#8E8E93',
700: '#636366',
800: '#48484A',
900: '#3A3A3C'
}
},
animation: {
'fade-in': 'fadeIn 0.3s ease-out forwards',
'slide-up': 'slideUp 0.5s cubic-bezier(0.23, 1, 0.32, 1) forwards',
'slide-down': 'slideDown 0.5s cubic-bezier(0.23, 1, 0.32, 1) forwards',
'scale-in': 'scaleIn 0.3s cubic-bezier(0.23, 1, 0.32, 1) forwards',
'scale-out': 'scaleOut 0.3s cubic-bezier(0.23, 1, 0.32, 1) forwards',
'pulse-slow': 'pulse 3s cubic-bezier(0.4, 0, 0.6, 1) infinite'
},
keyframes: {
fadeIn: {
'0%': { opacity: '0' },
'100%': { opacity: '1' }
},
slideUp: {
'0%': { transform: 'translateY(50px)', opacity: '0' },
'100%': { transform: 'translateY(0)', opacity: '1' }
},
slideDown: {
'0%': { transform: 'translateY(-50px)', opacity: '0' },
'100%': { transform: 'translateY(0)', opacity: '1' }
},
scaleIn: {
'0%': { transform: 'scale(0.95)', opacity: '0' },
'100%': { transform: 'scale(1)', opacity: '1' }
},
scaleOut: {
'0%': { transform: 'scale(1)', opacity: '1' },
'100%': { transform: 'scale(0.95)', opacity: '0' }
}
}
}
}
}
</script>
<style>
@import url('https://fonts.googleapis.com/css2?family=SF+Pro+Display:wght@300;400;500;600;700&display=swap');
body {
font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, sans-serif;
background-color: #F2F2F7;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
/* iOS-like scrollbar */
::-webkit-scrollbar {
width: 6px;
height: 6px;
}
::-webkit-scrollbar-thumb {
background-color: rgba(0, 0, 0, 0.2);
border-radius: 3px;
}
::-webkit-scrollbar-track {
background-color: transparent;
}
.card {
border-radius: 14px;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
}
.transaction-item {
transition: transform 0.3s cubic-bezier(0.23, 1, 0.32, 1);
}
.transaction-item:hover {