-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotes.html
More file actions
497 lines (435 loc) Β· 19.3 KB
/
Copy pathnotes.html
File metadata and controls
497 lines (435 loc) Β· 19.3 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
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="./db.js"></script>
<title>ShareHive - Notes</title>
<style>
/* --- Base & Theme (Unchanged) --- */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
background-color: var(--bg-color);
color: var(--text-color);
transition: background-color 0.3s, color 0.3s;
}
:root {
--bg-color: #f9f9f9;
--text-color: #222;
--primary-color: #0077ff;
--sidebar-bg: #ffffff;
--card-bg: #ffffff;
--border-color: #e0e0e0;
--shadow-color: rgba(0,0,0,0.08);
--note-default-bg: #ffffff; /* default note background (light theme) */
}
body.dark {
--bg-color: #1e1e1e;
--text-color: #f0f0f0;
--sidebar-bg: #2c2c2c;
--card-bg: #333333;
--border-color: #444;
--shadow-color: rgba(0,0,0,0.25);
--note-default-bg: #2f2f2f; /* slightly lighter than card-bg so note content is visible */
}
/* --- Navbar & Sidebar (Unchanged) --- */
.navbar { display: flex; justify-content: space-between; align-items: center; padding: 10px 20px; background: var(--primary-color); color: white; }
.navbar h1 { font-size: 20px; }
.toggle-btn { background: white; border: none; color: var(--primary-color); padding: 5px 10px; border-radius: 5px; cursor: pointer; font-weight: bold; }
.container { display: flex; height: calc(100vh - 50px); }
.sidebar { width: 220px; background: var(--sidebar-bg); padding: 20px; overflow-y: auto; border-right: 1px solid var(--border-color); }
.sidebar h2 { font-size: 16px; margin-bottom: 10px; }
.sidebar a { display: block; text-decoration: none; color: var(--text-color); padding: 8px 10px; border-radius: 5px; margin-bottom: 5px; }
.sidebar a:hover { background: var(--primary-color); color: white; }
/* --- Main Content Area (Modernized) --- */
.main { flex: 1; padding: 25px; overflow-y: auto; }
/* "Add Note" Form */
.add-note-container { max-width: 600px; margin: 0 auto 40px; }
.add-note-form {
background: var(--card-bg);
border-radius: 8px;
box-shadow: 0 4px 12px var(--shadow-color);
padding: 15px;
border: 1px solid var(--border-color);
}
.add-note-form input, .add-note-form textarea {
width: 100%;
border: none;
background: transparent;
color: var(--text-color);
font-size: 16px;
outline: none;
resize: none;
}
.add-note-form input { font-weight: bold; margin-bottom: 10px; }
.add-note-form textarea { line-height: 1.5; }
.form-footer { display: none; justify-content: flex-end; margin-top: 15px; }
.form-footer button {
background: var(--primary-color);
color: white;
border: none;
padding: 8px 20px;
border-radius: 5px;
font-weight: bold;
cursor: pointer;
}
.add-note-form.expanded .form-footer { display: flex; }
.add-note-form.expanded #content { display: block; }
#content { display: none; }
/* Search and Headers */
.search-box { max-width: 600px; margin: 0 auto 20px; }
.search-box input { width: 100%; padding: 12px; border-radius: 8px; border: 1px solid var(--border-color); background: var(--card-bg); color: var(--text-color); }
.notes-section-header { text-transform: uppercase; font-size: 12px; color: #888; margin: 30px 0 10px; }
/* Masonry Grid */
.notes-container {
column-count: 4;
column-gap: 15px;
}
@media (max-width: 1200px) { .notes-container { column-count: 3; } }
@media (max-width: 900px) { .notes-container { column-count: 2; } }
@media (max-width: 600px) { .notes-container { column-count: 1; } }
/* Note Card */
.note {
display: inline-block;
width: 100%;
margin-bottom: 15px;
background: var(--note-default-bg);
border-radius: 10px;
box-shadow: 0 2px 8px var(--shadow-color);
border: 1px solid var(--border-color);
overflow: hidden;
transition: box-shadow 0.2s;
}
.note:hover { box-shadow: 0 4px 15px var(--shadow-color); }
.note-content { padding: 15px; }
.note h3 { margin-bottom: 10px; font-size: 16px; }
.note p { white-space: pre-wrap; word-wrap: break-word; line-height: 1.5; }
.note-footer { display: flex; justify-content: space-between; align-items: center; padding: 10px 15px; opacity: 0; transition: opacity 0.2s; }
.note:hover .note-footer { opacity: 1; }
.note-footer .timestamp { font-size: 11px; color: #888; }
.note-footer .actions button { background: none; border: none; cursor: pointer; font-size: 18px; padding: 5px; color: #888; }
/* Note Colors */
.note[data-color="red"] { background-color: #f28b82; border-color: #f28b82; }
.note[data-color="blue"] { background-color: #aecbfa; border-color: #aecbfa; }
.note[data-color="green"] { background-color: #ccff90; border-color: #ccff90; }
.note[data-color="yellow"] { background-color: #fff475; border-color: #fff475; }
.note[data-color="gray"] { background-color: #e8eaed; border-color: #e8eaed; }
/* use theme text color so colored notes remain readable in dark/light themes */
.note[data-color] h3, .note[data-color] p, .note[data-color] .timestamp, .note[data-color] .actions button { color: var(--text-color); }
/* Modal for Editing */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); z-index: 1000; display: none; justify-content: center; align-items: center; }
.modal-content {
width: 90%; max-width: 700px;
max-height: 80vh;
display: flex; flex-direction: column;
}
.modal-content .note { width: 100%; margin: 0; }
.modal-content .note-footer { opacity: 1; }
.modal-content .edit-area { padding: 15px; flex-grow: 1; }
.modal-content input, .modal-content textarea { width: 100%; border: none; background: transparent; color: var(--text-color); font-size: 16px; outline: none; resize: none; }
.modal-content input { font-size: 20px; font-weight: bold; margin-bottom: 15px; }
.modal-content textarea { height: 100%; line-height: 1.5; }
/* Animation */
@keyframes scaleIn { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }
.note { animation: scaleIn 0.3s ease-out; }
</style>
</head>
<body>
<!-- Navbar -->
<div class="navbar">
<h1>π ShareHive - Notes</h1>
<button class="toggle-btn" onclick="toggleTheme()">π</button>
</div>
<div class="container">
<!-- Sidebar -->
<div class="sidebar">
<!-- Sidebar content remains the same -->
<h2>Menu</h2>
<a href="index.html">π Dashboard</a>
<a href="notes.html"><b>π Notes</b></a>
<a href="bookmarks.html">π Bookmarks</a>
<a href="videos.html">π¬ Video Links</a>
<a href="expense.html">π° Expense Tracker</a>
<a href="planner.html">π
Planner</a>
<a href="uploads.html">π Upload Files</a>
<a href="projects.html">π Projects</a>
<a href="watchlist.html">π₯ Watchlist</a>
<a href="courses.html">π Courses</a>
<a href="profile.html">π€ Profile</a>
<a href="settings.html">βοΈ Settings</a>
<hr>
<a href="about.html">βΉοΈ About</a>
<a href="help.html">β Help</a>
<a href="faq.html">β FAQ</a>
<a href="blog.html">π° Blog</a>
<a href="contact.html">βοΈ Contact</a>
<a href="join.html">π€ Join Us</a>
<a href="report.html">π Report</a>
<a href="privacy.html">π Privacy & Policy</a>
<a href="community.html">π Community</a>
</div>
<!-- Main -->
<div class="main">
<div class="add-note-container" id="addNoteContainer">
<div class="add-note-form" id="addNoteForm">
<input id="title" type="text" placeholder="Take a note...">
<textarea id="content" rows="4" placeholder="Note content..."></textarea>
<div class="form-footer">
<button id="saveBtn">Save</button>
</div>
</div>
</div>
<div class="search-box">
<input id="search" type="text" placeholder="Search notes...">
</div>
<div id="pinned-section" style="display: none;">
<div class="notes-section-header">Pinned</div>
<div class="notes-container" id="pinned-notes-container"></div>
</div>
<div id="others-section" style="display: none;">
<div class="notes-section-header">Others</div>
<div class="notes-container" id="notes-container"></div>
</div>
</div>
</div>
<!-- Edit Note Modal -->
<div class="modal-overlay" id="editModal">
<div class="modal-content">
<div class="note" id="modalNoteCard">
<div class="edit-area">
<input id="modalTitle" type="text">
<textarea id="modalContent"></textarea>
</div>
<div class="note-footer">
<span class="timestamp" id="modalTimestamp"></span>
<div class="actions" id="modalActions"></div>
</div>
</div>
</div>
</div>
<!-- β
Updated to IndexedDB v22 -->
<script>
// π Dark Mode (unchanged)
const toggleBtn = document.querySelector('.toggle-btn');
function toggleTheme() {
document.body.classList.toggle("dark");
const isDark = document.body.classList.contains("dark");
localStorage.setItem("theme", isDark ? "dark" : "light");
toggleBtn.textContent = isDark ? 'βοΈ' : 'π';
}
if (localStorage.getItem("theme") === "dark") {
document.body.classList.add("dark");
toggleBtn.textContent = 'βοΈ';
}
// π¦ IndexedDB (v22 unified)
let db;
const stores = ["notes","bookmarks","videos","todos","expenses","planner","wiki","uploads","projects","watchlist","courses","profile","community"];
const request = indexedDB.open("ShareHiveDB", 22); // π₯ version bumped to v22
request.onupgradeneeded = e => {
db = e.target.result;
// ensure all stores exist
stores.forEach(storeName => {
if (!db.objectStoreNames.contains(storeName)) {
db.createObjectStore(storeName, { keyPath: "id", autoIncrement: true });
}
});
};
request.onsuccess = e => { db = e.target.result; displayNotes(); };
request.onerror = e => console.error("DB error:", e.target.error);
// (Everything else below unchanged)
// --- Main Form Logic ---
const addNoteForm = document.getElementById('addNoteForm');
const titleInput = document.getElementById('title');
const contentInput = document.getElementById('content');
addNoteForm.addEventListener('click', () => addNoteForm.classList.add('expanded'));
document.addEventListener('click', (e) => {
if (!addNoteForm.contains(e.target)) {
if (addNoteForm.classList.contains('expanded')) {
saveNewNote();
}
}
});
document.getElementById('saveBtn').onclick = saveNewNote;
function saveNewNote() {
const title = titleInput.value.trim();
const content = contentInput.value.trim();
if (title || content) {
const now = new Date().toISOString();
const note = { title, content, pinned: false, color: 'default', createdAt: now, updatedAt: now };
const tx = db.transaction("notes", "readwrite");
tx.objectStore("notes").add(note);
tx.oncomplete = () => {
titleInput.value = "";
contentInput.value = "";
displayNotes();
};
}
addNoteForm.classList.remove('expanded');
}
// --- Display & Filtering ---
async function displayNotes() {
const tx = db.transaction("notes", "readonly");
const allNotes = await new Promise(res => tx.objectStore("notes").getAll().onsuccess = e => res(e.target.result));
const searchTerm = document.getElementById('search').value.toLowerCase();
const filteredNotes = searchTerm
? allNotes.filter(n => (n.title.toLowerCase().includes(searchTerm) || n.content.toLowerCase().includes(searchTerm)))
: allNotes;
const pinned = filteredNotes.filter(n => n.pinned).sort((a,b) => new Date(b.updatedAt) - new Date(a.updatedAt));
const others = filteredNotes.filter(n => !n.pinned).sort((a,b) => new Date(b.updatedAt) - new Date(a.updatedAt));
renderNotes('pinned-notes-container', pinned);
renderNotes('notes-container', others);
document.getElementById('pinned-section').style.display = pinned.length > 0 ? 'block' : 'none';
document.getElementById('others-section').style.display = others.length > 0 ? 'block' : 'none';
}
function renderNotes(containerId, notes) {
const container = document.getElementById(containerId);
container.innerHTML = "";
notes.forEach(note => container.appendChild(createNoteElement(note)));
}
function createNoteElement(note) {
const div = document.createElement('div');
div.className = 'note';
div.dataset.id = note.id;
div.dataset.color = note.color || 'default';
// open editor when clicking card
div.addEventListener('click', () => openEditModal(note.id));
const content = document.createElement('div');
content.className = 'note-content';
const h3 = document.createElement('h3');
h3.textContent = note.title || 'Untitled';
const p = document.createElement('p');
p.textContent = note.content || '';
content.appendChild(h3);
content.appendChild(p);
const footer = document.createElement('div');
footer.className = 'note-footer';
const ts = document.createElement('span');
ts.className = 'timestamp';
ts.textContent = `Edited ${formatRelativeTime(note.updatedAt)}`;
const actions = document.createElement('div');
actions.className = 'actions';
const pinBtn = document.createElement('button');
pinBtn.title = note.pinned ? 'Unpin' : 'Pin';
pinBtn.textContent = note.pinned ? 'π' : 'π';
pinBtn.addEventListener('click', (ev) => { ev.stopPropagation(); togglePin(Number(note.id)); });
const delBtn = document.createElement('button');
delBtn.title = 'Delete';
delBtn.textContent = 'ποΈ';
delBtn.addEventListener('click', (ev) => { ev.stopPropagation(); deleteNote(note.id); });
actions.appendChild(pinBtn);
actions.appendChild(delBtn);
footer.appendChild(ts);
footer.appendChild(actions);
div.appendChild(content);
div.appendChild(footer);
return div;
}
// --- Edit Modal Logic ---
const editModal = document.getElementById('editModal');
let currentEditId = null;
async function openEditModal(id) {
const note = await getNoteById(id);
if (!note) return;
currentEditId = id;
document.getElementById('modalTitle').value = note.title;
document.getElementById('modalContent').value = note.content;
document.getElementById('modalTimestamp').textContent = `Edited ${formatRelativeTime(note.updatedAt)}`;
document.getElementById('modalNoteCard').dataset.color = note.color || 'default';
// Actions (use event listeners to avoid inline handler scope issues)
const actionsContainer = document.getElementById('modalActions');
actionsContainer.innerHTML = '';
const pinBtn = document.createElement('button');
pinBtn.title = note.pinned ? 'Unpin' : 'Pin';
pinBtn.textContent = note.pinned ? 'π' : 'π';
pinBtn.addEventListener('click', () => togglePin(Number(id), true));
const delBtn = document.createElement('button');
delBtn.title = 'Delete';
delBtn.textContent = 'ποΈ';
delBtn.addEventListener('click', () => deleteNote(Number(id), true));
const saveBtn = document.createElement('button');
saveBtn.title = 'Save & Close';
saveBtn.textContent = 'Done';
saveBtn.addEventListener('click', () => closeEditModal(true));
actionsContainer.appendChild(pinBtn);
actionsContainer.appendChild(delBtn);
actionsContainer.appendChild(saveBtn);
editModal.style.display = 'flex';
}
function closeEditModal(save = false) {
if (save) {
const title = document.getElementById('modalTitle').value.trim();
const content = document.getElementById('modalContent').value.trim();
updateNote(currentEditId, { title, content });
}
editModal.style.display = 'none';
currentEditId = null;
}
editModal.onclick = (e) => { if (e.target === editModal) closeEditModal(true); };
// --- CRUD & Actions ---
function deleteNote(id, fromModal = false) {
id = Number(id);
if (confirm('Are you sure you want to delete this note?')) {
const tx = db.transaction("notes", "readwrite");
tx.objectStore("notes").delete(id);
tx.oncomplete = () => {
if (fromModal) editModal.style.display = 'none';
displayNotes();
};
}
}
function togglePin(id, fromModal = false) {
updateNote(id, null, (note) => ({ pinned: !note.pinned }), fromModal);
}
function updateNote(id, data, transformFn, fromModal = false) {
id = Number(id);
const tx = db.transaction("notes", "readwrite");
const store = tx.objectStore("notes");
const req = store.get(id);
req.onsuccess = (e) => {
const note = e.target.result;
if (!note) return; // nothing to update
let updatedData = { ...note };
if (data) Object.assign(updatedData, data);
if (transformFn) Object.assign(updatedData, transformFn(note));
updatedData.updatedAt = new Date().toISOString();
store.put(updatedData);
};
req.onerror = () => { console.error('Failed to read note for update', id); };
tx.oncomplete = () => {
if (fromModal) {
if (editModal.style.display === 'flex') {
openEditModal(id);
} else {
displayNotes();
}
} else {
displayNotes();
}
};
}
async function getNoteById(id) {
id = Number(id);
const tx = db.transaction("notes", "readonly");
return new Promise(res => {
tx.objectStore("notes").get(id).onsuccess = e => res(e.target.result);
});
}
// --- Utils ---
function formatRelativeTime(dateString) {
const date = new Date(dateString);
const now = new Date();
const seconds = Math.round((now - date) / 1000);
const minutes = Math.round(seconds / 60);
const hours = Math.round(minutes / 60);
const days = Math.round(hours / 24);
if (seconds < 60) return "just now";
if (minutes < 60) return `${minutes} min ago`;
if (hours < 24) return `${hours} hr ago`;
if (days < 7) return `${days} day${days > 1 ? 's' : ''} ago`;
return date.toLocaleDateString();
}
// --- Event Listeners ---
document.getElementById('search').addEventListener('input', displayNotes);
</script>
</body>
</html>