Chemically-motivated/PythonCodeAssistantProject
0
1// Reference the elements that we will need2const status = document.getElementById('status');3const codeInput = document.getElementById('codeInput');4const resultsContainer = document.getElementById('results');5const analyzeButton = document.querySelector('button');6 7// Set initial status8status.textContent = 'Ready to analyze code';9 10// Event listener for the analyze button11analyzeButton.addEventListener('click', async () => {12 const code = codeInput.value.trim();13 if (!code) {14 status.textContent = 'Please enter some Python code.';15 return;16 }17 18 status.textContent = 'Analyzing...';19 20 try {21 const response = await fetch('/analyze', {22 method: 'POST',23 headers: { 'Content-Type': 'application/json' },24 body: JSON.stringify({ code })25 });26 27 if (!response.ok) {28 throw new Error('Failed to analyze code');29 }30 31 const result = await response.json();32 displayResults(result);33 status.textContent = 'Analysis complete';34 } catch (error) {35 status.textContent = 'Error analyzing code';36 console.error(error);37 }38});39 40// Function to display the results41function displayResults(results) {42 resultsContainer.innerHTML = '';43 44 const preElement = document.createElement('pre');45 preElement.textContent = JSON.stringify(results, null, 2);46 47 resultsContainer.appendChild(preElement);48}49 