Greenwashing Detector Tool

Enter inputs and detect greenwashing to see results.

${recommendations}

`; const resultsOutput = document.getElementById('results-output'); if (resultsOutput) { resultsOutput.innerHTML = tableHtml; } // Switch to results tab openTab('results-tab'); }; // Tab Navigation window.openTab = function (tabId) { const tabs = document.querySelectorAll('.tab-content'); const tabLinks = document.querySelectorAll('.tab-link'); tabs.forEach(tab => tab.classList.remove('active')); tabLinks.forEach(link => link.classList.remove('active')); const activeTab = document.getElementById(tabId); if (activeTab) { activeTab.classList.add('active'); const activeLink = document.querySelector(`.tab-link[onclick="openTab('${tabId}')"]`); if (activeLink) activeLink.classList.add('active'); } }; // Download PDF window.downloadPDF = function () { const resultsOutput = document.getElementById('results-output'); const pdfContent = resultsOutput.querySelector('.pdf-content'); if (!resultsOutput || !pdfContent || !pdfContent.querySelector('.results-table')) { alert('No results available to download. Please detect greenwashing first.'); return; } // Extract table data const rows = []; const headers = ['Investment', 'Greenwashing Risk', 'Total Return (USD)', 'Annualized Return (%)']; rows.push(headers.map(header => ({ text: header, style: 'tableHeader' }))); const tableRow = pdfContent.querySelector('.results-table tbody tr'); if (tableRow) { const cells = tableRow.querySelectorAll('td'); const rowData = Array.from(cells).map(cell => ({ text: cell.textContent })); rows.push(rowData); } // Extract risk indicator, discrepancies, and recommendations const riskIndicator = pdfContent.querySelector('.risk-indicator')?.textContent || ''; const discrepancies = pdfContent.querySelector('.discrepancies p')?.innerHTML.replace(/
/g, '\n') || ''; const recommendations = pdfContent.querySelector('.recommendations p')?.textContent || ''; // Define PDF document structure const docDefinition = { content: [ { text: 'Greenwashing Detector Report', style: 'header' }, { text: '\n' }, { text: riskIndicator, style: 'riskIndicator' }, { text: '\n' }, { table: { headerRows: 1, widths: ['*', 'auto', 'auto', 'auto'], body: rows }, layout: { fillColor: function (rowIndex) { return (rowIndex % 2 === 0 && rowIndex > 0) ? '#f2f2f2' : null; }, hLineColor: '#ddd', vLineColor: '#ddd' } }, { text: '\n' }, { text: 'Discrepancies', style: 'subheader' }, { text: discrepancies, style: 'body' }, { text: '\n' }, { text: 'Recommendations', style: 'subheader' }, { text: recommendations, style: 'body' } ], styles: { header: { fontSize: 18, bold: true, alignment: 'center', color: '#333' }, subheader: { fontSize: 14, bold: true, color: '#333' }, riskIndicator: { fontSize: 12, bold: true, alignment: 'center', color: riskIndicator.includes('High') ? '#F44336' : riskIndicator.includes('Medium') ? '#FFC107' : '#4CAF50' }, tableHeader: { bold: true, fontSize: 12, color: 'white', fillColor: '#4CAF50' }, body: { fontSize: 10, color: '#333' } }, defaultStyle: { fontSize: 10, color: '#333' }, pageMargins: [40, 60, 40, 60] }; try { // Generate and download PDF pdfMake.createPdf(docDefinition).download('Greenwashing_Detector_Report.pdf'); } catch (err) { console.error('PDF generation failed:', err); alert('Failed to generate PDF. Please try again.'); } }; });
Scroll to Top