Auto-deploy: 2026-05-25 23:27:04
This commit is contained in:
93
popup.js
93
popup.js
@@ -169,6 +169,99 @@ document.getElementById('clear-all-btn').addEventListener('click', () => {
|
||||
}
|
||||
});
|
||||
|
||||
// ─── Autofill Functionality ──────────────────────────────────────────────────
|
||||
|
||||
function parseProfileText(text) {
|
||||
const emailRegex = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/;
|
||||
const phoneRegex = /\+?[0-9]{1,4}[ \t.-]?[0-9]{3,4}[ \t.-]?[0-9]{3,4}/;
|
||||
const linkedinRegex = /(https?:\/\/)?(www\.)?linkedin\.com\/in\/[a-zA-Z0-9_-]+/;
|
||||
const githubRegex = /(https?:\/\/)?(www\.)?github\.com\/[a-zA-Z0-9_-]+/;
|
||||
|
||||
const emailMatch = text.match(emailRegex);
|
||||
const phoneMatch = text.match(phoneRegex);
|
||||
const linkedinMatch = text.match(linkedinRegex);
|
||||
const githubMatch = text.match(githubRegex);
|
||||
|
||||
// Extract Name (first line usually)
|
||||
const lines = text.split('\n').map(l => l.trim()).filter(Boolean);
|
||||
let fullName = "Hamza Ayed";
|
||||
if (lines.length > 0) {
|
||||
const firstLine = lines[0].replace(/—.*/, '').replace(/:.*/, '').trim();
|
||||
fullName = firstLine;
|
||||
}
|
||||
|
||||
const nameParts = fullName.split(' ');
|
||||
const firstName = nameParts[0] || "";
|
||||
const lastName = nameParts.slice(1).join(' ') || "";
|
||||
|
||||
// Extract Summary
|
||||
let summary = "";
|
||||
const summaryIdx = text.toLowerCase().indexOf("summary:");
|
||||
if (summaryIdx !== -1) {
|
||||
const skillsIdx = text.toLowerCase().indexOf("core skills:", summaryIdx);
|
||||
if (skillsIdx !== -1) {
|
||||
summary = text.substring(summaryIdx + 8, skillsIdx).trim();
|
||||
} else {
|
||||
summary = text.substring(summaryIdx + 8, summaryIdx + 500).trim();
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
fullName,
|
||||
firstName,
|
||||
lastName,
|
||||
email: emailMatch ? emailMatch[0] : "",
|
||||
phone: phoneMatch ? phoneMatch[0] : "",
|
||||
linkedin: linkedinMatch ? linkedinMatch[0] : "",
|
||||
github: githubMatch ? githubMatch[0] : "",
|
||||
summary,
|
||||
cvText: text
|
||||
};
|
||||
}
|
||||
|
||||
document.getElementById('autofill-btn').addEventListener('click', async () => {
|
||||
const userProfile = document.getElementById('profile-textarea').value.trim();
|
||||
if (!userProfile) {
|
||||
showToast('⚠️ Please enter profile info first', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
const profileData = parseProfileText(userProfile);
|
||||
|
||||
try {
|
||||
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
|
||||
if (!tab) {
|
||||
showToast('❌ No active tab found', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the profile data on the tab window context
|
||||
await chrome.scripting.executeScript({
|
||||
target: { tabId: tab.id },
|
||||
func: (data) => {
|
||||
window.__autofillProfileData = data;
|
||||
},
|
||||
args: [profileData]
|
||||
});
|
||||
|
||||
// Execute the filler script
|
||||
const results = await chrome.scripting.executeScript({
|
||||
target: { tabId: tab.id },
|
||||
files: ['filler.js']
|
||||
});
|
||||
|
||||
if (results && results[0]) {
|
||||
showToast('✨ ' + results[0].result, 'success');
|
||||
} else {
|
||||
showToast('✨ Autofill completed!', 'success');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
showToast('❌ Error: ' + e.message, 'error');
|
||||
}
|
||||
});
|
||||
|
||||
// ─── Init ────────────────────────────────────────────────────────────────────
|
||||
|
||||
loadSettings();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user