AI-Powered Insider Trading Signal Detector
Potential Insider Trading Signals:
Signals will appear here after detection.
Analyzing data with AI...
×
Error: Could not retrieve AI analysis. Please try again.
'; console.error('Unexpected AI response structure:', result); } } catch (error) { console.error('Error detecting signals:', error); detectionResultsDiv.innerHTML = 'An error occurred during signal detection. Please try again later.
'; showAlertModal('An error occurred during signal detection. Please check your network connection and try again.'); } finally { // Hide loading indicator loadingIndicator.classList.add('hidden'); } }; // Helper function to format AI analysis into a readable list function formatAiAnalysis(text) { // Assuming the AI returns a list, convert newlines to list items const lines = text.split('\n').filter(line => line.trim() !== ''); if (lines.length === 0) { return 'No specific signals detected based on the provided information.
'; } const ul = document.createElement('ul'); ul.className = 'list-disc list-inside space-y-2'; lines.forEach(line => { const li = document.createElement('li'); li.textContent = line.replace(/^- /, ''); // Remove leading dash if present ul.appendChild(li); }); return ul.outerHTML; } // Function to generate and download PDF window.generatePdf = async function() { const toolContainer = document.getElementById('detector-tool-container'); const outputSection = document.getElementById('output-section'); // Temporarily show the output section if it's hidden for PDF generation const wasOutputHidden = outputSection.classList.contains('hidden'); if (wasOutputHidden) { outputSection.classList.remove('hidden'); // Ensure the tab button for output is active for PDF capture if it was a tabbed view outputTab.classList.add('active'); inputSection.classList.add('hidden'); // Hide input section inputTab.classList.remove('active'); // Deactivate input tab } // Hide irrelevant elements for PDF (e.g., tab buttons, detect button) const originalDisplayTabButtons = document.querySelector('.tab-buttons').style.display; document.querySelector('.tab-buttons').style.display = 'none'; const originalDisplayDetectButton = document.querySelector('.primary').style.display; document.querySelector('.primary').style.display = 'none'; const originalDisplayDownloadButton = document.querySelector('.secondary').style.display; document.querySelector('.secondary').style.display = 'none'; const originalDisplayLoading = loadingIndicator.style.display; loadingIndicator.style.display = 'none'; // Scroll to top of the tool container for better PDF capture toolContainer.scrollIntoView({ behavior: 'smooth', block: 'start' }); try { const canvas = await html2canvas(toolContainer, { scale: 2, // Increase scale for better resolution useCORS: true, // Required if images are from external sources windowWidth: toolContainer.scrollWidth, windowHeight: toolContainer.scrollHeight }); const imgData = canvas.toDataURL('image/png'); const pdf = new window.jspdf.jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' }); const imgWidth = pdf.internal.pageSize.getWidth(); const pageHeight = pdf.internal.pageSize.getHeight(); const imgHeight = (canvas.height * imgWidth) / canvas.width; let heightLeft = imgHeight; let position = 0; pdf.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight); heightLeft -= pageHeight; while (heightLeft >= 0) { position = heightLeft - imgHeight; pdf.addPage(); pdf.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight); heightLeft -= pageHeight; } pdf.save('InsiderTradingSignals.pdf'); } catch (error) { console.error('Error generating PDF:', error); showAlertModal('Failed to generate PDF. Please try again.'); } finally { // Restore original display styles document.querySelector('.tab-buttons').style.display = originalDisplayTabButtons; document.querySelector('.primary').style.display = originalDisplayDetectButton; document.querySelector('.secondary').style.display = originalDisplayDownloadButton; loadingIndicator.style.display = originalDisplayLoading; // Restore tab visibility if it was changed if (wasOutputHidden) { outputSection.classList.add('hidden'); inputSection.classList.remove('hidden'); inputTab.classList.add('active'); outputTab.classList.remove('active'); } } }; });