Changed around line 1
+ let notes = JSON.parse(localStorage.getItem('notes')) || [];
+ let currentNoteId = null;
+
+ function createNote() {
+ const note = {
+ id: Date.now(),
+ content: '',
+ created: new Date().toISOString()
+ };
+ notes.push(note);
+ saveNotes();
+ openNoteDialog(note.id);
+ }
+
+ function saveNotes() {
+ localStorage.setItem('notes', JSON.stringify(notes));
+ renderNotes();
+ }
+
+ function renderNotes() {
+ const grid = document.getElementById('notesGrid');
+ grid.innerHTML = '';
+
+ notes.forEach(note => {
+ const card = document.createElement('div');
+ card.className = 'note-card';
+ card.innerHTML = parseMarkdown(note.content.substring(0, 200) + '...');
+ card.onclick = () => openNoteDialog(note.id);
+ grid.appendChild(card);
+ });
+ }
+
+ function openNoteDialog(noteId) {
+ currentNoteId = noteId;
+ const note = notes.find(n => n.id === noteId);
+ const dialog = document.getElementById('noteDialog');
+ const input = document.getElementById('noteInput');
+ input.value = note.content;
+ dialog.showModal();
+ renderPreview();
+ }
+
+ function parseMarkdown(text) {
+ // Basic Markdown parsing
+ text = text
+ .replace(/\*\*(.*?)\*\*/g, '$1')
+ .replace(/\*(.*?)\*/g, '$1')
+ .replace(/\n/g, '
')
+ .replace(/\$\$(.*?)\$\$/g, (match, formula) => {
+ // Here you would integrate a LaTeX renderer
+ return `${formula}`;
+ });
+ return text;
+ }
+
+ function renderPreview() {
+ const input = document.getElementById('noteInput');
+ const preview = document.getElementById('previewArea');
+ preview.innerHTML = parseMarkdown(input.value);
+ }
+
+ // Event Listeners
+ document.getElementById('newNote').onclick = createNote;
+
+ document.getElementById('saveNote').onclick = () => {
+ const note = notes.find(n => n.id === currentNoteId);
+ note.content = document.getElementById('noteInput').value;
+ saveNotes();
+ document.getElementById('noteDialog').close();
+ };
+
+ document.getElementById('deleteNote').onclick = () => {
+ notes = notes.filter(n => n.id !== currentNoteId);
+ saveNotes();
+ document.getElementById('noteDialog').close();
+ };
+
+ document.getElementById('editMode').onclick = function() {
+ this.classList.add('active');
+ document.getElementById('previewMode').classList.remove('active');
+ document.getElementById('editArea').classList.remove('hidden');
+ document.getElementById('previewArea').classList.add('hidden');
+ };
+
+ document.getElementById('previewMode').onclick = function() {
+ this.classList.add('active');
+ document.getElementById('editMode').classList.remove('active');
+ document.getElementById('editArea').classList.add('hidden');
+ document.getElementById('previewArea').classList.remove('hidden');
+ renderPreview();
+ };
+
+ document.getElementById('closeDialog').onclick = () => {
+ document.getElementById('noteDialog').close();
+ };
+
+ // Initial render
+ renderNotes();