Personalized Horoscope Generator

Enter your birth date and select a focus to get a fun, fictional horoscope!

Your personalized horoscope will appear here!

Please enter a valid birth month and day.

'; downloadBtn.style.display = 'none'; return; } // Basic validation for day based on month (not perfect, but better than nothing) if (month === 2 && day > 29) { // Handle leap year edge case simply by limiting Feb to 29 resultsDiv.innerHTML = '

Please enter a valid day for February.

'; downloadBtn.style.display = 'none'; return; } if ([4, 6, 9, 11].includes(month) && day > 30) { // April, June, Sept, Nov have 30 days resultsDiv.innerHTML = '

Please enter a valid day for the selected month.

'; downloadBtn.style.display = 'none'; return; } const generatedHoroscope = generateHoroscope(month, day, focus); resultsDiv.innerHTML = `

${generatedHoroscope.replace(/\n/g, '
').replace(/\*\*(.*?)\*\*/g, '$1')}

`; // Format bold markdown and newlines downloadBtn.style.display = 'block'; // Show download button }); document.getElementById('clearBtn').addEventListener('click', () => { document.getElementById('birthMonth').value = ''; document.getElementById('birthDay').value = ''; document.getElementById('horoscopeFocus').value = 'general'; document.getElementById('horoscopeResults').innerHTML = '

Your personalized horoscope will appear here!

'; document.getElementById('downloadPdfBtn').style.display = 'none'; // Hide PDF button }); document.getElementById('downloadPdfBtn').addEventListener('click', () => { const resultsDiv = document.getElementById('horoscopeResults'); const horoscopeText = resultsDiv.textContent.trim(); if (!horoscopeText || horoscopeText.includes('Your personalized horoscope will appear here!')) { alert("No horoscope to download."); return; } // --- PDF Generation --- const doc = new jsPDF(); const margin = 15; let y = margin; const pageHeight = doc.internal.pageSize.height; const pageWidth = doc.internal.pageSize.width; const maxLineWidth = pageWidth - 2 * margin; // Max width for text line doc.setFontSize(18); doc.setTextColor(52, 58, 64); // Match text-color variable #343a0 doc.text("Your Personalized Horoscope", margin, y); y += 15; // Space after title doc.setFontSize(12); doc.setTextColor(52, 58, 64); // Match text-color variable #343a0 // Add the horoscope text, handling wrapping and pagination const horoscopeLines = doc.splitTextToSize(horoscopeText, maxLineWidth); horoscopeLines.forEach(line => { if (y + 7 > pageHeight - margin) { // Estimate line height + padding doc.addPage(); y = margin; doc.setFontSize(18); doc.setTextColor(52, 58, 64); doc.text("Your Personalized Horoscope (cont.)", margin, y); y += 15; doc.setFontSize(12); doc.setTextColor(52, 58, 64); } // Simple check for bold markdown in PDF (doesn't fully replicate HTML strong) if (line.includes('**') && line.endsWith('**')) { doc.setFont(undefined, 'bold'); // Set font to bold (approximation) doc.text(line.replace(/\*\*/g, ''), margin, y); // Remove markdown doc.setFont(undefined, 'normal'); // Reset font } else { doc.text(line, margin, y); } y += 7; // Estimate line height }); doc.save('personalized_horoscope.pdf'); });

How It Works:

  1. User Inputs: Users select their zodiac sign, enter their date of birth, and choose an area of life they want insights into (e.g., love, career, health).

  2. Horoscope Generation: The tool generates a unique, personalized horoscope based on the user’s inputs.

  3. Results Display: The horoscope is displayed in a visually appealing format, including the zodiac sign, date of birth, area of life, and the generated horoscope.

    Benefits for End Users:

    1. Personalization: Users receive a horoscope tailored to their zodiac sign and specific life area.

    2. Insightful Guidance: The tool provides meaningful and uplifting messages to inspire users.

    3. Shareability: The PDF download feature allows users to save and share their horoscopes easily.

    4. Ease of Use: The tool is simple and intuitive, requiring no technical knowledge.

Scroll to Top