-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
215 lines (183 loc) · 8.17 KB
/
Copy pathscript.js
File metadata and controls
215 lines (183 loc) · 8.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
document.addEventListener('DOMContentLoaded', () => {
// Required Predefined Skills
const predefinedSkills = [
'Python', 'Java', 'C++', 'SQL', 'Machine Learning',
'Data Analysis', 'Power BI', 'Excel', 'TensorFlow',
'Pandas', 'NumPy', 'Git', 'GitHub', 'Communication',
'Teamwork', 'Problem Solving'
];
// DOM Elements
const analyzeBtn = document.getElementById('analyze-btn');
const resumeText = document.getElementById('resume-text');
const scoreText = document.getElementById('score-text');
const progressBar = document.getElementById('progress-bar');
const foundSkillsList = document.getElementById('found-skills-list');
const missingSkillsList = document.getElementById('missing-skills-list');
// PDF Upload Elements
const resumeFile = document.getElementById('resume-file');
const uploadArea = document.getElementById('upload-area');
const uploadLabelSpan = uploadArea.querySelector('span');
// Handle File Selection
resumeFile.addEventListener('change', async (e) => {
const file = e.target.files[0];
if (!file) return;
if (file.type !== 'application/pdf') {
alert('Please upload a valid PDF file.');
return;
}
uploadLabelSpan.textContent = `Selected: ${file.name}`;
// Extract text
try {
analyzeBtn.innerHTML = '<span>Extracting Text...</span> <i class="fa-solid fa-spinner fa-spin"></i>';
analyzeBtn.disabled = true;
const text = await extractTextFromPDF(file);
resumeText.value = text;
analyzeBtn.innerHTML = '<span>Analyze Resume</span> <i class="fa-solid fa-wand-magic-sparkles"></i>';
analyzeBtn.disabled = false;
} catch (error) {
console.error('Error extracting text:', error);
alert('Failed to read the PDF file. Please try pasting the text instead.');
analyzeBtn.innerHTML = '<span>Analyze Resume</span> <i class="fa-solid fa-wand-magic-sparkles"></i>';
analyzeBtn.disabled = false;
uploadLabelSpan.textContent = 'Click to upload PDF or drag & drop';
resumeFile.value = '';
}
});
// Handle Drag & Drop
uploadArea.addEventListener('dragover', (e) => {
e.preventDefault();
uploadArea.classList.add('dragover');
});
uploadArea.addEventListener('dragleave', () => {
uploadArea.classList.remove('dragover');
});
uploadArea.addEventListener('drop', (e) => {
e.preventDefault();
uploadArea.classList.remove('dragover');
if (e.dataTransfer.files.length > 0) {
resumeFile.files = e.dataTransfer.files;
resumeFile.dispatchEvent(new Event('change'));
}
});
// PDF Extraction Function
async function extractTextFromPDF(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = async function () {
try {
const typedarray = new Uint8Array(this.result);
const pdf = await pdfjsLib.getDocument(typedarray).promise;
let fullText = '';
for (let i = 1; i <= pdf.numPages; i++) {
const page = await pdf.getPage(i);
const textContent = await page.getTextContent();
const pageText = textContent.items.map(item => item.str).join(' ');
fullText += pageText + '\n';
}
resolve(fullText);
} catch (error) {
reject(error);
}
};
reader.onerror = reject;
reader.readAsArrayBuffer(file);
});
}
// Event Listener for Analyze Button
analyzeBtn.addEventListener('click', () => {
const text = resumeText.value.trim();
if (!text) {
alert('Please paste some text into the resume area before analyzing.');
return;
}
// Add loading state to button
const originalBtnHTML = analyzeBtn.innerHTML;
analyzeBtn.innerHTML = '<span>Analyzing...</span> <i class="fa-solid fa-spinner fa-spin"></i>';
analyzeBtn.disabled = true;
// Simulate a slight delay for aesthetic UX
setTimeout(() => {
analyzeResume(text);
// Restore button
analyzeBtn.innerHTML = originalBtnHTML;
analyzeBtn.disabled = false;
}, 600);
});
function analyzeResume(text) {
// Lowercase for case-insensitive exact matching
const lowercasedText = text.toLowerCase();
const foundSkills = [];
const missingSkills = [];
// Simple string matching logic
predefinedSkills.forEach(skill => {
if (lowercasedText.includes(skill.toLowerCase())) {
foundSkills.push(skill);
} else {
missingSkills.push(skill);
}
});
// Calculate Score
const totalSkills = predefinedSkills.length;
const scorePercentage = Math.round((foundSkills.length / totalSkills) * 100);
// Update UI Dashboard
updateDashboard(scorePercentage, foundSkills, missingSkills);
}
function updateDashboard(score, found, missing) {
// 1. Animate Progress bar & update Score Text
progressBar.style.width = `${score}%`;
// Dynamic color for progress bar based on score
if (score < 40) {
progressBar.style.background = 'linear-gradient(90deg, #F43F5E, #FB923C)'; // Red to Orange
scoreText.style.background = '-webkit-linear-gradient(right, #F43F5E, #FB923C)';
} else if (score < 75) {
progressBar.style.background = 'linear-gradient(90deg, #F59E0B, #FBBF24)'; // Orange/Yellow
scoreText.style.background = '-webkit-linear-gradient(right, #F59E0B, #FBBF24)';
} else {
progressBar.style.background = 'linear-gradient(90deg, #10B981, #34D399)'; // Green
scoreText.style.background = '-webkit-linear-gradient(right, #10B981, #34D399)';
}
// Ensure webkit text fill is preserved
scoreText.style.webkitBackgroundClip = 'text';
scoreText.style.backgroundClip = 'text';
scoreText.style.webkitTextFillColor = 'transparent';
// Animate numbers counting up
animateValue(scoreText, parseInt(scoreText.innerText) || 0, score, 1000);
// 2. Clear previous lists
foundSkillsList.innerHTML = '';
missingSkillsList.innerHTML = '';
// 3. Render Found Skills
if (found.length === 0) {
foundSkillsList.innerHTML = '<li class="empty-state">No predefined skills found.</li>';
} else {
found.forEach((skill, index) => {
const li = document.createElement('li');
li.innerHTML = `<i class="fa-solid fa-check" style="margin-right: 4px;"></i>${skill}`;
li.style.animationDelay = `${index * 0.05}s`;
foundSkillsList.appendChild(li);
});
}
// 4. Render Missing Skills
if (missing.length === 0) {
missingSkillsList.innerHTML = '<li class="empty-state">Perfect! All predefined skills found.</li>';
} else {
missing.forEach((skill, index) => {
const li = document.createElement('li');
li.innerHTML = `<i class="fa-solid fa-xmark" style="margin-right: 4px;"></i>${skill}`;
li.style.animationDelay = `${index * 0.05}s`;
missingSkillsList.appendChild(li);
});
}
}
// Quick counter animation function
function animateValue(obj, start, end, duration) {
let startTimestamp = null;
const step = (timestamp) => {
if (!startTimestamp) startTimestamp = timestamp;
const progress = Math.min((timestamp - startTimestamp) / duration, 1);
obj.innerHTML = Math.floor(progress * (end - start) + start) + '%';
if (progress < 1) {
window.requestAnimationFrame(step);
}
};
window.requestAnimationFrame(step);
}
});