Commodities Price Tracker

Commodities Price Tracker

Market Overview

Commodity Unit Price (USD) Change % Change

${formatPriceChange(item.change, 'price')} (${formatPriceChange(item.percentChange, 'percent')})

`; elements.keyCommodities.appendChild(card); } // Render table rows const row = document.createElement('tr'); row.className = 'bg-white border-b'; row.innerHTML = ` ${item.name} ${item.unit} $${item.price.toFixed(2)} ${formatPriceChange(item.change, 'price')} ${formatPriceChange(item.percentChange, 'percent')} `; elements.tableBody.appendChild(row); }); }; async function downloadPDF() { const contentToPrint = document.getElementById('pdf-content'); if (!contentToPrint) return; if (typeof window.jspdf === 'undefined' || typeof window.html2canvas === 'undefined') { console.error("PDF generation library is not available."); return; } try { const { jsPDF } = window.jspdf; const pdfCanvas = await html2canvas(contentToPrint, { scale: 2 }); const imgData = pdfCanvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = (pdfCanvas.height * pdfWidth) / pdfCanvas.width; pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight); pdf.save('commodities-report.pdf'); } catch(err) { console.error("PDF generation failed:", err); } } // Set current time based on user prompt const now = new Date('2025-09-11T11:43:00+06:00'); elements.currentTime.textContent = `As of ${now.toLocaleString('en-US', { dateStyle: 'full', timeStyle: 'short' })}`; elements.pdfBtn.addEventListener('click', downloadPDF); // Initial Render renderData(); });
Scroll to Top