Welcome to Your Private Journal
Please set a 4-digit PIN to secure your entries. This PIN is stored only on your device.
Enter PIN
Enter your 4-digit PIN to unlock your journal.
My Entries
Select an entry to read
Or create a new one to get started.
${date}
`; entryList.appendChild(item); }); } // --- DATA & LOGIC FUNCTIONS --- function loadEntries() { const storedEntries = localStorage.getItem(ENTRIES_KEY); entries = storedEntries ? JSON.parse(storedEntries) : []; } function saveEntries() { localStorage.setItem(ENTRIES_KEY, JSON.stringify(entries)); } function unlockApp() { loadEntries(); renderEntryList(); switchView('mainApp'); switchContentPanel('welcome'); pinEntryInput.value = ''; } function lockApp() { currentEntryId = null; switchView('lockScreen'); } function viewEntry(id) { const entry = entries.find(e => e.id === id); if (!entry) return; currentEntryId = id; entryTitleView.textContent = entry.title; const date = new Date(entry.timestamp).toLocaleString('en-US', { dateStyle: 'full', timeStyle: 'short' }); entryDateView.textContent = date; // Sanitize and format body content for display const formattedBody = entry.content.replace(/\n/g, ''); entryBodyView.innerHTML = formattedBody; switchContentPanel('view'); renderEntryList(); // To update selection style } function editEntry(id) { const entry = entries.find(e => e.id === id); if (!entry) return; currentEntryId = id; entryTitleEdit.value = entry.title; entryBodyEdit.value = entry.content; switchContentPanel('edit'); } function saveEntry() { const title = entryTitleEdit.value.trim() || 'Untitled Entry'; const content = entryBodyEdit.value.trim(); if (currentEntryId === 'new') { // Creating a new entry const newEntry = { id: Date.now(), title, content, timestamp: Date.now() }; entries.push(newEntry); currentEntryId = newEntry.id; } else { // Updating an existing entry const entry = entries.find(e => e.id === currentEntryId); if (entry) { entry.title = title; entry.content = content; entry.timestamp = Date.now(); // Update timestamp on edit } } saveEntries(); renderEntryList(); viewEntry(currentEntryId); } function deleteEntry() { if (!currentEntryId) return; // Simple confirmation, as per spec (no system dialogs) const originalText = deleteEntryBtn.innerText; if (deleteEntryBtn.dataset.confirming !== 'true') { deleteEntryBtn.innerText = 'Are you sure? Click again to delete.'; deleteEntryBtn.dataset.confirming = 'true'; setTimeout(() => { deleteEntryBtn.innerText = originalText; deleteEntryBtn.dataset.confirming = 'false'; }, 3000); return; } entries = entries.filter(e => e.id !== currentEntryId); saveEntries(); currentEntryId = null; renderEntryList(); switchContentPanel('welcome'); } async function downloadPDF() { const entry = entries.find(e => e.id === currentEntryId); if (!entry) return; const { jsPDF } = window.jspdf; const date = new Date(entry.timestamp).toLocaleString('en-US', { dateStyle: 'full', timeStyle: 'short' }); const formattedBody = entry.content.replace(/\n/g, '
'); pdfContent.innerHTML = `
${entry.title}
${date}
${formattedBody}
