Auto-Generated Customer Review Aggregator

Customer Review Aggregator

Simulate and analyze customer sentiment for any product.

Enter a topic to generate a review summary.

Aggregating reviews...

'; placeholder.classList.remove('hidden'); resultsContainer.classList.add('hidden'); setTimeout(() => { currentReviews = generateReviews(topic); renderResults(currentReviews); placeholder.classList.add('hidden'); resultsContainer.classList.remove('hidden'); }, 1500); }; const generateReviews = (topic) => { const names = ["Alex J.", "Maria G.", "Sam T.", "Priya K.", "Chen L.", "Fatima A.", "David S."]; const positiveLines = [ `Absolutely love the ${topic}! The quality is outstanding and exceeded my expectations.`, `This is the best ${topic} I've ever purchased. Highly recommended!`, `Fantastic product. It works perfectly and the build quality is solid.`, `I'm so happy with this purchase. The ${topic} has made a huge difference.` ]; const negativeLines = [ `I was really disappointed with the ${topic}. It broke after just a few uses.`, `The quality is not what I expected for the price. I wouldn't buy this again.`, `It arrived damaged and the customer service was not helpful at all.`, `This ${topic} doesn't work as advertised. A complete waste of money.` ]; let reviews = []; const numReviews = Math.floor(Math.random() * 10) + 10; // 10-19 reviews for (let i = 0; i < numReviews; i++) { const isPositive = Math.random() > 0.3; // 70% chance of positive const rating = isPositive ? Math.floor(Math.random() * 2) + 4 : Math.floor(Math.random() * 2) + 1; // 4-5 stars or 1-2 stars reviews.push({ author: names[Math.floor(Math.random() * names.length)], rating: rating, text: isPositive ? positiveLines[Math.floor(Math.random() * positiveLines.length)] : negativeLines[Math.floor(Math.random() * negativeLines.length)], date: new Date(Date.now() - Math.random() * 30 * 24 * 60 * 60 * 1000).toLocaleDateString() }); } return reviews; }; const renderResults = (reviews) => { // Calculate stats const totalReviews = reviews.length; const totalRating = reviews.reduce((sum, r) => sum + r.rating, 0); const avgRating = totalReviews > 0 ? (totalRating / totalReviews).toFixed(1) : 0; const positiveCount = reviews.filter(r => r.rating >= 4).length; const negativeCount = reviews.filter(r => r.rating <= 2).length; // Update summary cards summaryAvg.textContent = avgRating; summaryTotal.textContent = totalReviews; summaryPositive.textContent = positiveCount; summaryNegative.textContent = negativeCount; // Render reviews list reviewsList.innerHTML = reviews.map(review => { const starColor = review.rating >= 4 ? 'text-green-500' : 'text-red-500'; let stars = ''; for(let i=0; i<5; i++) { stars += ``; } return `
${stars}
${review.date}

${review.text}

- ${review.author}

`}).join(''); }; const handleDownloadPdf = () => { const pdfContentEl = document.getElementById('pdf-content'); const topic = productTopicInput.value.trim(); if (!pdfContentEl || !topic) return; // Populate PDF document.getElementById('pdf-timestamp').textContent = new Date().toLocaleString('en-US'); document.getElementById('pdf-topic-title').textContent = topic; document.getElementById('pdf-summary-grid').innerHTML = `
Avg. Rating:
${summaryAvg.textContent}
Total Reviews:
${summaryTotal.textContent}
Positive:
${summaryPositive.textContent}
Negative:
${summaryNegative.textContent}
`; document.getElementById('pdf-review-list').innerHTML = currentReviews.map(review => { let starsHTML = ''; for(let i=0; i

Rating: ${starsHTML}

"${review.text}"

- ${review.author}, ${review.date}

`}).join(''); pdfContentEl.classList.remove('hidden'); html2canvas(pdfContentEl, { scale: 2 }).then(canvas => { pdfContentEl.classList.add('hidden'); const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const margin = 40; const imgWidth = pdfWidth - (margin * 2); const imgHeight = (canvas.height * imgWidth) / canvas.width; pdf.addImage(imgData, 'PNG', margin, margin, imgWidth, imgHeight); pdf.save(`${topic.replace(/\s+/g, '-')}-review-report.pdf`); }).catch(err => { console.error("Error generating PDF:", err); pdfContentEl.classList.add('hidden'); }); }; // --- Event Listeners --- generateBtn.addEventListener('click', handleGeneration); pdfBtn.addEventListener('click', handleDownloadPdf); });
Scroll to Top