Download script.js from UltraFastBrother/veggie-ledger-tracker: direct link, hf CLI and curl.
- Browser
- Download file 4.98 kB
-
https://huggingface.co/spaces/UltraFastBrother/veggie-ledger-tracker/resolve/main/script.js
- Command line
-
hf download hf://spaces/UltraFastBrother/veggie-ledger-tracker/script.js
-
curl -L -o script.js https://huggingface.co/spaces/UltraFastBrother/veggie-ledger-tracker/resolve/main/script.js
4.98 kB
| // Sample data - in a real app, this would come from a database | |
| let transactions = [ | |
| { | |
| id: 1, | |
| date: '2023-11-15', | |
| time: '10:30 AM', | |
| description: 'Vegetables for home', | |
| amount: 350, | |
| type: 'expense', | |
| person: 'Mother', | |
| balance: 4650 | |
| }, | |
| { | |
| id: 2, | |
| date: '2023-11-14', | |
| time: '5:45 PM', | |
| description: 'Grocery shopping', | |
| amount: 1200, | |
| type: 'expense', | |
| person: 'Father', | |
| balance: 5000 | |
| }, | |
| { | |
| id: 3, | |
| date: '2023-11-12', | |
| time: '12:15 PM', | |
| description: 'Received money', | |
| amount: 2000, | |
| type: 'income', | |
| person: 'Brother', | |
| balance: 6200 | |
| } | |
| ]; | |
| let familyMembers = [ | |
| { id: 1, name: 'Anubhav', balance: 0, avatar: 'http://static.photos/people/200x200/1' }, | |
| { id: 2, name: 'Anidhya', balance: 0, avatar: 'http://static.photos/people/200x200/2' }, | |
| { id: 3, name: 'Mumma', balance: 0, avatar: 'http://static.photos/people/200x200/3' }, | |
| { id: 4, name: 'Papa Ji', balance: 0, avatar: 'http://static.photos/people/200x200/4' } | |
| ]; | |
| // Calculate current balance | |
| function calculateBalance() { | |
| return transactions.reduce((total, transaction) => { | |
| return transaction.type === 'income' ? total + transaction.amount : total - transaction.amount; | |
| }, 0); | |
| } | |
| // Load initial data | |
| function loadInitialData() { | |
| setupDarkMode(); | |
| // Update balance | |
| const balance = calculateBalance(); | |
| document.getElementById('current-balance').textContent = `₹${balance.toFixed(2)}`; | |
| // Load recent transactions (last 3) | |
| const recentTransactions = transactions.slice(0, 3); | |
| const transactionsContainer = document.getElementById('recent-transactions'); | |
| recentTransactions.forEach(transaction => { | |
| const transactionEl = document.createElement('div'); | |
| transactionEl.className = 'transaction-card bg-gray-50 p-4 rounded-md'; | |
| transactionEl.innerHTML = ` | |
| <div class="flex justify-between items-center"> | |
| <div> | |
| <p class="font-medium">${transaction.description}</p> | |
| <p class="text-sm text-gray-500">${transaction.person} • ${transaction.date} ${transaction.time}</p> | |
| </div> | |
| <p class="font-semibold ${transaction.type === 'income' ? 'text-primary' : 'text-red-500'}"> | |
| ${transaction.type === 'income' ? '+' : '-'}₹${transaction.amount.toFixed(2)} | |
| </p> | |
| </div> | |
| `; | |
| transactionsContainer.appendChild(transactionEl); | |
| }); | |
| // Load family members | |
| const familyContainer = document.getElementById('family-members'); | |
| familyMembers.forEach(member => { | |
| const memberEl = document.createElement('div'); | |
| memberEl.className = 'family-member-card bg-gray-50 p-4 rounded-md text-center'; | |
| memberEl.innerHTML = ` | |
| <img src="${member.avatar}" alt="${member.name}" class="w-12 h-12 rounded-full mx-auto mb-2"> | |
| <p class="font-medium">${member.name}</p> | |
| <p class="text-sm ${member.balance > 0 ? 'text-primary' : member.balance < 0 ? 'text-red-500' : 'text-gray-500'}"> | |
| ${member.balance > 0 ? 'You owe' : member.balance < 0 ? 'Owes you' : 'Settled'} ${member.balance !== 0 ? '₹' + Math.abs(member.balance).toFixed(2) : ''} | |
| </p> | |
| `; | |
| familyContainer.appendChild(memberEl); | |
| }); | |
| } | |
| // Dark mode toggle | |
| function setupDarkMode() { | |
| const themeToggle = document.getElementById('theme-toggle'); | |
| const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches; | |
| const currentTheme = localStorage.getItem('theme') || (prefersDark ? 'dark' : 'light'); | |
| if (currentTheme === 'dark') { | |
| document.documentElement.setAttribute('data-theme', 'dark'); | |
| themeToggle.innerHTML = '<i data-feather="sun" class="w-5 h-5"></i>'; | |
| } else { | |
| document.documentElement.removeAttribute('data-theme'); | |
| themeToggle.innerHTML = '<i data-feather="moon" class="w-5 h-5"></i>'; | |
| } | |
| feather.replace(); | |
| themeToggle.addEventListener('click', () => { | |
| const currentTheme = document.documentElement.getAttribute('data-theme'); | |
| if (currentTheme === 'dark') { | |
| document.documentElement.removeAttribute('data-theme'); | |
| localStorage.setItem('theme', 'light'); | |
| themeToggle.innerHTML = '<i data-feather="moon" class="w-5 h-5"></i>'; | |
| } else { | |
| document.documentElement.setAttribute('data-theme', 'dark'); | |
| localStorage.setItem('theme', 'dark'); | |
| themeToggle.innerHTML = '<i data-feather="sun" class="w-5 h-5"></i>'; | |
| } | |
| feather.replace(); | |
| }); | |
| } | |
| // Shared functions | |
| function formatDate(dateString) { | |
| const options = { year: 'numeric', month: 'short', day: 'numeric' }; | |
| return new Date(dateString).toLocaleDateString('en-US', options); | |
| } |