Spaces:
Running
Running
Download index.html from JJ-life/DailyExpenseManager: direct link, hf CLI and curl.
- Browser
- Download file 18.9 kB
-
https://huggingface.co/spaces/JJ-life/DailyExpenseManager/resolve/main/index.html
- Command line
-
hf download hf://spaces/JJ-life/DailyExpenseManager/index.html
-
curl -L -o index.html https://huggingface.co/spaces/JJ-life/DailyExpenseManager/resolve/main/index.html
18.9 kB
<!DOCTYPE html>
<html lang="zh-Hant">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Daily Expense Manager 每日記帳助手</title>
<style>
:root { color-scheme: light; --ink:#173b3a; --muted:#647877; --brand:#16877b; --brand-dark:#106b62; --accent:#e7a94b; --surface:#fffefa; --line:#e4ebe6; --canvas:#f3f7f3; }
* { box-sizing:border-box; margin:0; padding:0; font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", Arial, sans-serif; }
body { background:var(--canvas); color:var(--ink); padding:28px 20px; line-height:1.6; }
.container { max-width:1100px; margin:auto; }
header { background:linear-gradient(135deg,#146e67,#26988a); color:white; padding:32px 24px; border-radius:20px; text-align:center; margin-bottom:22px; box-shadow:0 12px 30px #146e6724; }
header p { color:#e0f3ed; margin-top:4px; }
header h1 { margin-bottom:5px; font-size:clamp(25px,4vw,34px); }
.form-box,.budget-box,.history-box,.insight-box,.card { background:var(--surface); padding:22px; border:1px solid var(--line); border-radius:16px; margin-bottom:20px; box-shadow:0 5px 18px #254d3a0b; }
h2 { margin-bottom:16px; color:var(--brand-dark); font-size:21px; }
.form-grid { display:grid; grid-template-columns:repeat(2,1fr); gap:16px; }
label { font-weight:650; display:block; margin-bottom:6px; }
input,select { width:100%; padding:12px 13px; border:1px solid #d5dfd9; border-radius:10px; background:#fff; color:var(--ink); font-size:15px; }
input:focus,select:focus { outline:3px solid #16877b25; border-color:var(--brand); }
.full { grid-column:1/-1; }
button { background:var(--brand); color:white; border:0; padding:12px 20px; border-radius:10px; cursor:pointer; font-size:15px; font-weight:700; transition:background .18s,transform .18s; }
button:hover { background:var(--brand-dark); transform:translateY(-1px); }
.dashboard { display:grid; grid-template-columns:repeat(4,1fr); gap:14px; margin-bottom:20px; }
.card { text-align:center; margin:0; padding:20px 14px; }
.card h3 { font-size:15px; color:var(--muted); margin-bottom:9px; }
.amount { font-size:24px; font-weight:750; color:var(--brand-dark); }
.budget-row { display:flex; gap:10px; }
.budget-row input { flex:1; }
.budget-info { margin-top:15px; line-height:1.9; }
.budget-info p { margin:0; color:var(--muted); }
.table-container { overflow-x:auto; }
table { width:100%; border-collapse:collapse; min-width:750px; }
th,td { padding:12px; border-bottom:1px solid var(--line); text-align:left; }
th { background:#eef6f1; color:#315952; }
tbody tr:hover { background:#f8fbf8; }
.delete-btn { background:#bd4b43; padding:7px 12px; font-size:13px; }
.delete-btn:hover { background:#a83c35; }
.empty { text-align:center; padding:20px; color:var(--muted); }
.insight { background:#eff7f1; border-left:4px solid var(--accent); padding:16px; border-radius:10px; line-height:1.8; }
.search-box { margin-bottom:15px; }
footer { text-align:center; margin-top:26px; color:var(--muted); font-size:14px; }
@media(max-width:800px) { .dashboard { grid-template-columns:repeat(2,1fr); } .form-grid { grid-template-columns:1fr; } .full { grid-column:auto; } }
@media(max-width:500px) { body { padding:12px; } .dashboard { grid-template-columns:1fr 1fr; gap:10px; } .budget-row { flex-direction:column; } header { padding:26px 16px; } .card { padding:16px 8px; } .amount { font-size:20px; } }
</style>
</head>
<body>
<div class="container">
<header>
<h1>💰 每日記帳助手</h1>
<p>輕鬆記錄每日支出,掌握每一筆花費。</p>
</header>
<!-- DASHBOARD -->
<div class="dashboard">
<div class="card">
<h3>💵 今日支出</h3>
<div class="amount" id="todayAmount">NT$ 0</div>
</div>
<div class="card">
<h3>📅 本週支出</h3>
<div class="amount" id="weekAmount">NT$ 0</div>
</div>
<div class="card">
<h3>🗓️ 本月支出</h3>
<div class="amount" id="monthAmount">NT$ 0</div>
</div>
<div class="card">
<h3>💰 累計支出</h3>
<div class="amount" id="totalAmount">NT$ 0</div>
</div>
</div>
<!-- ADD EXPENSE -->
<div class="form-box">
<h2>➕ 新增支出</h2>
<div class="form-grid">
<div>
<label>日期</label>
<input type="date" id="date">
</div>
<div>
<label>支出項目</label>
<input
type="text"
id="expenseName"
placeholder="例如:日常採買">
</div>
<div>
<label>金額(NT$)</label>
<input
type="number"
id="amount"
placeholder="例如:850"
min="1">
</div>
<div>
<label>類別</label>
<select id="category">
<option value="">請選擇類別</option>
<option>🍔 餐飲</option>
<option>🛒 購物</option>
<option>🚗 交通</option>
<option>🏠 居家</option>
<option>💊 醫療</option>
<option>🎬 娛樂</option>
<option>📱 帳單</option>
<option>📦 其他</option>
</select>
</div>
<div>
<label>付款方式</label>
<select id="payment">
<option value="">請選擇付款方式</option>
<option>行動支付</option>
<option>現金</option>
<option>金融卡</option>
<option>信用卡</option>
<option>網路銀行</option>
</select>
</div>
<div>
<label>備註</label>
<input
type="text"
id="description"
placeholder="例如:每月採買">
</div>
<div class="full">
<button onclick="addExpense()">
➕ 新增支出
</button>
</div>
</div>
</div>
<!-- BUDGET -->
<div class="budget-box">
<h2>💰 每月預算</h2>
<div class="budget-row">
<input
type="number"
id="budget"
placeholder="輸入每月預算(NT$)"
min="1">
<button onclick="saveBudget()">
儲存預算
</button>
</div>
<div class="budget-info">
<p>
預算:
<strong id="budgetDisplay">NT$ 0</strong>
</p>
<p>
已支出:
<strong id="budgetSpent">NT$ 0</strong>
</p>
<p>
剩餘:
<strong id="remaining">NT$ 0</strong>
</p>
</div>
</div>
<!-- HISTORY -->
<div class="history-box">
<h2>📋 支出紀錄</h2>
<div class="search-box">
<input
type="text"
id="search"
placeholder="🔍 搜尋項目、類別或付款方式…"
oninput="displayExpenses()">
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>日期</th>
<th>項目</th>
<th>金額</th>
<th>類別</th>
<th>付款方式</th>
<th>備註</th>
<th>操作</th>
</tr>
</thead>
<tbody id="expenseTable"></tbody>
</table>
</div>
<div id="emptyMessage" class="empty">
目前還沒有支出紀錄。
</div>
</div>
<!-- INSIGHTS -->
<div class="insight-box">
<h2>🤖 消費分析</h2>
<div class="insight" id="insight">
新增支出後,即可查看消費分析。
</div>
</div>
<footer>
© 2026 每日記帳助手
</footer>
</div>
<script>
/* =========================
LOAD SAVED DATA
========================= */
let expenses =
JSON.parse(localStorage.getItem("expenses")) || [];
let monthlyBudget =
Number(localStorage.getItem("monthlyBudget")) || 0;
/* =========================
LOCAL DATE
========================= */
function getLocalDate() {
const today = new Date();
const year = today.getFullYear();
const month =
String(today.getMonth() + 1).padStart(2, "0");
const day =
String(today.getDate()).padStart(2, "0");
return `${year}-${month}-${day}`;
}
/* Set today's date */
document.getElementById("date").value =
getLocalDate();
/* =========================
MONEY FORMAT
========================= */
function money(value) {
return "NT$ " +
Number(value).toLocaleString("zh-TW");
}
/* =========================
ADD EXPENSE
========================= */
function addExpense() {
const date =
document.getElementById("date").value;
const name =
document.getElementById("expenseName")
.value
.trim();
const amount =
Number(
document.getElementById("amount").value
);
const category =
document.getElementById("category").value;
const payment =
document.getElementById("payment").value;
const description =
document.getElementById("description")
.value
.trim();
/* Check required fields */
if (
!date ||
!name ||
amount <= 0 ||
!category ||
!payment
) {
alert("請填寫所有必填欄位。");
return;
}
/* Create expense */
const expense = {
id: Date.now(),
date: date,
name: name,
amount: amount,
category: category,
payment: payment,
description: description
};
/* Add to existing expenses */
expenses.push(expense);
/* Save ALL expenses */
localStorage.setItem(
"expenses",
JSON.stringify(expenses)
);
/* Clear fields */
document.getElementById("expenseName")
.value = "";
document.getElementById("amount")
.value = "";
document.getElementById("category")
.value = "";
document.getElementById("payment")
.value = "";
document.getElementById("description")
.value = "";
/* Update everything */
updateApp();
alert("支出已新增!✅");
}
/* =========================
DELETE EXPENSE
========================= */
function deleteExpense(id) {
if (
confirm(
"確定要刪除這筆支出嗎?"
)
) {
expenses =
expenses.filter(
expense => expense.id !== id
);
localStorage.setItem(
"expenses",
JSON.stringify(expenses)
);
updateApp();
}
}
/* =========================
SAVE MONTHLY BUDGET
========================= */
function saveBudget() {
const value =
Number(
document.getElementById("budget").value
);
if (value <= 0) {
alert("請輸入有效的每月預算。");
return;
}
monthlyBudget = value;
localStorage.setItem(
"monthlyBudget",
monthlyBudget
);
document.getElementById("budget")
.value = "";
updateApp();
alert("每月預算已儲存!✅");
}
/* =========================
CHECK CURRENT MONTH
========================= */
function sameMonth(dateString) {
const parts =
dateString.split("-");
const year =
Number(parts[0]);
const month =
Number(parts[1]);
const today =
new Date();
return (
year === today.getFullYear() &&
month === today.getMonth() + 1
);
}
/* =========================
CHECK CURRENT WEEK
Monday - Sunday
========================= */
function sameWeek(dateString) {
const parts =
dateString.split("-");
const expenseDate =
new Date(
Number(parts[0]),
Number(parts[1]) - 1,
Number(parts[2])
);
const today =
new Date();
today.setHours(0, 0, 0, 0);
expenseDate.setHours(0, 0, 0, 0);
/* Find Monday */
const day =
today.getDay();
const difference =
day === 0 ? 6 : day - 1;
const weekStart =
new Date(today);
weekStart.setDate(
today.getDate() - difference
);
weekStart.setHours(0, 0, 0, 0);
/* Find Sunday */
const weekEnd =
new Date(weekStart);
weekEnd.setDate(
weekStart.getDate() + 6
);
weekEnd.setHours(
23, 59, 59, 999
);
return (
expenseDate >= weekStart &&
expenseDate <= weekEnd
);
}
/* =========================
UPDATE DASHBOARD
========================= */
function updateDashboard() {
const today =
getLocalDate();
/* TODAY */
const todayTotal =
expenses
.filter(
expense =>
expense.date === today
)
.reduce(
(total, expense) =>
total + Number(expense.amount),
0
);
/* THIS WEEK */
const weekTotal =
expenses
.filter(
expense =>
sameWeek(expense.date)
)
.reduce(
(total, expense) =>
total + Number(expense.amount),
0
);
/* THIS MONTH */
const monthTotal =
expenses
.filter(
expense =>
sameMonth(expense.date)
)
.reduce(
(total, expense) =>
total + Number(expense.amount),
0
);
/* ALL EXPENSES */
const total =
expenses
.reduce(
(sum, expense) =>
sum + Number(expense.amount),
0
);
/* Show dashboard */
document.getElementById("todayAmount")
.textContent =
money(todayTotal);
document.getElementById("weekAmount")
.textContent =
money(weekTotal);
document.getElementById("monthAmount")
.textContent =
money(monthTotal);
document.getElementById("totalAmount")
.textContent =
money(total);
/* =====================
BUDGET
===================== */
/*
IMPORTANT:
All current-month expenses
are included in budget.
*/
const spent =
monthTotal;
const remaining =
monthlyBudget - spent;
document.getElementById("budgetDisplay")
.textContent =
money(monthlyBudget);
document.getElementById("budgetSpent")
.textContent =
money(spent);
document.getElementById("remaining")
.textContent =
money(remaining);
}
/* =========================
EXPENSE HISTORY
========================= */
function displayExpenses() {
const table =
document.getElementById("expenseTable");
const search =
document.getElementById("search")
.value
.toLowerCase()
.trim();
table.innerHTML = "";
const filtered =
expenses.filter(expense =>
expense.name
.toLowerCase()
.includes(search)
||
expense.category
.toLowerCase()
.includes(search)
||
expense.payment
.toLowerCase()
.includes(search)
||
expense.date
.includes(search)
);
document.getElementById("emptyMessage")
.style.display =
filtered.length === 0
? "block"
: "none";
/* Newest first */
filtered
.slice()
.reverse()
.forEach(expense => {
const row =
document.createElement("tr");
row.innerHTML = `
<td>
${expense.date}
</td>
<td>
${expense.name}
</td>
<td>
${money(expense.amount)}
</td>
<td>
${expense.category}
</td>
<td>
${expense.payment}
</td>
<td>
${expense.description || "-"}
</td>
<td>
<button
class="delete-btn"
onclick="deleteExpense(${expense.id})">
刪除
</button>
</td>
`;
table.appendChild(row);
});
}
/* =========================
SPENDING INSIGHTS
========================= */
function updateInsights() {
const insight =
document.getElementById("insight");
const monthExpenses =
expenses.filter(
expense =>
sameMonth(expense.date)
);
if (monthExpenses.length === 0) {
insight.innerHTML =
"本月新增支出後,即可查看消費分析。";
return;
}
/* 類別支出 */
const categories = {};
monthExpenses.forEach(expense => {
if (
!categories[expense.category]
) {
categories[expense.category] = 0;
}
categories[expense.category] +=
Number(expense.amount);
});
let highestCategory = "";
let highestAmount = 0;
for (
const category in categories
) {
if (
categories[category] >
highestAmount
) {
highestAmount =
categories[category];
highestCategory =
category;
}
}
const monthTotal =
monthExpenses.reduce(
(sum, expense) =>
sum + Number(expense.amount),
0
);
let message = `
💡 本月支出最多的類別是
<strong>
${highestCategory}
</strong>
,金額為:
<strong>
${money(highestAmount)}
</strong>
<br><br>
📊 本月總支出為
<strong>
${money(monthTotal)}
</strong>。
`;
/* Budget message */
if (monthlyBudget > 0) {
const remaining =
monthlyBudget - monthTotal;
if (remaining >= 0) {
message += `
<br><br>
✅ 每月預算尚餘
<strong>
${money(remaining)}
</strong>
。
`;
} else {
message += `
<br><br>
⚠️ 本月支出已超出預算
<strong>
${money(Math.abs(remaining))}
</strong>。
`;
}
}
insight.innerHTML = message;
}
/* =========================
UPDATE ENTIRE APP
========================= */
function updateApp() {
updateDashboard();
displayExpenses();
updateInsights();
}
/* =========================
START APP
========================= */
updateApp();
</script>
</body>
</html>
<html lang="zh-Hant">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Daily Expense Manager 每日記帳助手</title>
<style>
:root { color-scheme: light; --ink:#173b3a; --muted:#647877; --brand:#16877b; --brand-dark:#106b62; --accent:#e7a94b; --surface:#fffefa; --line:#e4ebe6; --canvas:#f3f7f3; }
* { box-sizing:border-box; margin:0; padding:0; font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", Arial, sans-serif; }
body { background:var(--canvas); color:var(--ink); padding:28px 20px; line-height:1.6; }
.container { max-width:1100px; margin:auto; }
header { background:linear-gradient(135deg,#146e67,#26988a); color:white; padding:32px 24px; border-radius:20px; text-align:center; margin-bottom:22px; box-shadow:0 12px 30px #146e6724; }
header p { color:#e0f3ed; margin-top:4px; }
header h1 { margin-bottom:5px; font-size:clamp(25px,4vw,34px); }
.form-box,.budget-box,.history-box,.insight-box,.card { background:var(--surface); padding:22px; border:1px solid var(--line); border-radius:16px; margin-bottom:20px; box-shadow:0 5px 18px #254d3a0b; }
h2 { margin-bottom:16px; color:var(--brand-dark); font-size:21px; }
.form-grid { display:grid; grid-template-columns:repeat(2,1fr); gap:16px; }
label { font-weight:650; display:block; margin-bottom:6px; }
input,select { width:100%; padding:12px 13px; border:1px solid #d5dfd9; border-radius:10px; background:#fff; color:var(--ink); font-size:15px; }
input:focus,select:focus { outline:3px solid #16877b25; border-color:var(--brand); }
.full { grid-column:1/-1; }
button { background:var(--brand); color:white; border:0; padding:12px 20px; border-radius:10px; cursor:pointer; font-size:15px; font-weight:700; transition:background .18s,transform .18s; }
button:hover { background:var(--brand-dark); transform:translateY(-1px); }
.dashboard { display:grid; grid-template-columns:repeat(4,1fr); gap:14px; margin-bottom:20px; }
.card { text-align:center; margin:0; padding:20px 14px; }
.card h3 { font-size:15px; color:var(--muted); margin-bottom:9px; }
.amount { font-size:24px; font-weight:750; color:var(--brand-dark); }
.budget-row { display:flex; gap:10px; }
.budget-row input { flex:1; }
.budget-info { margin-top:15px; line-height:1.9; }
.budget-info p { margin:0; color:var(--muted); }
.table-container { overflow-x:auto; }
table { width:100%; border-collapse:collapse; min-width:750px; }
th,td { padding:12px; border-bottom:1px solid var(--line); text-align:left; }
th { background:#eef6f1; color:#315952; }
tbody tr:hover { background:#f8fbf8; }
.delete-btn { background:#bd4b43; padding:7px 12px; font-size:13px; }
.delete-btn:hover { background:#a83c35; }
.empty { text-align:center; padding:20px; color:var(--muted); }
.insight { background:#eff7f1; border-left:4px solid var(--accent); padding:16px; border-radius:10px; line-height:1.8; }
.search-box { margin-bottom:15px; }
footer { text-align:center; margin-top:26px; color:var(--muted); font-size:14px; }
@media(max-width:800px) { .dashboard { grid-template-columns:repeat(2,1fr); } .form-grid { grid-template-columns:1fr; } .full { grid-column:auto; } }
@media(max-width:500px) { body { padding:12px; } .dashboard { grid-template-columns:1fr 1fr; gap:10px; } .budget-row { flex-direction:column; } header { padding:26px 16px; } .card { padding:16px 8px; } .amount { font-size:20px; } }
</style>
</head>
<body>
<div class="container">
<header>
<h1>💰 每日記帳助手</h1>
<p>輕鬆記錄每日支出,掌握每一筆花費。</p>
</header>
<!-- DASHBOARD -->
<div class="dashboard">
<div class="card">
<h3>💵 今日支出</h3>
<div class="amount" id="todayAmount">NT$ 0</div>
</div>
<div class="card">
<h3>📅 本週支出</h3>
<div class="amount" id="weekAmount">NT$ 0</div>
</div>
<div class="card">
<h3>🗓️ 本月支出</h3>
<div class="amount" id="monthAmount">NT$ 0</div>
</div>
<div class="card">
<h3>💰 累計支出</h3>
<div class="amount" id="totalAmount">NT$ 0</div>
</div>
</div>
<!-- ADD EXPENSE -->
<div class="form-box">
<h2>➕ 新增支出</h2>
<div class="form-grid">
<div>
<label>日期</label>
<input type="date" id="date">
</div>
<div>