-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport.html
More file actions
224 lines (188 loc) · 9.83 KB
/
import.html
File metadata and controls
224 lines (188 loc) · 9.83 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
215
216
217
218
219
220
221
222
223
224
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>FridgeSort Import/Export</title>
<style>
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
background-color: #1E1E2E;
color: #E0E0E0;
font-family: Arial, sans-serif;
padding: 2rem;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
}
h1 {
color: #50FA7B;
font-size: 2.5rem;
margin-bottom: 2rem;
letter-spacing: 1.5px;
}
.container {
background-color: #282a36;
padding: 2rem;
border-radius: 15px;
box-shadow: 0 8px 20px rgba(80, 250, 123, 0.1);
max-width: 500px;
width: 100%;
text-align: center;
}
button, .file-label {
width: 100%;
margin-top: 1rem;
padding: 0.75rem 1rem;
font-size: 1rem;
border: none;
border-radius: 8px;
cursor: pointer;
background-color: #50FA7B;
color: #1E1E2E;
font-weight: bold;
transition: background-color 0.3s ease;
display: inline-block;
text-align: center;
}
button:hover, .file-label:hover {
background-color: #45e06e;
}
input[type="file"] {
display: none;
}
#fileNameDisplay {
margin-top: 0.5rem;
font-size: 0.95rem;
color: #A0FFA0;
}
#status {
margin-top: 1.5rem;
font-size: 1rem;
color: #A0FFA0;
}
</style>
</head>
<body>
<h1>Fridge<span style="color:#fff;">Sort</span> Import/Export</h1>
<div class="container">
<button id="exportBtn">Daten exportieren</button>
<label for="importFile" class="file-label">Datei auswählen</label>
<input type="file" id="importFile" accept=".json"/>
<div id="fileNameDisplay"></div>
<button id="importBtn">Daten importieren</button>
<div id="status"></div>
<button id="addExampleItemsBtn">Beispiele importieren</button>
<button id="addUserStatsBtn">Statistiken importieren</button>
</div>
<script>
document.getElementById('exportBtn').addEventListener('click', () => {
const data = {};
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
data[key] = localStorage.getItem(key);
}
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'fridgesort-data-export.json';
a.click();
URL.revokeObjectURL(url);
});
document.getElementById('importFile').addEventListener('change', (event) => {
const fileNameDisplay = document.getElementById('fileNameDisplay');
const file = event.target.files[0];
if (file) {
fileNameDisplay.textContent = `Ausgewählte Datei: ${file.name}`;
} else {
fileNameDisplay.textContent = '';
}
});
document.getElementById('importBtn').addEventListener('click', () => {
const fileInput = document.getElementById('importFile');
const file = fileInput.files[0];
if (!file) {
alert('Bitte eine JSON-Datei auswählen.');
return;
}
const reader = new FileReader();
reader.onload = function(event) {
try {
const importedData = JSON.parse(event.target.result);
let addedCount = 0;
for (const key in importedData) {
if (!localStorage.getItem(key)) {
localStorage.setItem(key, importedData[key]);
addedCount++;
}
}
document.getElementById('status').innerText = `${addedCount} neue Einträge importiert.`;
} catch (err) {
alert('Fehler beim Importieren der Datei: ' + err.message);
}
};
reader.readAsText(file);
});
document.getElementById('addExampleItemsBtn').addEventListener('click', () => {
const exampleItems = [
{"name":"Eier","description":"Freilandhaltung","current":"2025-07-07","expiry":"2025-07-21","autoShop":true,"uuid":"1a88c012-b7fc-4763-b04c-91f71f38c4a6"},
{"name":"Butter","description":"Süßrahm","current":"2025-07-03","expiry":"2025-08-01","autoShop":false,"uuid":"597f7b57-5c1a-4957-97c1-b8a1d9e6f5cb"},
{"name":"Käse","description":"Gouda jung","current":"2025-07-09","expiry":"2025-07-18","autoShop":false,"uuid":"d324a3ea-9ac0-4ba4-8c92-33099312e09c"},
{"name":"Joghurt","description":"Erdbeer","current":"2025-07-06","expiry":"2025-07-13","autoShop":true,"uuid":"bc86e3e9-d5c6-4ae7-a99f-e8de6a7d1e99"},
{"name":"Äpfel","description":"Bio, rot","current":"2025-07-04","expiry":"2025-07-15","autoShop":false,"uuid":"f3198b0b-707e-45ef-967e-f226b58a3912"},
{"name":"Bananen","description":"Chiquita","current":"2025-07-08","expiry":"2025-07-12","autoShop":true,"uuid":"12cd34f5-343a-43ee-987f-d7d72d9f1ef9"},
{"name":"Kartoffeln","description":"festkochend","current":"2025-07-02","expiry":"2025-08-01","autoShop":false,"uuid":"7de5b8b6-9a89-46dc-988d-cc3b3e2f8d00"},
{"name":"Karotten","description":"Bio","current":"2025-07-01","expiry":"2025-07-14","autoShop":false,"uuid":"b61c4071-3788-4d6f-983b-02aa2f9f6870"},
{"name":"Tomaten","description":"Roma","current":"2025-07-05","expiry":"2025-07-10","autoShop":true,"uuid":"68b8e1be-b4c5-4f53-91e7-e7809271b4ad"},
{"name":"Gurken","description":"Salatgurke","current":"2025-07-06","expiry":"2025-07-11","autoShop":false,"uuid":"9a36d761-7888-4038-bdfc-0380b2c38851"},
{"name":"Paprika","description":"gelb, rot","current":"2025-07-03","expiry":"2025-07-13","autoShop":true,"uuid":"f088de62-4350-4c77-a928-88d9f8b8e63d"},
{"name":"Zwiebeln","description":"gelb","current":"2025-07-02","expiry":"2025-07-30","autoShop":false,"uuid":"735b4168-c0c3-41fd-84e1-5bca8e0f85ae"},
{"name":"Knoblauch","description":"frisch","current":"2025-07-01","expiry":"2025-08-01","autoShop":false,"uuid":"e7f0222c-72b5-4f4d-9c5d-e2ae93ea71a6"},
{"name":"Spinat","description":"tiefgekühlt","current":"2025-06-25","expiry":"2026-01-01","autoShop":true,"uuid":"cc6229a9-8cb3-4dc1-9019-2f491826939f"},
{"name":"Fischstäbchen","description":"Iglo","current":"2025-07-08","expiry":"2026-03-10","autoShop":true,"uuid":"2a6b5f6a-4588-4c92-bf2f-9f1bd5d9ad50"},
{"name":"Hackfleisch","description":"Rind, 500g","current":"2025-07-09","expiry":"2025-07-10","autoShop":false,"uuid":"6a734d60-0fbd-4a69-9ac3-9b0711e3cd0f"},
{"name":"Hähnchenbrust","description":"frisch","current":"2025-07-05","expiry":"2025-07-09","autoShop":true,"uuid":"acfe9cc6-4499-42b5-bb2f-bc2337e6dc68"},
{"name":"Reis","description":"Langkorn","current":"2025-06-15","expiry":"2026-06-30","autoShop":false,"uuid":"f28cfd2f-8aa7-45ff-87aa-4ed4b90a8a0b"},
{"name":"Nudeln","description":"Penne","current":"2025-07-01","expiry":"2027-01-01","autoShop":true,"uuid":"93efb3f4-7e9c-4093-9134-8582ebc7fc76"},
{"name":"Tomatensauce","description":"Basilikum","current":"2025-07-08","expiry":"2026-02-01","autoShop":false,"uuid":"b1f06613-0502-4e2f-b6c6-60431e5a06e4"},
{"name":"Öl","description":"Olivenöl","current":"2025-05-01","expiry":"2027-05-01","autoShop":true,"uuid":"90a2e7e9-cffe-4f7c-b5df-f275ca2a4b38"},
{"name":"Mehl","description":"Weizen, Type 405","current":"2025-06-10","expiry":"2026-06-10","autoShop":false,"uuid":"c3a29588-2b66-4dd6-ae8b-54f5d50d5bd7"},
{"name":"Zucker","description":"weiß","current":"2025-05-15","expiry":"2026-12-31","autoShop":true,"uuid":"cf0b9ab1-0a75-4b69-905b-334c4e79c4c3"},
{"name":"Honig","description":"Blütenhonig","current":"2025-07-01","expiry":"2026-12-01","autoShop":false,"uuid":"38a7a398-cfb3-4ab1-bbfc-6be3052124fd"},
{"name":"Marmelade","description":"Himbeer","current":"2025-06-20","expiry":"2025-12-01","autoShop":true,"uuid":"fa3bc99e-6b27-4c64-b812-15cc3108aa90"},
{"name":"Kaffee","description":"gemahlen","current":"2025-07-03","expiry":"2026-01-01","autoShop":false,"uuid":"061e67ae-2ee1-453c-8607-5b01b9b5dce9"},
{"name":"Tee","description":"Grüntee","current":"2025-07-04","expiry":"2026-04-01","autoShop":false,"uuid":"7f2fe0d7-b6f7-4695-9c52-15ab633f5aa6"},
{"name":"Saft","description":"Orangensaft","current":"2025-07-07","expiry":"2025-07-21","autoShop":true,"uuid":"1d19d2e6-8dd5-4f17-9b3d-61e0dd8984dc"},
{"name":"Wasser","description":"Mineralwasser","current":"2025-07-06","expiry":"2026-07-06","autoShop":true,"uuid":"79223e95-d7e9-4178-a4c5-7337b7bbf775"}
];
let foodList = JSON.parse(localStorage.getItem('foodList') || '[]');
const existingUUIDs = new Set(foodList.map(item => item.uuid));
const newItems = exampleItems.filter(item => !existingUUIDs.has(item.uuid));
foodList = foodList.concat(newItems);
localStorage.setItem('foodList', JSON.stringify(foodList));
document.getElementById('status').innerText = `${newItems.length} neue Items wurden zur foodList hinzugefügt.`;
});
document.getElementById('addUserStatsBtn').addEventListener('click', () => {
const userStatsData = {
progress: 80,
level: 4,
savedItems: 48,
highscore: 30,
streak: 30,
streakSince: "13.7.2025",
highscoreSince: "13.7.2025",
badge: 1
};
localStorage.setItem('userStatsData', JSON.stringify(userStatsData));
document.getElementById('status').innerText = 'userStatsData wurde gespeichert.';
});
</script>
</body>
</html>