Study Notes Categorizer

Study Notes Categorizer

1. Paste Your Notes

2. Organized Notes

Your organized notes will appear here.

Please paste some notes to categorize.

`; return; } // Show loading state outputPlaceholder.classList.add('hidden'); loadingSpinner.classList.remove('hidden'); categorizedOutput.innerHTML = ''; categorizedOutput.appendChild(loadingSpinner); const prompt = ` Analyze the following block of study notes. Identify the main subjects and the specific topics within each subject. Organize all the notes into a structured format. RULES: - Group all related notes under the most appropriate subject and topic. - If a line seems to be a topic heading, use it as the topic name. - Do not summarize or change the content of the notes. Present them as they are. --- STUDY NOTES --- ${notes} --- END STUDY NOTES --- `; // Define the expected JSON structure for the response const payload = { contents: [{ role: "user", parts: [{ text: prompt }] }], generationConfig: { responseMimeType: "application/json", responseSchema: { type: "ARRAY", items: { type: "OBJECT", properties: { "subject": { "type": "STRING" }, "topics": { "type": "ARRAY", "items": { "type": "OBJECT", "properties": { "topic_name": { "type": "STRING" }, "notes": { "type": "ARRAY", "items": { "type": "STRING" } } }, required: ["topic_name", "notes"] } } }, required: ["subject", "topics"] } } } }; try { const response = await fetch(API_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) }); if (!response.ok) { throw new Error(`API request failed with status ${response.status}`); } const result = await response.json(); if (result.candidates && result.candidates[0].content && result.candidates[0].content.parts[0].text) { const jsonText = result.candidates[0].content.parts[0].text; const parsedJson = JSON.parse(jsonText); displayCategorizedNotes(parsedJson); } else { throw new Error("Invalid response structure from API."); } } catch (error) { console.error("Error categorizing notes:", error); categorizedOutput.innerHTML = `

An error occurred. Please try again.

`; } finally { loadingSpinner.classList.add('hidden'); } }; /** * Renders the categorized notes in the output area. * @param {Array} categorizedData - The structured data from the API. */ const displayCategorizedNotes = (categorizedData) => { categorizedOutput.innerHTML = ''; // Clear previous content if (!categorizedData || categorizedData.length === 0) { categorizedOutput.appendChild(outputPlaceholder); outputPlaceholder.classList.remove('hidden'); outputPlaceholder.querySelector('p').innerText = "Could not categorize the notes. Please try different text."; return; } const fragment = document.createDocumentFragment(); categorizedData.forEach(subject => { const subjectContainer = document.createElement('div'); subjectContainer.className = 'p-4 border border-gray-200 rounded-lg bg-gray-50 mb-4'; const subjectTitle = document.createElement('h3'); subjectTitle.className = 'text-xl font-bold text-blue-700 mb-3'; subjectTitle.textContent = subject.subject; subjectContainer.appendChild(subjectTitle); subject.topics.forEach(topic => { const topicContainer = document.createElement('div'); topicContainer.className = 'ml-4 mb-3'; const topicTitle = document.createElement('h4'); topicTitle.className = 'text-lg font-semibold text-gray-800'; topicTitle.textContent = topic.topic_name; topicContainer.appendChild(topicTitle); const notesList = document.createElement('ul'); notesList.className = 'list-disc list-inside text-gray-700 ml-4 mt-1 space-y-1'; topic.notes.forEach(note => { const noteItem = document.createElement('li'); noteItem.textContent = note; notesList.appendChild(noteItem); }); topicContainer.appendChild(notesList); subjectContainer.appendChild(topicContainer); }); fragment.appendChild(subjectContainer); }); categorizedOutput.appendChild(fragment); }; // --- Event Listener --- if (categorizeBtn) { categorizeBtn.addEventListener('click', handleCategorizeNotes); } });
Scroll to Top