Error:
City not found. Please try another location.
Loading...
--:-- --
--°
------
Feels Like
--°
Humidity
--%
Wind Speed
-- km/h
Pressure
-- hPa
5-Day Forecast
${day.day}
${weatherIcons[day.icon] || weatherIcons['cloud']}
${day.high}° / ${day.low}°
`; forecastGrid.appendChild(forecastItem); }); } function showLoading() { document.getElementById('location-name').textContent = 'Loading...'; } function showError() { document.getElementById('error-message').classList.remove('hidden'); } function hideError() { document.getElementById('error-message').classList.add('hidden'); } // --- EVENT HANDLERS & GLOBAL FUNCTIONS --- async function handleSearch(city) { hideError(); showLoading(); try { const data = await getWeatherData(city); updateUI(city, data); } catch (error) { showError(); } } document.getElementById('search-form').addEventListener('submit', (e) => { e.preventDefault(); const city = document.getElementById('city-input').value; if (city) { handleSearch(city); } }); window.downloadPDF = async () => { const { jsPDF } = window.jspdf; const content = document.getElementById('pdf-content'); try { const canvas = await html2canvas(content, { scale: 2, useCORS: true, backgroundColor: '#ffffff' }); const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'portrait', unit: 'px', format: [canvas.width, canvas.height] }); pdf.addImage(imgData, 'PNG', 0, 0, canvas.width, canvas.height); const locationName = document.getElementById('location-name').textContent.replace(/, /g, '_'); pdf.save(`Weather_Report_${locationName}.pdf`); } catch (error) { console.error('Error generating PDF:', error); } }; // --- INITIALIZATION --- const initialCity = "Pirganj, Bangladesh"; document.getElementById('city-input').value = initialCity; handleSearch(initialCity); });