-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaman.html
323 lines (276 loc) · 10.3 KB
/
aman.html
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Enter Amount and Category</title>
<style>
/* Global Reset */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-image: url('bg2.jpg');
background-size: cover;
font-family: Arial, sans-serif;
background-color: #fff;
color: #202124;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
text-align: center;
}
.container {
width: 100%;
max-width: 800px; /* Increased width */
padding: 30px; /* Increased padding */
background-color: #f8f9fa;
border-radius: 12px; /* Slightly rounded corners */
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15); /* Enhanced shadow */
}
.google-btn {
background-color: #4285F4;
color: white;
font-size: 18px;
padding: 15px 30px;
border: none;
border-radius: 8px;
cursor: pointer;
transition: background-color 0.3s;
font-weight: bold;
width: 100%;
}
.google-btn:hover {
background-color: #3367D6;
}
.category-section {
margin-top: 30px;
}
.category {
background-color: #34A853;
color: white;
padding: 15px 30px;
border-radius: 20px;
margin: 10px;
cursor: pointer;
font-size: 16px;
display: inline-block;
position: relative;
transition: background-color 0.3s, transform 0.3s ease-in-out, border 0.3s;
}
.category:hover {
background-color: #1D8F42;
transform: scale(1.1);
}
.category.selected-category {
transform: scale(1.2);
border: 3px solid gold;
background-color: #34A853;
}
.category button {
position: absolute;
top: 0;
right: 0;
background-color: #d32f2f;
color: white;
border: none;
border-radius: 50%;
padding: 8px;
cursor: pointer;
font-size: 16px;
width: 30px;
height: 30px;
display: none;
}
.category:hover button {
display: block;
}
.category-form {
display: flex;
justify-content: center;
margin-top: 30px;
}
.amount-section {
margin-top: 30px;
}
.proceed-btn {
background-color: #FBBC05;
color: white;
font-size: 18px;
padding: 15px 30px;
border: none;
border-radius: 8px;
cursor: pointer;
margin-top: 30px;
font-weight: bold;
width: 100%;
opacity: 0.5;
pointer-events: none;
}
.proceed-btn.enabled {
opacity: 1;
pointer-events: auto;
}
.input-category {
margin-top: 20px;
display: inline-block;
width: 100%;
max-width: 300px;
padding: 12px;
border-radius: 8px;
border: 1px solid #ccc;
font-size: 16px;
}
/* Mobile responsiveness */
@media (max-width: 600px) {
.container {
padding: 15px;
}
.google-btn, .proceed-btn {
width: 100%;
}
.category {
font-size: 14px;
padding: 10px 20px;
}
.amount-section input {
font-size: 16px;
}
}
</style>
</head>
<body >
<div class="container">
<h1>Enter the Amount to be Paid</h1>
<!-- Input field for Amount -->
<div class="amount-section">
<input type="number" id="amount" placeholder="Amount in USD" class="input-category" min="0.01" step="any">
</div>
<!-- Categories section -->
<div class="category-section" id="categorySection">
<h2>Select Category</h2>
</div>
<!-- Custom Category input form -->
<div class="category-form">
<input type="text" id="newCategory" class="input-category" placeholder="Add your own category">
</div>
<!-- Hidden Google Pay URL -->
<input type="hidden" id="googlePayUrl" value="https://pay.google.com">
<button class="proceed-btn" id="proceedBtn" onclick="redirectToGooglePay()">Proceed to Payment Screen</button>
</div>
<script>
// Retrieve categories and totals from localStorage or initialize if not present
function getCategories() {
const storedCategories = localStorage.getItem('categories');
return storedCategories ? JSON.parse(storedCategories) : [];
}
function getCategoryTotals() {
const storedTotals = localStorage.getItem('categoryTotals');
return storedTotals ? JSON.parse(storedTotals) : {};
}
// Save categories and totals to localStorage
function saveCategories(categories) {
localStorage.setItem('categories', JSON.stringify(categories));
}
function saveCategoryTotals(totals) {
localStorage.setItem('categoryTotals', JSON.stringify(totals));
}
// Display categories dynamically with their totals
function displayCategories() {
const categoryContainer = document.getElementById('categorySection');
const categories = getCategories();
const totals = getCategoryTotals();
// Remove all current categories (to prevent duplicates)
categoryContainer.querySelectorAll('.category:not(:first-child)').forEach(category => category.remove());
// Add each category to the display
categories.forEach(category => {
const categoryElement = document.createElement('div');
categoryElement.classList.add('category');
categoryElement.textContent = `${category} - $${totals[category] || 0}`;
// Create delete button for each category
const deleteButton = document.createElement('button');
deleteButton.textContent = 'X';
deleteButton.onclick = function () {
deleteCategory(category);
};
categoryElement.appendChild(deleteButton);
categoryElement.onclick = function () {
toggleCategorySelection(categoryElement);
};
categoryContainer.appendChild(categoryElement);
});
}
// Toggle the selected category (change color, scale, and add border)
function toggleCategorySelection(categoryElement) {
const categories = document.querySelectorAll('.category');
categories.forEach(category => category.classList.remove('selected-category')); // Remove selected from all
categoryElement.classList.add('selected-category'); // Add selected class to the clicked category
checkCategorySelection(); // Check if a category is selected
}
// Add a new custom category
document.getElementById('newCategory').addEventListener('keydown', function(event) {
if (event.key === 'Enter') {
const newCategory = event.target.value.trim();
if (newCategory) {
const categories = getCategories();
categories.push(newCategory); // Add the new category
saveCategories(categories); // Save to localStorage
event.target.value = ''; // Clear the input field
displayCategories(); // Reload the displayed categories
checkCategorySelection(); // Check if a category is selected
}
}
});
// Delete a category
function deleteCategory(categoryToDelete) {
const categories = getCategories();
const updatedCategories = categories.filter(category => category !== categoryToDelete); // Remove category
const totals = getCategoryTotals();
delete totals[categoryToDelete]; // Remove category total
saveCategories(updatedCategories); // Save updated categories to localStorage
saveCategoryTotals(totals); // Save updated totals to localStorage
displayCategories(); // Reload the displayed categories
checkCategorySelection(); // Check if a category is selected
}
// Redirect to Google Pay when Proceed button is clicked
function redirectToGooglePay() {
const amount = document.getElementById('amount').value;
const selectedCategory = document.querySelector('.category.selected-category');
// Check if amount is valid before proceeding
if (!amount || amount <= 0) {
alert('Please enter a valid amount.');
return; // Do nothing if the amount is invalid
}
// Update the total spent for the selected category
const category = selectedCategory.textContent.split(' - ')[0];
const totals = getCategoryTotals();
totals[category] = (totals[category] || 0) + parseFloat(amount);
saveCategoryTotals(totals); // Save the updated totals
// Show the confirmation dialog
const userConfirmed = confirm(`Proceed with a payment of $${amount} for ${category}?`);
if (userConfirmed) {
const googlePayUrl = document.getElementById('googlePayUrl').value;
window.location.href = googlePayUrl; // Redirect to Google Pay
}
}
// Ensure the category is selected before enabling the proceed button
function checkCategorySelection() {
const proceedBtn = document.getElementById('proceedBtn');
const selectedCategory = document.querySelector('.category.selected-category');
if (selectedCategory) {
proceedBtn.classList.add('enabled');
} else {
proceedBtn.classList.remove('enabled');
}
}
// Initialize category selection state and display categories on page load
document.addEventListener('DOMContentLoaded', function() {
displayCategories();
checkCategorySelection(); // Ensure button starts in correct state
});
</script>
</body>
</html>