Persuasive Research Paper Generator

Persuasive Research Paper Generator

Structure and write a compelling research paper, section by section.

${tab.prompt}

`; if (tab.id === 'title') { contentHtml += ``; contentHtml += ``; } else { contentHtml += ``; } contentHtml += `
`; tabContentContainer.innerHTML += `
${contentHtml}
`; }); updateNavButtons(); } window.showTab = (index) => { if (index >= tabsData.length) { showFinalReview(); return; } currentTab = index; pdfDownloadSection.classList.add('hidden'); document.querySelectorAll('[role="tab"]').forEach((button, i) => { button.className = button.className.replace('tab-active', 'tab-inactive'); button.setAttribute('aria-selected', 'false'); if (i === currentTab) { button.className = button.className.replace('tab-inactive', 'tab-active'); button.setAttribute('aria-selected', 'true'); } }); document.querySelectorAll('[role="tabpanel"]').forEach((panel, i) => { panel.classList.toggle('hidden', i !== currentTab); }); updateNavButtons(); }; function updateNavButtons() { if (!prevBtn || !nextBtn) return; prevBtn.disabled = currentTab === 0; nextBtn.textContent = currentTab === tabsData.length - 1 ? 'Finish & Review' : 'Next'; } function showFinalReview() { currentTab = tabsData.length; document.querySelectorAll('[role="tabpanel"]').forEach(p => p.classList.add('hidden')); prevBtn.disabled = false; nextBtn.classList.add('hidden'); let fullPaperHtml = ''; const paperTitle = document.getElementById('input-title')?.value || 'Untitled Paper'; fullPaperHtml += `

${paperTitle}

`; tabsData.forEach(tab => { const textarea = document.getElementById(`textarea-${tab.id}`); if (textarea && textarea.value.trim() !== '') { if(tab.id !== 'title') { // Don't repeat title/thesis section heading fullPaperHtml += `

${tab.title}

`; } fullPaperHtml += `

${textarea.value.trim().replace(/\n/g, '
')}

`; } }); paperPreviewForPdf.innerHTML = fullPaperHtml || '

You haven\'t written anything yet.

'; pdfDownloadSection.classList.remove('hidden'); } function handleNavigation(direction) { const newTab = currentTab + direction; if (newTab >= 0 && newTab <= tabsData.length) { if (newTab === tabsData.length) { showFinalReview(); } else { nextBtn.classList.remove('hidden'); window.showTab(newTab); } } } window.handleAIAction = async (button, tabId) => { const textarea = document.getElementById(`textarea-${tabId}`); const aiOutputContainer = document.getElementById(`ai-output-${tabId}`); if (!textarea || !aiOutputContainer) return; const text = textarea.value.trim(); if (text.length < 25) { alert("Please write at least 25 characters to get a meaningful suggestion."); return; } const buttonText = button.querySelector('.button-text'); const spinner = button.querySelector('.spinner'); button.disabled = true; buttonText.textContent = 'Analyzing...'; spinner.classList.remove('hidden'); aiOutputContainer.innerHTML = ''; try { const systemPrompt = `You are a university professor specializing in rhetoric and persuasive writing. Analyze the following excerpt from a student's research paper. Your task is to strengthen the argument. Improve the academic tone, enhance clarity, refine word choice, and make the reasoning more robust and persuasive. Maintain the core idea of the original text. Respond only with the improved text.`; const refinedText = await callGeminiAPI(text, systemPrompt); aiOutputContainer.innerHTML = `

AI Suggestion:

${refinedText.replace(/\n/g, '
')}

`; setTimeout(() => aiOutputContainer.querySelector('.ai-suggestion-enter')?.classList.add('ai-suggestion-enter-active'), 10); } catch (error) { aiOutputContainer.innerHTML = `

Error: ${error.message}

`; } finally { button.disabled = false; buttonText.textContent = 'Strengthen Argument'; spinner.classList.add('hidden'); } }; async function callGeminiAPI(text, systemPrompt) { const apiKey = ""; const apiUrl = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-05-20:generateContent?key=${apiKey}`; const payload = { contents: [{ parts: [{ text: text }] }], systemInstruction: { parts: [{ text: systemPrompt }] }, }; const response = await fetch(apiUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) }); if (!response.ok) { const errorBody = await response.json(); throw new Error(errorBody.error?.message || `API request failed with status ${response.status}`); } const result = await response.json(); const candidate = result.candidates?.[0]; if (candidate?.content?.parts?.[0]?.text) { return candidate.content.parts[0].text; } else { throw new Error("Could not get a valid response from the AI model."); } } window.downloadPDF = function() { const { jsPDF } = window.jspdf; const doc = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const paperTitle = document.getElementById('input-title')?.value.trim() || 'Untitled Research Paper'; const leftMargin = 20, topMargin = 25, contentWidth = doc.internal.pageSize.getWidth() - leftMargin * 2; const pageHeight = doc.internal.pageSize.getHeight(), bottomMargin = 20; const lineHeight = 6, headingFontSize = 12, bodyFontSize = 10; const font = 'Times'; let cursorY = 0; // --- Title Page --- doc.setFont(font, 'normal'); doc.setFontSize(18); const titleLines = doc.splitTextToSize(paperTitle, contentWidth - 20); const titleHeight = titleLines.length * 10; doc.text(titleLines, doc.internal.pageSize.getWidth() / 2, pageHeight / 2 - titleHeight, { align: 'center' }); doc.setFontSize(12); doc.text(`A Persuasive Research Paper`, doc.internal.pageSize.getWidth() / 2, pageHeight / 2, { align: 'center' }); doc.addPage(); cursorY = topMargin; // --- Main Content --- function addHeader() { doc.setFontSize(9); doc.setFont(font, 'italic'); doc.text(paperTitle.substring(0, 50) + (paperTitle.length > 50 ? '...' : ''), leftMargin, topMargin - 10); } function addFooter(pageNumber) { doc.setFontSize(10); doc.setFont(font, 'normal'); doc.text(String(pageNumber), doc.internal.pageSize.getWidth() / 2, pageHeight - 10, { align: 'center' }); } function checkPageBreak() { if (cursorY + (lineHeight * 2) > pageHeight - bottomMargin) { addFooter(doc.internal.getNumberOfPages()); doc.addPage(); cursorY = topMargin; addHeader(); } } addHeader(); tabsData.forEach(tab => { const textarea = document.getElementById(`textarea-${tab.id}`); if (!textarea || textarea.value.trim() === '') return; checkPageBreak(); cursorY += (lineHeight * 1.5); // Space between sections checkPageBreak(); doc.setFont(font, 'bold'); doc.setFontSize(headingFontSize); const sectionTitle = tab.id === 'title' ? 'Thesis Statement' : tab.title; const titleLines = doc.splitTextToSize(sectionTitle, contentWidth); doc.text(titleLines, leftMargin, cursorY); cursorY += (titleLines.length * (lineHeight + 1)); doc.setFont(font, 'normal'); doc.setFontSize(bodyFontSize); const bodyText = textarea.value.trim(); const splitBody = doc.splitTextToSize(bodyText, contentWidth); splitBody.forEach(line => { checkPageBreak(); doc.text(line, leftMargin, cursorY); cursorY += lineHeight; }); }); addFooter(doc.internal.getNumberOfPages()); doc.save(paperTitle.replace(/[^a-z0-9]/gi, '_').toLowerCase() + '.pdf'); } // Attach Event Listeners if (prevBtn && nextBtn && downloadPdfBtn) { prevBtn.addEventListener('click', () => handleNavigation(-1)); nextBtn.addEventListener('click', () => handleNavigation(1)); downloadPdfBtn.addEventListener('click', window.downloadPDF); } initializeUI(); });
Scroll to Top