-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotes-list.html
More file actions
1220 lines (1127 loc) · 44.5 KB
/
notes-list.html
File metadata and controls
1220 lines (1127 loc) · 44.5 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
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes, maximum-scale=5.0">
<title>📄 Notes List</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: #f8fafc;
color: #334155;
height: 100vh;
overflow: hidden;
}
.header {
background: #fff;
display: flex;
align-items: center;
justify-content: space-between;
padding: 12px 16px;
border-bottom: 1px solid #e2e8f0;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
z-index: 50;
min-height: 60px;
}
.header-left {
display: flex;
align-items: center;
gap: 12px;
flex: 1;
min-width: 0;
}
.header-title {
font-size: 1.25rem;
font-weight: 600;
color: #1e293b;
margin: 0;
white-space: nowrap;
}
.header-actions {
display: flex;
align-items: center;
gap: 8px;
flex-wrap: nowrap;
}
.btn {
padding: 8px 16px;
border: none;
border-radius: 6px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s;
display: inline-flex;
align-items: center;
gap: 6px;
}
.btn-primary {
background: #3b82f6;
color: #fff;
}
.btn-primary:hover {
background: #2563eb;
}
.btn-secondary {
background: #f1f5f9;
color: #475569;
}
.btn-secondary:hover {
background: #e2e8f0;
}
.main-content {
height: calc(100vh - 60px);
overflow-y: auto;
background: #fff;
}
.notes-controls {
padding: 16px;
border-bottom: 1px solid #e2e8f0;
background: #fff;
position: sticky;
top: 0;
z-index: 10;
}
.search-section {
display: flex;
gap: 8px;
align-items: center;
flex-wrap: wrap;
margin-bottom: 12px;
}
.search-input {
flex: 1;
min-width: 200px;
padding: 8px 12px;
border: 1px solid #d1d5db;
border-radius: 6px;
font-size: 14px;
outline: none;
transition: border-color 0.2s;
}
.search-input:focus {
border-color: #3b82f6;
box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}
.filter-select {
padding: 8px 12px;
border: 1px solid #d1d5db;
border-radius: 6px;
font-size: 14px;
background: #fff;
outline: none;
min-width: 120px;
cursor: pointer;
}
.filter-select:focus {
border-color: #3b82f6;
box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}
.stats-section {
display: flex;
gap: 16px;
font-size: 14px;
color: #6b7280;
}
.stat-item {
display: flex;
align-items: center;
gap: 4px;
}
.notes-list {
padding: 8px 0;
}
.note-item {
position: relative;
padding: 16px;
border-bottom: 1px solid #f1f5f9;
cursor: pointer;
transition: background-color 0.2s;
}
.note-item:hover {
background: #f8fafc;
}
.note-item.selected {
background: #eff6ff;
border-left: 4px solid #3b82f6;
padding-left: 12px;
}
.note-content {
padding-right: 40px;
}
.note-title {
font-size: 1rem;
font-weight: 600;
color: #1e293b;
margin-bottom: 8px;
line-height: 1.4;
}
.note-preview {
font-size: 0.875rem;
color: #6b7280;
line-height: 1.4;
margin-bottom: 8px;
display: -webkit-box;
-webkit-line-clamp: 2;
line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.note-meta {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 0.75rem;
color: #9ca3af;
margin-bottom: 8px;
}
.note-tags {
display: flex;
flex-wrap: wrap;
gap: 4px;
}
.tag-item {
display: inline-flex;
align-items: center;
background: #e0f2fe;
color: #0369a1;
padding: 2px 6px;
border-radius: 10px;
font-size: 0.75rem;
border: 1px solid #0284c7;
}
.note-actions {
position: absolute;
top: 12px;
right: 12px;
display: flex;
gap: 4px;
opacity: 0;
transition: opacity 0.2s;
}
.note-item:hover .note-actions {
opacity: 1;
}
.note-action-btn {
background: #fff;
border: 1px solid #d1d5db;
color: #6b7280;
cursor: pointer;
padding: 4px 8px;
border-radius: 4px;
font-size: 0.75rem;
transition: all 0.2s;
}
.note-action-btn:hover {
background: #f3f4f6;
border-color: #9ca3af;
}
.note-action-btn.edit {
color: #3b82f6;
border-color: #3b82f6;
}
.note-action-btn.edit:hover {
background: #eff6ff;
}
.note-action-btn.delete {
color: #dc2626;
border-color: #dc2626;
}
.note-action-btn.delete:hover {
background: #fef2f2;
}
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 300px;
text-align: center;
color: #6b7280;
padding: 40px 20px;
}
.empty-icon {
font-size: 3rem;
margin-bottom: 16px;
opacity: 0.5;
}
.sort-controls {
display: flex;
gap: 8px;
align-items: center;
font-size: 14px;
color: #6b7280;
}
.sort-btn {
background: none;
border: 1px solid #d1d5db;
color: #6b7280;
cursor: pointer;
padding: 4px 8px;
border-radius: 4px;
font-size: 12px;
transition: all 0.2s;
}
.sort-btn:hover, .sort-btn.active {
background: #f3f4f6;
border-color: #9ca3af;
color: #374151;
}
.lock-btn {
background: #dc2626;
color: white;
border: 1px solid #dc2626;
cursor: pointer;
padding: 4px 8px;
border-radius: 4px;
font-size: 12px;
transition: all 0.2s;
white-space: nowrap;
}
.lock-btn:hover {
background: #b91c1c;
border-color: #b91c1c;
}
@media (max-width: 768px) {
.header {
padding: 10px 16px;
}
.header-title {
font-size: 1.1rem;
}
.search-section {
flex-direction: column;
align-items: stretch;
}
.search-input {
min-width: unset;
}
.filter-select {
min-width: unset;
}
.stats-section {
flex-wrap: wrap;
gap: 12px;
}
}
</style>
<script src="encrypted-storage.js"></script>
</head>
<body>
<div class="main-content">
<div class="notes-controls">
<div class="search-section">
<input type="text" class="search-input" id="searchInput" placeholder="Search notes..." onkeyup="searchNotes()">
<select class="filter-select" id="tagFilter" onchange="filterNotesByTag()">
<option value="">All Tags</option>
</select>
<div class="sort-controls">
<span>Sort:</span>
<button class="sort-btn active" onclick="sortNotes('modified')" data-sort="modified">Recent</button>
<button class="sort-btn" onclick="sortNotes('created')" data-sort="created">Created</button>
<button class="sort-btn" onclick="sortNotes('title')" data-sort="title">A-Z</button>
</div>
</div>
<div class="stats-section">
<div class="stat-item">
<span>📝</span>
<span id="total-notes">0 notes</span>
</div>
<div class="stat-item">
<span>🏷️</span>
<span id="total-tags">0 tags</span>
</div>
<div class="stat-item">
<span>📊</span>
<span id="total-words">0 words</span>
</div>
<div class="stat-item" id="lock-button-container" style="display: none;">
<button class="lock-btn" id="manual-lock-btn" onclick="manualLock()" title="Lock notes">
🔒 Lock
</button>
</div>
</div>
</div>
<div class="notes-list" id="notesList">
<!-- Notes will be dynamically loaded here -->
</div>
</div>
<!-- Modal Overlay -->
<div id="modalOverlay" class="modal-overlay" style="display: none;">
<div class="modal-content">
<div class="modal-header">
<h3 id="modalTitle">Modal Title</h3>
</div>
<div class="modal-body">
<p id="modalMessage">Modal message</p>
<input type="text" id="modalInput" class="modal-input" style="display: none;" placeholder="Enter text...">
</div>
<div class="modal-footer">
<button id="modalCancel" class="btn btn-secondary">Cancel</button>
<button id="modalConfirm" class="btn btn-primary">OK</button>
</div>
</div>
</div>
<!-- Password Protection Modal -->
<div id="passwordModal" class="modal-overlay" style="display: none;">
<div class="modal-content">
<div class="modal-header">
<h3>🔒 Password Required</h3>
</div>
<div class="modal-body">
<p>Enter your password to access your notes:</p>
<input type="password" id="passwordInput" class="modal-input" placeholder="Enter password..." autocomplete="current-password">
<div id="passwordError" style="color: #dc2626; font-size: 0.875rem; margin-top: 8px; display: none;">
Incorrect password. Please try again.
</div>
</div>
<div class="modal-footer">
<button id="passwordCancel" class="btn btn-secondary">Cancel</button>
<button id="passwordSubmit" class="btn btn-primary">🔓 Unlock</button>
</div>
</div>
</div>
<!-- Note View Modal -->
<div id="noteViewModal" class="modal-overlay" style="display: none;">
<div class="note-modal-content">
<div class="note-modal-header">
<h2 id="noteViewTitle">Note Title</h2>
<div class="note-modal-actions">
<button class="btn btn-primary" id="editNoteBtn">✏️ Edit</button>
<button class="btn btn-secondary" onclick="closeNoteModal()">✕ Close</button>
</div>
</div>
<div class="note-modal-meta">
<div id="noteViewMeta">Note metadata</div>
<div id="noteViewTags" class="note-view-tags"></div>
</div>
<div class="note-modal-body">
<div id="noteViewContent">Note content</div>
</div>
</div>
</div>
<style>
.modal-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
}
.modal-content {
background: white;
border-radius: 8px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
min-width: 300px;
max-width: 500px;
margin: 20px;
}
.modal-header {
padding: 16px 20px;
border-bottom: 1px solid #e2e8f0;
}
.modal-header h3 {
margin: 0;
font-size: 1.1rem;
color: #1e293b;
}
.modal-body {
padding: 20px;
}
.modal-body p {
margin: 0 0 16px 0;
color: #64748b;
line-height: 1.5;
}
.modal-input {
width: 100%;
padding: 8px 12px;
border: 1px solid #d1d5db;
border-radius: 6px;
font-size: 14px;
outline: none;
}
.modal-input:focus {
border-color: #3b82f6;
box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}
.modal-footer {
padding: 16px 20px;
border-top: 1px solid #e2e8f0;
display: flex;
gap: 8px;
justify-content: flex-end;
}
.note-modal-content {
background: white;
border-radius: 12px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
min-width: 400px;
max-width: 800px;
width: 90vw;
max-height: 90vh;
margin: 20px;
display: flex;
flex-direction: column;
}
.note-modal-header {
padding: 20px 24px 16px;
border-bottom: 1px solid #e2e8f0;
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 16px;
}
.note-modal-header h2 {
margin: 0;
font-size: 1.5rem;
color: #1e293b;
line-height: 1.4;
flex: 1;
word-break: break-word;
}
.note-modal-actions {
display: flex;
gap: 8px;
flex-shrink: 0;
}
.note-modal-meta {
padding: 16px 24px;
border-bottom: 1px solid #f1f5f9;
background: #f8fafc;
}
.note-modal-meta div:first-child {
font-size: 0.875rem;
color: #6b7280;
margin-bottom: 8px;
}
.note-view-tags {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.note-view-tags .tag-item {
background: #e0f2fe;
color: #0369a1;
padding: 4px 8px;
border-radius: 12px;
font-size: 0.75rem;
border: 1px solid #0284c7;
}
.note-modal-body {
padding: 24px;
overflow-y: auto;
flex: 1;
line-height: 1.6;
}
.note-modal-body h1, .note-modal-body h2, .note-modal-body h3 {
margin-top: 0;
margin-bottom: 16px;
color: #1e293b;
}
.note-modal-body p {
margin-bottom: 16px;
color: #334155;
}
.note-modal-body ul, .note-modal-body ol {
margin-bottom: 16px;
padding-left: 24px;
}
.note-modal-body blockquote {
margin: 16px 0;
padding: 12px 16px;
border-left: 4px solid #3b82f6;
background: #f8fafc;
font-style: italic;
color: #6b7280;
}
.note-modal-body code {
background: #f1f5f9;
padding: 2px 4px;
border-radius: 3px;
font-family: Monaco, monospace;
font-size: 0.875rem;
}
.note-modal-body img {
max-width: 100%;
height: auto;
border-radius: 6px;
margin: 8px 0;
}
@media (max-width: 768px) {
.note-modal-content {
min-width: unset;
width: 95vw;
max-height: 95vh;
margin: 10px;
}
.note-modal-header {
padding: 16px 20px 12px;
flex-direction: column;
align-items: stretch;
gap: 12px;
}
.note-modal-actions {
align-self: flex-end;
}
.note-modal-meta {
padding: 12px 20px;
}
.note-modal-body {
padding: 20px;
}
}
</style>
<script>
// Global state using encrypted storage
let notes = {};
let tags = [];
let storage = null;
let currentSort = 'modified';
let isPasswordProtected = false;
let isUnlocked = false;
let passwordHash = null;
// Initialize storage
async function initStorage() {
try {
if (typeof EncryptedStorage !== 'undefined') {
storage = new EncryptedStorage();
} else {
// Fallback storage
storage = {
async saveEncrypted(key, data) {
localStorage.setItem(key, JSON.stringify(data));
return true;
},
async loadEncrypted(key) {
const data = localStorage.getItem(key);
return data ? JSON.parse(data) : null;
}
};
}
await loadData();
} catch (error) {
console.error('Storage initialization failed:', error);
}
}
// Load data from storage
async function loadData() {
try {
const data = await storage.loadEncrypted('notebook-data');
if (data) {
notes = data.notes || {};
tags = data.tags || [];
isPasswordProtected = data.settings?.passwordProtected || false;
passwordHash = data.settings?.passwordHash || null;
} else {
// Default data
notes = {
'1': {
id: '1',
title: 'Welcome to your Notes! 👋',
content: '<h2>Getting Started</h2><p>Welcome to your unified productivity workspace! Here\'s how to get started:</p><ul><li><strong>Browse notes:</strong> Use search and filters to find notes</li><li><strong>Create notes:</strong> Click the "New Note" button</li><li><strong>Edit notes:</strong> Click the edit button or use the Editor tool</li><li><strong>Organize:</strong> Use tags to organize your notes</li></ul><p>Your notes are automatically saved and work completely offline. Happy note-taking! ✨</p>',
tags: ['welcome'],
created: new Date().toISOString(),
modified: new Date().toISOString()
}
};
tags = ['welcome'];
}
// Check for stored unlock state from other components
checkStoredUnlockState();
updateNotesList();
updateTagFilter();
updateStats();
updateLockButtonVisibility();
} catch (error) {
console.error('Failed to load data:', error);
}
}
// Save data to storage
async function saveData() {
try {
const data = {
notes: notes,
tags: tags,
settings: {
encryptionEnabled: false,
passwordProtected: isPasswordProtected,
passwordHash: passwordHash
}
};
await storage.saveEncrypted('notebook-data', data);
} catch (error) {
console.error('Failed to save data:', error);
}
}
// Password protection functions
async function hashPassword(password) {
// Simple hash function for demo - in production, use stronger hashing
const encoder = new TextEncoder();
const data = encoder.encode(password + 'notes-salt-2025');
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
const hashArray = Array.from(new Uint8Array(hashBuffer));
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
}
async function verifyPassword(inputPassword) {
if (!isPasswordProtected || !passwordHash) return true;
const inputHash = await hashPassword(inputPassword);
return inputHash === passwordHash;
}
function showPasswordModal() {
document.getElementById('passwordModal').style.display = 'flex';
document.getElementById('passwordInput').value = '';
document.getElementById('passwordError').style.display = 'none';
// Focus the password input
setTimeout(() => document.getElementById('passwordInput').focus(), 100);
return new Promise((resolve) => {
const handleSubmit = async () => {
const password = document.getElementById('passwordInput').value;
if (await verifyPassword(password)) {
isUnlocked = true;
// Store unlock state in sessionStorage for cross-component sharing
sessionStorage.setItem('notes-unlocked', 'true');
sessionStorage.setItem('notes-unlock-timestamp', Date.now().toString());
hidePasswordModal();
updateLockButtonVisibility();
updateNotesList(); // Refresh the display to show unlocked content
resolve(true);
} else {
document.getElementById('passwordError').style.display = 'block';
document.getElementById('passwordInput').value = '';
document.getElementById('passwordInput').focus();
}
};
const handleCancel = () => {
hidePasswordModal();
resolve(false);
};
// Set up event listeners
document.getElementById('passwordSubmit').onclick = handleSubmit;
document.getElementById('passwordCancel').onclick = handleCancel;
// Handle Enter key
document.getElementById('passwordInput').onkeypress = (e) => {
if (e.key === 'Enter') handleSubmit();
if (e.key === 'Escape') handleCancel();
};
});
}
function hidePasswordModal() {
document.getElementById('passwordModal').style.display = 'none';
// Clean up event listeners
document.getElementById('passwordSubmit').onclick = null;
document.getElementById('passwordCancel').onclick = null;
document.getElementById('passwordInput').onkeypress = null;
}
async function requirePasswordAuth() {
if (!isPasswordProtected) return true;
if (isUnlocked) return true;
return await showPasswordModal();
}
function manualLock() {
if (isPasswordProtected && isUnlocked) {
console.log('🔒 Manual lock triggered');
isUnlocked = false;
// Clear stored unlock state
sessionStorage.removeItem('notes-unlocked');
sessionStorage.removeItem('notes-unlock-timestamp');
updateNotesList();
updateLockButtonVisibility();
}
}
function checkStoredUnlockState() {
// Check if we have a stored unlock state from a recent password entry
const unlocked = sessionStorage.getItem('notes-unlocked');
const timestamp = sessionStorage.getItem('notes-unlock-timestamp');
if (unlocked === 'true' && timestamp) {
const unlockTime = parseInt(timestamp);
const now = Date.now();
const fiveMinutes = 5 * 60 * 1000; // 5 minutes in milliseconds
// If unlock was recent (within 5 minutes), consider it valid
if (now - unlockTime < fiveMinutes) {
console.log('🔓 Found recent unlock state, setting isUnlocked = true');
isUnlocked = true;
} else {
// Clean up expired unlock state
sessionStorage.removeItem('notes-unlocked');
sessionStorage.removeItem('notes-unlock-timestamp');
}
}
}
function updateLockButtonVisibility() {
const lockButtonContainer = document.getElementById('lock-button-container');
if (isPasswordProtected && isUnlocked) {
lockButtonContainer.style.display = 'block';
} else {
lockButtonContainer.style.display = 'none';
}
}
function updateNotesList() {
const container = document.getElementById('notesList');
const searchInput = document.getElementById('searchInput');
const tagFilter = document.getElementById('tagFilter');
const searchTerm = searchInput ? searchInput.value.toLowerCase() : '';
const selectedTag = tagFilter ? tagFilter.value : '';
let allNotes = Object.entries(notes).map(([id, note]) => ({id, note}));
// Apply search filter
if (searchTerm) {
allNotes = allNotes.filter(({note}) => {
const title = (note.title || '').toLowerCase();
const content = note.content.replace(/<[^>]*>/g, '').toLowerCase();
const tags = (note.tags || []).join(' ').toLowerCase();
return title.includes(searchTerm) || content.includes(searchTerm) || tags.includes(searchTerm);
});
}
// Apply tag filter
if (selectedTag) {
allNotes = allNotes.filter(({note}) => (note.tags || []).includes(selectedTag));
}
// Sort notes
allNotes.sort((a, b) => {
switch(currentSort) {
case 'created':
return new Date(b.note.created) - new Date(a.note.created);
case 'title':
return (a.note.title || 'Untitled').localeCompare(b.note.title || 'Untitled');
case 'modified':
default:
return new Date(b.note.modified) - new Date(a.note.modified);
}
});
// Check if content should be hidden due to password protection
const shouldHideContent = isPasswordProtected && !isUnlocked;
container.innerHTML = allNotes.length ? allNotes.map(({id, note}) => {
const displayTitle = shouldHideContent ? '🔒 Protected Note' : (note.title || 'Untitled Note');
const contentText = note.content.replace(/<[^>]*>/g, '');
const preview = shouldHideContent ? 'Content is password protected' : contentText.substring(0, 150);
const wordCount = contentText.trim() ? contentText.trim().split(/\s+/).length : 0;
const createdDate = new Date(note.created).toLocaleDateString();
const modifiedDate = new Date(note.modified).toLocaleDateString();
const noteTags = shouldHideContent ? [] : (note.tags || []);
const tagsHTML = noteTags.map(tag => `<span class="tag-item">${tag}</span>`).join('');
const wordDisplay = shouldHideContent ? '-- words' : `${wordCount} words`;
return `<div class="note-item" data-note-id="${id}" onclick="viewNote('${id}')">
<div class="note-actions">
<button class="note-action-btn edit" onclick="event.stopPropagation(); editNote('${id}')" title="Edit note">✏️ Edit</button>
<button class="note-action-btn delete" onclick="event.stopPropagation(); deleteNote('${id}')" title="Delete note">🗑️ Delete</button>
</div>
<div class="note-content">
<div class="note-title">${displayTitle}</div>
<div class="note-preview">${preview}${!shouldHideContent && preview.length >= 150 ? '...' : ''}</div>
<div class="note-meta">
<span>Created: ${createdDate}</span>
<span>Modified: ${modifiedDate}</span>
<span>${wordDisplay}</span>
</div>
<div class="note-tags">${tagsHTML}</div>
</div>
</div>`;
}).join('') : `<div class="empty-state">
<div class="empty-icon">${shouldHideContent ? '🔒' : '📝'}</div>
<h3>${shouldHideContent ? 'Notes are protected' : 'No notes found'}</h3>
<p>${shouldHideContent ? 'Enter your password to view your notes.' : 'Create your first note to get started!'}</p>
</div>`;
}
function updateTagFilter() {
const filter = document.getElementById('tagFilter');
if (!filter) return;
const currentValue = filter.value;
filter.innerHTML = '<option value="">All Tags</option>' +
tags.map(tag => `<option value="${tag}" ${tag === currentValue ? 'selected' : ''}>${tag}</option>`).join('');
}
function updateStats() {
const totalNotes = Object.keys(notes).length;
const totalTags = tags.length;
const totalWords = Object.values(notes).reduce((sum, note) => {
const content = note.content.replace(/<[^>]*>/g, '');
return sum + (content.trim() ? content.trim().split(/\s+/).length : 0);
}, 0);
document.getElementById('total-notes').textContent = `${totalNotes} note${totalNotes !== 1 ? 's' : ''}`;
document.getElementById('total-tags').textContent = `${totalTags} tag${totalTags !== 1 ? 's' : ''}`;
document.getElementById('total-words').textContent = `${totalWords} words`;
}
function searchNotes() {
updateNotesList();
}
function filterNotesByTag() {
updateNotesList();
}
function sortNotes(sortType) {
currentSort = sortType;
// Update active sort button
document.querySelectorAll('.sort-btn').forEach(btn => btn.classList.remove('active'));
document.querySelector(`[data-sort="${sortType}"]`).classList.add('active');
updateNotesList();
}
async function createNote() {
// Check password authentication first
if (!(await requirePasswordAuth())) {
return;
}
showInputModal('Enter note title:', '', (title) => {
if (!title || !title.trim()) return;
const noteId = Date.now().toString();
notes[noteId] = {
id: noteId,
title: title.trim(),
content: '',
tags: [],
created: new Date().toISOString(),
modified: new Date().toISOString()
};
saveData();
updateNotesList();
updateStats();
// Automatically open the new note in editor
editNote(noteId);
});
}
async function editNote(noteId) {
// Check password authentication first
if (!(await requirePasswordAuth())) {
return;
}
const note = notes[noteId];
if (!note) {
console.error('Note not found:', noteId);
return;
}
console.log('📝 Editing note:', noteId, note.title);
// Ensure data is saved before switching tools
await saveData();
// Since editor is persistent, we can use a simpler approach
sessionStorage.setItem('editingNoteId', noteId);
// Send message to editor iframe directly to load the note
if (window.parent && window.parent !== window) {
console.log('📨 Switching to note-editor and loading note');
window.parent.postMessage({
action: 'switch-tool',
tool: 'note-editor',
editNoteId: noteId
}, '*');
} else {
// Fallback: try to navigate directly
window.location.href = 'note-editor.html';
}
}
async function deleteNote(noteId) {
// Check password authentication first
if (!(await requirePasswordAuth())) {
return;
}
const note = notes[noteId];
if (!note) return;
showConfirmModal(
`Delete "${note.title || 'Untitled Note'}"?`,
'This cannot be undone.',
() => {
delete notes[noteId];
saveData();
updateNotesList();
updateStats();
}
);
}
async function openEditor() {
// Check password authentication first
if (!(await requirePasswordAuth())) {
return;
}
// Clear any existing editing session
sessionStorage.removeItem('editingNoteId');
// Open editor tool