Fictional Space Mission Simulator
Generate a summary for a fictional journey through the cosmos!
Your fictional space mission summary will appear here!
Error: ${missionSummary.missionName}
${missionSummary.journey}
// Display error detailsEvents: ${missionSummary.events.join('. ')}
Outcome: ${missionSummary.outcome}
`; downloadBtn.style.display = 'none'; // Ensure button stays hidden on error } else { resultsDiv.innerHTML = `Mission Name: ${missionSummary.missionName}
Mission Goal: ${missionSummary.missionGoal}
Ship: ${missionSummary.ship}
Crew: ${missionSummary.crew}
Journey & Destination: ${missionSummary.journey}
Events Encountered: ${missionSummary.events.join('. ')}
Mission Outcome: ${missionSummary.outcome}
`; downloadPdfBtn.style.display = 'block'; // Show download button only on success } }); document.getElementById('clearBtn').addEventListener('click', () => { document.getElementById('missionGoal').value = 'any'; document.getElementById('shipType').value = 'any'; document.getElementById('destinationType').value = 'any'; document.getElementById('primaryChallenge').value = 'any'; document.getElementById('outcomeStyle').value = 'successful'; document.getElementById('missionKeyword').value = ''; document.getElementById('missionResults').innerHTML = 'Your fictional space mission summary will appear here!
'; document.getElementById('downloadPdfBtn').style.display = 'none'; // Hide PDF button }); // Download PDF Button document.getElementById('downloadPdfBtn').addEventListener('click', () => { const resultsDiv = document.getElementById('missionResults'); // Check if results are error message before attempting to get summary text if (resultsDiv.textContent.includes("Error:") || resultsDiv.textContent.includes('Your fictional space mission summary will appear here!')) { alert("No mission summary to download."); return; } const missionNameText = resultsDiv.querySelector('p:nth-child(1)') ? resultsDiv.querySelector('p:nth-child(1)').textContent.replace('Mission Name: ', '').trim() : ''; const missionGoalText = resultsDiv.querySelector('p:nth-child(2)') ? resultsDiv.querySelector('p:nth-child(2)').textContent.replace('Mission Goal: ', '').trim() : ''; const shipText = resultsDiv.querySelector('p:nth-child(3)') ? resultsDiv.querySelector('p:nth-child(3)').textContent.replace('Ship: ', '').trim() : ''; const crewText = resultsDiv.querySelector('p:nth-child(4)') ? resultsDiv.querySelector('p:nth-child(4)').textContent.replace('Crew: ', '').trim() : ''; const journeyText = resultsDiv.querySelector('p:nth-child(5)') ? resultsDiv.querySelector('p:nth-child(5)').textContent.replace('Journey & Destination: ', '').trim() : ''; const eventsText = resultsDiv.querySelector('p:nth-child(6)') ? resultsDiv.querySelector('p:nth-child(6)').textContent.replace('Events Encountered: ', '').trim() : ''; const outcomeText = resultsDiv.querySelector('p:nth-child(7)') ? resultsDiv.querySelector('p:nth-child(7)').textContent.replace('Mission Outcome: ', '').trim() : ''; if (!missionNameText) { // Should not happen if check passed, but for safety alert("No mission summary 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("Fictional Space Mission Summary", margin, y); y += 15; // Space after title doc.setFontSize(12); doc.setTextColor(52, 58, 64); // Match text-color variable #343a0 // Add Mission Name doc.setFontSize(14); doc.text("Mission Name:", margin, y); y += 8; doc.setFontSize(12); doc.text(doc.splitTextToSize(missionNameText, maxLineWidth), margin, y); y += (doc.splitTextToSize(missionNameText, maxLineWidth).length * 7) + 10; // Add Mission Goal doc.setFontSize(14); doc.text("Mission Goal:", margin, y); y += 8; doc.setFontSize(12); const goalLines = doc.splitTextToSize(missionGoalText, maxLineWidth); doc.text(goalLines, margin, y); y += (goalLines.length * 7) + 10; // Add Ship doc.setFontSize(14); doc.text("Ship:", margin, y); y += 8; doc.setFontSize(12); const shipLines = doc.splitTextToSize(shipText, maxLineWidth); doc.text(shipLines, margin, y); y += (shipLines.length * 7) + 10; // Add Crew doc.setFontSize(14); doc.text("Crew:", margin, y); y += 8; doc.setFontSize(12); const crewLines = doc.splitTextToSize(crewText, maxLineWidth); doc.text(crewLines, margin, y); y += (crewLines.length * 7) + 10; // Add Journey doc.setFontSize(14); doc.text("Journey & Destination:", margin, y); y += 8; doc.setFontSize(12); const journeyLines = doc.splitTextToSize(journeyText, maxLineWidth); doc.text(journeyLines, margin, y); y += (journeyLines.length * 7) + 10; // Add Events doc.setFontSize(14); doc.text("Events Encountered:", margin, y); y += 8; doc.setFontSize(12); const eventsLines = doc.splitTextToSize(eventsText, maxLineWidth); eventsLines.forEach(line => { if (y + 7 > pageHeight - margin) { doc.addPage(); y = margin; } doc.text(line, margin, y); y += 7; }); y += 10; // Add Outcome doc.setFontSize(14); doc.text("Mission Outcome:", margin, y); y += 8; doc.setFontSize(12); const outcomeLines = doc.splitTextToSize(outcomeText, maxLineWidth); outcomeLines.forEach(line => { if (y + 7 > pageHeight - margin) { doc.addPage(); y = margin; } doc.text(line, margin, y); y += 7; }); y += 10; doc.save('space_mission_summary.pdf'); });Key Features:
Customizable Mission Details: Users can input mission name, destination, and crew size to simulate a unique space mission.
AI-Generated Mission Report: The tool generates a detailed and imaginative mission report based on user inputs.
Centered Design: The tool is perfectly centered on the page, ensuring a clean and professional look.
PDF Download: Users can download the mission report as a PDF, complete with the same color scheme for consistency.
Benefits for End Users:
Immersive Experience: Users can simulate and explore fictional space missions, sparking their imagination and curiosity.
Educational Tool: Great for students, educators, and space enthusiasts to learn about space exploration concepts.
Creative Outlet: Writers and storytellers can use the tool to generate ideas for sci-fi stories or projects.
Portable Results: The PDF download feature allows users to save and share their mission reports easily.
