Air Quality Index (AQI) & Respiratory Risk Tool

Air Quality Index (AQI) & Respiratory Risk Tool

Enter Your Location

Enter a city and state (USA) to generate a simulated AQI forecast.

Enter a location on the previous tab to see your AQI forecast.

Main Pollutant: ${day.pollutant}

${day.details.advice}

`; }); forecastHTML += `

This is a simulated forecast for demonstration purposes only. It is not a substitute for official air quality data or medical advice.

`; forecastResultsContainer.innerHTML = forecastHTML; forecastPlaceholder.style.display = 'none'; document.getElementById('pdf-download-btn').addEventListener('click', () => downloadPdf(data)); }; /** * Generates and downloads the PDF report. * @param {object} data - The forecast data to be included in the PDF. */ const downloadPdf = async (data) => { let pdfHTML = `

Air Quality & Risk Report

For: ${data.location}

`; data.forecast.forEach(day => { pdfHTML += `

${day.dayName}

${day.dateString}

${day.aqi}

${day.details.name}

Main Pollutant: ${day.pollutant}

${day.details.advice}

`; }); pdfHTML += `

This report was generated for informational purposes only and is not a substitute for official data or medical advice.

`; pdfContentContainer.innerHTML = pdfHTML; pdfContentContainer.classList.remove('hidden'); pdfContentContainer.style.position = 'absolute'; pdfContentContainer.style.left = '-9999px'; try { const { jsPDF } = window.jspdf; const canvas = await html2canvas(pdfContentContainer, { scale: 2, useCORS: true }); const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'portrait', unit: 'mm', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = (canvas.height * pdfWidth) / canvas.width; pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight); pdf.save(`AQI-Forecast-${data.location.replace(/, /g, '-')}.pdf`); } catch (error) { console.error("Failed to generate PDF:", error); } finally { pdfContentContainer.classList.add('hidden'); pdfContentContainer.style.position = ''; pdfContentContainer.style.left = ''; } }; // --- EVENT LISTENERS --- getForecastBtn.addEventListener('click', () => { if (locationInput.value.trim() === '') { locationError.classList.remove('hidden'); } else { locationError.classList.add('hidden'); const forecastData = generateSimulatedAQI(); displayForecast(forecastData); tabBtn2.disabled = false; changeTab(2); } }); tabBtn1.addEventListener('click', () => changeTab(1)); tabBtn2.addEventListener('click', () => { if (!tabBtn2.disabled) { changeTab(2); } }); });
Scroll to Top