Alternate History Generator
Explore the 'what ifs' of the past by changing a single moment in time.
Generated Timeline:
Please make a selection for all three options to generate a scenario.
`; resultsContainer.style.display = 'block'; pdfButtonContainer.style.display = 'none'; return; } const scenarioData = historicalData[eraKey].pointsOfDivergence[podKey].changes[changeKey]; scenarioOutput.innerHTML = `${scenarioData.outcome}
`; resultsContainer.style.display = 'block'; pdfButtonContainer.style.display = 'block'; } function downloadPDF() { try { const { jsPDF } = window.jspdf; const doc = new jsPDF(); const eraKey = eraSelect.value; const podKey = podSelect.value; const changeKey = changeSelect.value; const eraName = historicalData[eraKey].name; const podName = historicalData[eraKey].pointsOfDivergence[podKey].name; const changeName = historicalData[eraKey].pointsOfDivergence[podKey].changes[changeKey].name; const outcomeText = historicalData[eraKey].pointsOfDivergence[podKey].changes[changeKey].outcome; const pageHeight = doc.internal.pageSize.getHeight(); const pageWidth = doc.internal.pageSize.getWidth(); const margin = 15; let cursorY = margin; // --- PDF Header --- doc.setFont('times', 'bold'); doc.setFontSize(18); doc.setTextColor(41, 32, 25); // Darker Brown doc.text('HISTORICAL DIVERGENCE ANALYSIS', pageWidth / 2, cursorY, { align: 'center' }); cursorY += 8; doc.setFont('times', 'normal'); doc.setFontSize(10); doc.setTextColor(150); doc.text(`DOCUMENT GENERATED: ${new Date().toUTCString()}`, pageWidth / 2, cursorY, { align: 'center' }); cursorY += 10; doc.setDrawColor(92, 64, 51); // Brown doc.setLineWidth(0.5); doc.line(margin, cursorY, pageWidth - margin, cursorY); cursorY += 12; // --- Parameters Table --- doc.autoTable({ startY: cursorY, head: [['PARAMETER', 'SPECIFICATION']], body: [ ['HISTORICAL ERA:', eraName], ['POINT OF DIVERGENCE:', podName], ['CRITICAL CHANGE:', changeName] ], theme: 'grid', headStyles: { fillColor: [92, 64, 51], font: 'times', fontStyle: 'bold' }, bodyStyles: { font: 'times' }, columnStyles: { 0: { fontStyle: 'bold', cellWidth: 60 } } }); cursorY = doc.previousAutoTable.finalY + 15; // --- Scenario Synopsis --- doc.setFont('times', 'bold'); doc.setFontSize(14); doc.setTextColor(41, 32, 25); doc.text('PROJECTED OUTCOME:', margin, cursorY); cursorY += 8; doc.setFont('times', 'normal'); doc.setFontSize(12); doc.setTextColor(30, 30, 30); const textLines = doc.splitTextToSize(outcomeText, pageWidth - margin * 2); doc.text(textLines, margin, cursorY); // --- Footer --- const pageCount = doc.internal.getNumberOfPages(); for (let i = 1; i <= pageCount; i++) { doc.setPage(i); doc.setFontSize(9); doc.setTextColor(150); const footerText = `Page ${i} of ${pageCount} | Alternate Timeline Analysis`; doc.text(footerText, pageWidth / 2, pageHeight - 10, { align: 'center' }); } doc.save('Alternate_History_Scenario.pdf'); } catch (error) { console.error("Failed to generate PDF:", error); if (pdfButtonContainer && !pdfButtonContainer.querySelector('.error-msg')) { const errorMsg = document.createElement('p'); errorMsg.textContent = 'Sorry, the PDF could not be created.'; errorMsg.className = 'text-red-600 text-sm mt-2 error-msg'; pdfButtonContainer.appendChild(errorMsg); } } } // Event Listeners eraSelect.addEventListener('change', updatePodSelect); podSelect.addEventListener('change', updateChangeSelect); generateButton.addEventListener('click', generateScenario); downloadPdfButton.addEventListener('click', downloadPDF); // Initial setup populateEraSelect(); });