-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcard2.html
More file actions
214 lines (189 loc) · 7.72 KB
/
card2.html
File metadata and controls
214 lines (189 loc) · 7.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>Credit Card Todo Reminder</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
padding: 20px;
max-width: 600px;
margin: 0 auto;
}
.month-section {
margin: 20px 0;
}
.card-item {
background: #f5f5f5;
padding: 15px;
margin: 10px 0;
border-radius: 8px;
display: flex;
align-items: center;
}
.card-item.completed {
background: #e0e0e0;
text-decoration: line-through;
color: #666;
}
input, button {
padding: 8px;
margin: 5px 0;
}
button {
background: #007aff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
.export-import {
margin-top: 20px;
}
.checkbox {
margin-right: 10px;
}
</style>
</head>
<body>
<h1>Credit Card Reminders</h1>
<div id="addForm">
<input type="text" id="cardName" placeholder="Card Name">
<input type="number" id="dueDate" placeholder="Due Date (1-31)" min="1" max="31">
<button onclick="addCard()">Add Card</button>
</div>
<div id="cardList"></div>
<div class="export-import">
<button onclick="exportData()">Export Data</button>
<input type="file" id="importFile" accept=".json" onchange="importData(event)">
<label for="importFile">Import Data</label>
</div>
<script>
let cards = JSON.parse(localStorage.getItem('creditCards')) || [];
const months = [
'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'
];
function saveCards() {
localStorage.setItem('creditCards', JSON.stringify(cards));
renderCards();
}
function addCard() {
const name = document.getElementById('cardName').value;
const dueDate = parseInt(document.getElementById('dueDate').value);
if (name && dueDate >= 1 && dueDate <= 31) {
const newCard = {
name,
dueDate,
completions: {} // Store completion status by year-month
};
cards.push(newCard);
saveCards();
document.getElementById('cardName').value = '';
document.getElementById('dueDate').value = '';
}
}
function toggleComplete(cardIndex, yearMonth) {
const card = cards[cardIndex];
if (!card.completions[yearMonth]) {
card.completions[yearMonth] = false;
}
card.completions[yearMonth] = !card.completions[yearMonth];
saveCards();
}
function deleteCard(index) {
cards.splice(index, 1);
saveCards();
}
function getDaysUntilDue(dueDate, month, year) {
const today = new Date();
const targetDate = new Date(year, month, dueDate);
const diffTime = targetDate - today;
return Math.ceil(diffTime / (1000 * 60 * 60 * 24));
}
function renderCards() {
const cardList = document.getElementById('cardList');
cardList.innerHTML = '';
const today = new Date();
const currentYear = today.getFullYear();
// Show current and next 11 months (1 year total)
for (let i = 0; i < 12; i++) {
const month = (today.getMonth() + i) % 12;
const year = currentYear + Math.floor((today.getMonth() + i) / 12);
const yearMonth = `${year}-${month}`;
const monthSection = document.createElement('div');
monthSection.className = 'month-section';
monthSection.innerHTML = `<h2>${months[month]} ${year}</h2>`;
cards.forEach((card, cardIndex) => {
const daysUntilDue = getDaysUntilDue(card.dueDate, month, year);
const isCompleted = card.completions[yearMonth] || false;
const cardDiv = document.createElement('div');
cardDiv.className = `card-item ${isCompleted ? 'completed' : ''}`;
cardDiv.innerHTML = `
<input type="checkbox" class="checkbox"
${isCompleted ? 'checked' : ''}
onchange="toggleComplete(${cardIndex}, '${yearMonth}')">
<div style="flex: 1">
<strong>${card.name}</strong><br>
Due Date: ${card.dueDate}<br>
${daysUntilDue >= 0 ? `Days until due: ${daysUntilDue}` : 'Past Due'}
</div>
${i === 0 ? `<button onclick="deleteCard(${cardIndex})">Delete</button>` : ''}
`;
monthSection.appendChild(cardDiv);
});
cardList.appendChild(monthSection);
}
}
function exportData() {
const dataStr = JSON.stringify(cards);
const dataUri = 'data:application/json;charset=utf-8,'+ encodeURIComponent(dataStr);
const exportFileDefaultName = 'credit_card_reminders.json';
const linkElement = document.createElement('a');
linkElement.setAttribute('href', dataUri);
linkElement.setAttribute('download', exportFileDefaultName);
linkElement.click();
}
function importData(event) {
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
try {
cards = JSON.parse(e.target.result);
saveCards();
} catch (error) {
alert('Error importing data: Invalid file format');
}
};
reader.readAsText(file);
}
}
// Initial render
renderCards();
// Check reminders daily
setInterval(() => {
const today = new Date();
const currentMonth = today.getMonth();
const currentYear = today.getFullYear();
const currentYearMonth = `${currentYear}-${currentMonth}`;
cards.forEach((card, index) => {
const daysUntilDue = getDaysUntilDue(card.dueDate, currentMonth, currentYear);
const isCompleted = card.completions[currentYearMonth] || false;
if (daysUntilDue <= 3 && daysUntilDue >= 0 && !isCompleted) {
if ('Notification' in window && Notification.permission === 'granted') {
new Notification(`${card.name} payment due in ${daysUntilDue} day(s)!`);
}
}
});
renderCards();
}, 24 * 60 * 60 * 1000); // Check every 24 hours
// Request notification permission
if ('Notification' in window && Notification.permission !== 'denied') {
Notification.requestPermission();
}
</script>
</body>
</html>