102 lines
4.8 KiB
JavaScript
102 lines
4.8 KiB
JavaScript
document.addEventListener('DOMContentLoaded', function() {
|
|
const uploadForm = document.getElementById('upload-form');
|
|
const analyzeBtn = document.getElementById('analyze-btn');
|
|
const uploadSection = document.getElementById('upload-section');
|
|
const analysisSection = document.getElementById('analysis-section');
|
|
const resumeFileInput = document.getElementById('resume-file');
|
|
|
|
if (uploadForm) {
|
|
uploadForm.addEventListener('submit', function(event) {
|
|
event.preventDefault();
|
|
|
|
if (!resumeFileInput.files || resumeFileInput.files.length === 0) {
|
|
alert('Please select a resume file to analyze.');
|
|
return;
|
|
}
|
|
|
|
const formData = new FormData();
|
|
formData.append('resume', resumeFileInput.files[0]);
|
|
|
|
// Show loading state
|
|
analyzeBtn.disabled = true;
|
|
analyzeBtn.innerHTML = '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> Analyzing...';
|
|
|
|
fetch('analyze.php', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
// Hide loading state
|
|
analyzeBtn.disabled = false;
|
|
analyzeBtn.innerHTML = '<i class="bi bi-magic me-2"></i>Analyze My Resume';
|
|
|
|
if (data.success && data.data) {
|
|
const analysis = data.data;
|
|
|
|
// Update Score and Status
|
|
document.getElementById('ats-score').textContent = analysis.score;
|
|
const scoreCircle = document.querySelector('.score-circle');
|
|
const statusElement = scoreCircle.parentElement.parentElement.querySelector('.fw-semibold');
|
|
statusElement.textContent = analysis.status;
|
|
|
|
if (analysis.score >= 80) {
|
|
statusElement.className = 'fw-semibold text-success';
|
|
} else if (analysis.score >= 60) {
|
|
statusElement.className = 'fw-semibold text-warning';
|
|
} else {
|
|
statusElement.className = 'fw-semibold text-danger';
|
|
}
|
|
|
|
// Update Strengths
|
|
const strengthsList = document.querySelector('#analysis-section .bg-success').parentElement.querySelector('.list-group');
|
|
strengthsList.innerHTML = ''; // Clear existing items
|
|
if (analysis.strengths && analysis.strengths.length > 0) {
|
|
analysis.strengths.forEach(item => {
|
|
const li = document.createElement('li');
|
|
li.className = 'list-group-item';
|
|
li.textContent = item;
|
|
strengthsList.appendChild(li);
|
|
});
|
|
} else {
|
|
const li = document.createElement('li');
|
|
li.className = 'list-group-item';
|
|
li.textContent = 'No specific strengths identified.';
|
|
strengthsList.appendChild(li);
|
|
}
|
|
|
|
// Update Weaknesses
|
|
const weaknessesList = document.querySelector('#analysis-section .bg-warning').parentElement.querySelector('.list-group');
|
|
weaknessesList.innerHTML = ''; // Clear existing items
|
|
if (analysis.weaknesses && analysis.weaknesses.length > 0) {
|
|
analysis.weaknesses.forEach(item => {
|
|
const li = document.createElement('li');
|
|
li.className = 'list-group-item';
|
|
li.textContent = item;
|
|
weaknessesList.appendChild(li);
|
|
});
|
|
} else {
|
|
const li = document.createElement('li');
|
|
li.className = 'list-group-item';
|
|
li.textContent = 'No specific areas for improvement identified.';
|
|
weaknessesList.appendChild(li);
|
|
}
|
|
|
|
// Show the analysis
|
|
uploadSection.style.display = 'none';
|
|
analysisSection.style.display = 'block';
|
|
} else {
|
|
alert('Error: ' + data.message);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
// Hide loading state
|
|
analyzeBtn.disabled = false;
|
|
analyzeBtn.innerHTML = '<i class="bi bi-magic me-2"></i>Analyze My Resume';
|
|
alert('An unexpected error occurred. Please try again.');
|
|
console.error('Error:', error);
|
|
});
|
|
});
|
|
}
|
|
});
|