-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
740 lines (635 loc) · 24.4 KB
/
script.js
File metadata and controls
740 lines (635 loc) · 24.4 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
let todos = [];
let todoIdCounter = 0;
let autoSaveEnabled = true;
let autoSaveInterval;
let journalEntries = [];
const templates = {
daily: {
name: "Daily Code Session",
icon: "💻",
fields: [
"What did I code today?",
"What languages/frameworks did I use?",
"What problems did I solve?",
"What new concepts did I learn?",
"What challenged me the most?",
"Code snippets or solutions to remember",
"Tomorrow's coding goals"
]
},
project: {
name: "Project Development Log",
icon: "🚀",
fields: [
"Project name and current milestone",
"Features implemented today",
"Technical decisions made",
"Architecture/design patterns used",
"Challenges encountered and solutions",
"Code quality improvements",
"Next development priorities"
]
},
skill: {
name: "Skill Building Session",
icon: "⚡",
fields: [
"Skill/technology being learned",
"Learning resources used",
"Hands-on practice completed",
"Key concepts understood",
"Areas still confusing",
"Practice projects or exercises",
"Next learning steps"
]
},
debugging: {
name: "Bug Hunt & Debug Log",
icon: "🐛",
fields: [
"Bug description and symptoms",
"Error messages encountered",
"Debugging techniques used",
"Root cause identified",
"Solution implemented",
"Prevention strategies for future",
"Tools that helped most"
]
},
learning: {
name: "New Tech Learning Log",
icon: "📚",
fields: [
"Technology/framework being learned",
"Why this tech was chosen",
"Tutorial/course progress",
"Hello world and first examples",
"Comparison with familiar technologies",
"Practical applications identified",
"Learning roadmap and next steps"
]
}
};
// Auto-save functionality
function toggleAutoSave() {
autoSaveEnabled = !autoSaveEnabled;
const toggle = document.getElementById('autoSaveToggle');
const status = document.getElementById('autoSaveStatus');
if (autoSaveEnabled) {
toggle.classList.add('active');
status.textContent = 'Auto-Save: ON';
startAutoSave();
showNotification('Auto-save enabled', 'success');
} else {
toggle.classList.remove('active');
status.textContent = 'Auto-Save: OFF';
stopAutoSave();
showNotification('Auto-save disabled', 'info');
}
}
function startAutoSave() {
if (autoSaveInterval) clearInterval(autoSaveInterval);
autoSaveInterval = setInterval(autoSave, 30000); // Auto-save every 30 seconds
}
function stopAutoSave() {
if (autoSaveInterval) {
clearInterval(autoSaveInterval);
autoSaveInterval = null;
}
}
function autoSave() {
if (!autoSaveEnabled) return;
const status = document.getElementById('autoSaveStatus');
status.textContent = 'Saving...';
status.classList.add('saving');
const allData = {
todos: todos,
journalEntries: getAllEntries(),
settings: {
focus: document.getElementById('focus').value,
language: document.getElementById('language').value,
experience: document.getElementById('experience').value
},
lastSaved: new Date().toISOString(),
version: '2.0'
};
localStorage.setItem('devjournal_data', JSON.stringify(allData));
setTimeout(() => {
status.textContent = 'Auto-Save: ON';
status.classList.remove('saving');
updateLastSavedTime();
}, 1000);
}
function loadData() {
try {
const savedData = localStorage.getItem('devjournal_data');
if (!savedData) return;
const data = JSON.parse(savedData);
// Load todos
if (data.todos) {
todos = data.todos;
todoIdCounter = Math.max(...todos.map(t => t.id), 0) + 1;
}
// Load journal entries
if (data.journalEntries) {
journalEntries = data.journalEntries;
}
// Load settings
if (data.settings) {
document.getElementById('focus').value = data.settings.focus || 'daily';
document.getElementById('language').value = data.settings.language || 'javascript';
document.getElementById('experience').value = data.settings.experience || 'beginner';
}
renderTodos();
updateProgress();
updateTemplates();
populateTemplatesWithData();
updateLastSavedTime();
updateDataInfo();
showNotification('Data loaded successfully', 'success');
} catch (error) {
console.error('Error loading data:', error);
showNotification('Error loading saved data', 'error');
}
}
function populateTemplatesWithData() {
if (journalEntries.length === 0) return;
const cards = document.querySelectorAll('.template-card');
cards.forEach(card => {
const title = card.querySelector('h3').textContent.replace(/[💻🚀⚡🐛📚]/g, '').trim();
const latestEntry = journalEntries
.filter(entry => entry.template === title)
.sort((a, b) => new Date(b.date) - new Date(a.date))[0];
if (latestEntry && latestEntry.content) {
const fields = card.querySelectorAll('.field');
fields.forEach(field => {
const label = field.querySelector('.field-label').textContent.replace('> ', '');
const input = field.querySelector('.field-input');
if (latestEntry.content[label]) {
input.value = latestEntry.content[label];
}
});
}
});
}
// Notification system
function showNotification(message, type = 'info') {
const notification = document.getElementById('notification');
notification.textContent = message;
notification.className = `notification ${type}`;
notification.classList.add('show');
setTimeout(() => {
notification.classList.remove('show');
}, 3000);
}
function updateLastSavedTime() {
const lastSaved = localStorage.getItem('devjournal_last_saved') || new Date().toISOString();
const date = new Date(lastSaved);
document.getElementById('lastSavedTime').textContent = date.toLocaleString();
localStorage.setItem('devjournal_last_saved', new Date().toISOString());
}
function updateDataInfo() {
const entryCount = journalEntries.length;
const todoCount = todos.length;
document.getElementById('entryCount').textContent = entryCount;
document.getElementById('todoCount').textContent = todoCount;
}
// File import functionality
function handleFileImport(event) {
const file = event.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function(e) {
try {
const data = JSON.parse(e.target.result);
if (data.todos) {
const existingTodos = todos.length;
todos = [...todos, ...data.todos.map(todo => ({
...todo,
id: todoIdCounter++
}))];
renderTodos();
updateProgress();
showNotification(`Imported ${data.todos.length} todos (${existingTodos} existing)`, 'success');
}
} catch (error) {
showNotification('Invalid file format', 'error');
}
};
reader.readAsText(file);
event.target.value = '';
}
function handleFullDataImport(event) {
const file = event.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function(e) {
try {
const data = JSON.parse(e.target.result);
if (confirm('This will replace all your current data. Are you sure?')) {
if (data.todos) {
todos = data.todos;
todoIdCounter = Math.max(...todos.map(t => t.id), 0) + 1;
}
if (data.journalEntries) {
journalEntries = data.journalEntries;
}
if (data.settings) {
document.getElementById('focus').value = data.settings.focus || 'daily';
document.getElementById('language').value = data.settings.language || 'javascript';
document.getElementById('experience').value = data.settings.experience || 'beginner';
}
renderTodos();
updateProgress();
updateTemplates();
populateTemplatesWithData();
updateDataInfo();
autoSave();
showNotification('Data imported successfully', 'success');
}
} catch (error) {
showNotification('Invalid backup file format', 'error');
}
};
reader.readAsText(file);
event.target.value = '';
}
function mergeDataPrompt() {
const input = document.createElement('input');
input.type = 'file';
input.accept = '.json';
input.onchange = function(event) {
const file = event.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function(e) {
try {
const data = JSON.parse(e.target.result);
let merged = 0;
if (data.todos) {
const newTodos = data.todos.filter(importTodo =>
!todos.some(existingTodo => existingTodo.text === importTodo.text)
);
newTodos.forEach(todo => {
todos.push({ ...todo, id: todoIdCounter++ });
});
merged += newTodos.length;
}
if (data.journalEntries) {
const newEntries = data.journalEntries.filter(importEntry =>
!journalEntries.some(existingEntry =>
existingEntry.date === importEntry.date &&
existingEntry.template === importEntry.template
)
);
journalEntries = [...journalEntries, ...newEntries];
merged += newEntries.length;
}
renderTodos();
updateProgress();
updateDataInfo();
autoSave();
showNotification(`Merged ${merged} new items`, 'success');
} catch (error) {
showNotification('Invalid file format', 'error');
}
};
reader.readAsText(file);
};
input.click();
}
function updateTemplates() {
const focus = document.getElementById('focus').value;
const language = document.getElementById('language').value;
const experience = document.getElementById('experience').value;
const templatesDiv = document.getElementById('templates');
templatesDiv.innerHTML = '';
// Get primary template
const primaryTemplate = templates[focus];
// Customize fields based on experience level
let fields = [...primaryTemplate.fields];
if (experience === 'beginner') {
fields = fields.map(field => {
if (field.includes('patterns')) return field.replace('patterns', 'approaches');
if (field.includes('architecture')) return 'Basic structure and organization';
return field;
});
}
// Create template card
const templateDiv = document.createElement('div');
templateDiv.className = 'template-card';
templateDiv.innerHTML = `
<h3><span class="icon">${primaryTemplate.icon}</span>${primaryTemplate.name}</h3>
<div class="template-content">
${fields.map(field => `
<div class="field">
<div class="field-label">${field}</div>
<textarea class="field-input" placeholder="Share your coding insights..." oninput="scheduleAutoSave()"></textarea>
</div>
`).join('')}
<button class="btn" onclick="saveEntry(this)">Save Entry</button>
</div>
`;
templatesDiv.appendChild(templateDiv);
// Add a second complementary template
const complementaryTemplates = Object.values(templates).filter(t => t !== primaryTemplate);
if (complementaryTemplates.length > 0) {
const secondTemplate = complementaryTemplates[0];
const secondDiv = document.createElement('div');
secondDiv.className = 'template-card';
secondDiv.innerHTML = `
<h3><span class="icon">${secondTemplate.icon}</span>${secondTemplate.name}</h3>
<div class="template-content">
${secondTemplate.fields.slice(0, 5).map(field => `
<div class="field">
<div class="field-label">${field}</div>
<textarea class="field-input" placeholder="Document your progress..." oninput="scheduleAutoSave()"></textarea>
</div>
`).join('')}
<button class="btn" onclick="saveEntry(this)">Save Entry</button>
</div>
`;
templatesDiv.appendChild(secondDiv);
}
populateTemplatesWithData();
}
function scheduleAutoSave() {
if (autoSaveEnabled) {
clearTimeout(window.autoSaveTimeout);
window.autoSaveTimeout = setTimeout(autoSave, 5000); // Save 5 seconds after typing stops
}
}
function addTodo() {
const input = document.getElementById('todoInput');
const text = input.value.trim();
if (text === '') return;
const todo = {
id: todoIdCounter++,
text: text,
completed: false,
timestamp: new Date().toLocaleTimeString(),
dateAdded: new Date().toISOString()
};
todos.push(todo);
input.value = '';
renderTodos();
updateProgress();
updateDataInfo();
if (autoSaveEnabled) {
scheduleAutoSave();
}
}
function renderTodos() {
const todoList = document.getElementById('todoList');
todoList.innerHTML = '';
todos.forEach(todo => {
const li = document.createElement('li');
li.className = `todo-item ${todo.completed ? 'completed' : ''}`;
li.innerHTML = `
<input type="checkbox" class="todo-checkbox" ${todo.completed ? 'checked' : ''}
onchange="toggleTodo(${todo.id})">
<span class="todo-text">${todo.text}</span>
<button class="delete-btn" onclick="deleteTodo(${todo.id})">×</button>
`;
todoList.appendChild(li);
});
}
function toggleTodo(id) {
const todo = todos.find(t => t.id === id);
if (todo) {
todo.completed = !todo.completed;
todo.completedDate = todo.completed ? new Date().toISOString() : null;
renderTodos();
updateProgress();
if (autoSaveEnabled) {
scheduleAutoSave();
}
}
}
function deleteTodo(id) {
todos = todos.filter(t => t.id !== id);
renderTodos();
updateProgress();
updateDataInfo();
if (autoSaveEnabled) {
scheduleAutoSave();
}
}
function clearCompleted() {
const completedCount = todos.filter(t => t.completed).length;
todos = todos.filter(t => !t.completed);
renderTodos();
updateProgress();
updateDataInfo();
if (completedCount > 0) {
showNotification(`Cleared ${completedCount} completed tasks`, 'success');
if (autoSaveEnabled) {
scheduleAutoSave();
}
}
}
function updateProgress() {
const completed = todos.filter(t => t.completed).length;
const total = todos.length;
const percentage = total > 0 ? (completed / total) * 100 : 0;
document.getElementById('progressFill').style.width = percentage + '%';
document.getElementById('completedCount').textContent = `${completed} completed`;
document.getElementById('totalCount').textContent = `${total} total`;
}
// Journal entry functions
function saveEntry(button) {
const card = button.closest('.template-card');
const inputs = card.querySelectorAll('.field-input');
const title = card.querySelector('h3').textContent.replace(/[💻🚀⚡🐛📚]/g, '').trim();
let hasContent = false;
const entry = {
template: title,
date: new Date().toISOString(),
content: {}
};
inputs.forEach(input => {
const fieldLabel = input.parentNode.querySelector('.field-label').textContent.replace('> ', '');
const value = input.value.trim();
if (value) {
hasContent = true;
entry.content[fieldLabel] = value;
}
});
if (hasContent) {
// Update existing entry or add new one
const existingIndex = journalEntries.findIndex(e =>
e.template === entry.template &&
new Date(e.date).toDateString() === new Date(entry.date).toDateString()
);
if (existingIndex >= 0) {
journalEntries[existingIndex] = entry;
} else {
journalEntries.push(entry);
}
button.textContent = 'Entry Saved! ✓';
button.style.background = 'linear-gradient(45deg, #00ff88, #00cc6a)';
updateDataInfo();
if (autoSaveEnabled) {
scheduleAutoSave();
}
setTimeout(() => {
button.textContent = 'Save Entry';
button.style.background = 'linear-gradient(45deg, #00ff88, #00cc6a)';
}, 2000);
} else {
button.textContent = 'Add some content first!';
button.style.background = 'linear-gradient(45deg, #ff4757, #c0392b)';
setTimeout(() => {
button.textContent = 'Save Entry';
button.style.background = 'linear-gradient(45deg, #00ff88, #00cc6a)';
}, 2000);
}
}
function getAllEntries() {
return journalEntries;
}
function getTimestamp() {
const now = new Date();
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, '0');
const day = String(now.getDate()).padStart(2, '0');
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
return `${year}-${month}-${day}_${hours}-${minutes}`;
}
function exportAsText() {
const entries = getAllEntries();
if (entries.length === 0) {
showNotification('No entries to export! Fill out some journal entries first.', 'error');
return;
}
let content = `DEV JOURNAL EXPORT\n`;
content += `Exported: ${new Date().toLocaleString()}\n`;
content += `Total Entries: ${entries.length}\n`;
content += `${'='.repeat(60)}\n\n`;
entries.forEach((entry, index) => {
content += `[${index + 1}] ${entry.template}\n`;
content += `Date: ${new Date(entry.date).toLocaleString()}\n`;
content += `${'-'.repeat(40)}\n`;
Object.entries(entry.content).forEach(([question, answer]) => {
content += `${question}\n${answer}\n\n`;
});
content += `${'='.repeat(60)}\n\n`;
});
const filename = `DevJournal_Export_${getTimestamp()}.txt`;
downloadFile(content, filename, 'text/plain');
showNotification('Text export downloaded!', 'success');
}
function exportAsJSON() {
const entries = getAllEntries();
const exportData = {
exportDate: new Date().toISOString(),
version: '2.0',
journalEntries: entries,
todos: todos,
settings: {
focus: document.getElementById('focus').value,
language: document.getElementById('language').value,
experience: document.getElementById('experience').value
},
stats: {
totalEntries: entries.length,
totalTodos: todos.length,
completedTodos: todos.filter(t => t.completed).length
}
};
const filename = `DevJournal_Backup_${getTimestamp()}.json`;
downloadFile(JSON.stringify(exportData, null, 2), filename, 'application/json');
showNotification('Full backup downloaded!', 'success');
}
function copyToClipboard() {
const entries = getAllEntries();
if (entries.length === 0) {
showNotification('No entries to copy!', 'error');
return;
}
let content = `DEV JOURNAL ENTRIES\n`;
content += `Copied: ${new Date().toLocaleString()}\n\n`;
entries.forEach((entry, index) => {
content += `${entry.template} (${new Date(entry.date).toLocaleDateString()})\n`;
Object.entries(entry.content).forEach(([question, answer]) => {
content += `• ${question}: ${answer}\n`;
});
content += `\n`;
});
navigator.clipboard.writeText(content).then(() => {
showNotification('Journal entries copied to clipboard!', 'success');
}).catch(() => {
showNotification('Could not copy to clipboard', 'error');
});
}
function exportTodos() {
if (todos.length === 0) {
showNotification('No todos to export!', 'error');
return;
}
let content = `DEV TODO LIST\n`;
content += `Exported: ${new Date().toLocaleString()}\n`;
content += `${'='.repeat(40)}\n\n`;
const pending = todos.filter(t => !t.completed);
const completed = todos.filter(t => t.completed);
if (pending.length > 0) {
content += `PENDING TASKS (${pending.length}):\n`;
content += `${'-'.repeat(20)}\n`;
pending.forEach((todo, i) => {
content += `${i + 1}. [ ] ${todo.text}\n`;
content += ` Added: ${new Date(todo.dateAdded).toLocaleString()}\n\n`;
});
content += `\n`;
}
if (completed.length > 0) {
content += `COMPLETED TASKS (${completed.length}):\n`;
content += `${'-'.repeat(20)}\n`;
completed.forEach((todo, i) => {
content += `${i + 1}. [✓] ${todo.text}\n`;
content += ` Added: ${new Date(todo.dateAdded).toLocaleString()}\n`;
content += ` Completed: ${new Date(todo.completedDate).toLocaleString()}\n\n`;
});
}
const filename = `DevJournal_Todos_${getTimestamp()}.txt`;
downloadFile(content, filename, 'text/plain');
showNotification('Todo list exported!', 'success');
}
function downloadFile(content, filename, mimeType) {
const blob = new Blob([content], { type: mimeType });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = filename;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(url);
}
// Event listeners
document.getElementById('todoInput').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
addTodo();
}
});
// Listen for template input changes
document.addEventListener('input', function(e) {
if (e.target.classList.contains('field-input')) {
scheduleAutoSave();
}
});
// Initialize
document.addEventListener('DOMContentLoaded', function() {
loadData();
updateTemplates();
renderTodos();
updateProgress();
updateDataInfo();
startAutoSave();
});
// Save data before page unload
window.addEventListener('beforeunload', function() {
if (autoSaveEnabled) {
autoSave();
}
});