Auto-deploy: 2026-05-17 02:14:05
This commit is contained in:
98
content.js
98
content.js
@@ -567,6 +567,13 @@
|
||||
analyzeBtn.disabled = true;
|
||||
|
||||
try {
|
||||
if (tab === 'qa') {
|
||||
const freshData = extractApplicationQuestions();
|
||||
if (freshData.length > 0) {
|
||||
jobData.questions = freshData;
|
||||
}
|
||||
}
|
||||
|
||||
const prompt = buildPromptV2(tab, jobData, settings.userProfile, settings.language);
|
||||
const response = await chrome.runtime.sendMessage({
|
||||
type: 'GEMINI_REQUEST',
|
||||
@@ -749,6 +756,25 @@ Brief honest assessment of this opportunity for my profile`
|
||||
// ─── Markdown Renderer ───────────────────────────────────────────────────
|
||||
|
||||
function renderMarkdown(text) {
|
||||
try {
|
||||
const startIdx = text.indexOf('{');
|
||||
const endIdx = text.lastIndexOf('}');
|
||||
if (startIdx !== -1 && endIdx !== -1) {
|
||||
const parsed = JSON.parse(text.substring(startIdx, endIdx + 1));
|
||||
let html = '<div style="display:flex;flex-direction:column;gap:12px;">';
|
||||
for (const [q, a] of Object.entries(parsed)) {
|
||||
html += `<div style="background: rgba(255,255,255,0.05); padding: 10px; border-radius: 6px;">
|
||||
<div style="font-weight: 600; font-size: 13px; color: #fff; margin-bottom: 4px;">❓ ${q}</div>
|
||||
<div style="color: #4caf50; font-size: 13px;">💡 ${a}</div>
|
||||
</div>`;
|
||||
}
|
||||
html += '</div>';
|
||||
return html;
|
||||
}
|
||||
} catch(e) {
|
||||
// Not JSON, continue to normal markdown rendering
|
||||
}
|
||||
|
||||
return text
|
||||
.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
||||
.replace(/^## (.+)$/gm, '<h3>$1</h3>')
|
||||
@@ -766,25 +792,77 @@ Brief honest assessment of this opportunity for my profile`
|
||||
|
||||
function autoFillAnswers(qaText, root) {
|
||||
showPanelToast(root, '🔄 Attempting to fill answers...');
|
||||
// Parse numbered answers from AI response
|
||||
const answerLines = qaText.split('\n');
|
||||
const inputs = document.querySelectorAll('.jobs-easy-apply-content input[type="text"], .jobs-easy-apply-content textarea');
|
||||
let answers = {};
|
||||
try {
|
||||
const startIndex = qaText.indexOf('{');
|
||||
const endIndex = qaText.lastIndexOf('}');
|
||||
if (startIndex !== -1 && endIndex !== -1) {
|
||||
answers = JSON.parse(qaText.substring(startIndex, endIndex + 1));
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to parse AI answers JSON:', e);
|
||||
}
|
||||
|
||||
if (Object.keys(answers).length === 0) {
|
||||
showPanelToast(root, '⚠️ Could not parse answers. Please copy manually.');
|
||||
return;
|
||||
}
|
||||
|
||||
let filled = 0;
|
||||
inputs.forEach((input, idx) => {
|
||||
const answerLine = answerLines.find(l => l.match(new RegExp(`^${idx + 1}\\.`)));
|
||||
if (answerLine) {
|
||||
const answer = answerLine.replace(/^\d+\.\s*/, '').trim();
|
||||
if (answer) {
|
||||
input.value = answer;
|
||||
const labels = document.querySelectorAll('.jobs-easy-apply-content label, .jobs-easy-apply-content legend, .jobs-easy-apply-content .fb-dash-form-element__label');
|
||||
|
||||
labels.forEach(label => {
|
||||
const qText = label.textContent.trim().toLowerCase();
|
||||
if (!qText) return;
|
||||
|
||||
const matchedKey = Object.keys(answers).find(k => {
|
||||
const kLower = k.toLowerCase();
|
||||
return kLower.includes(qText) || qText.includes(kLower);
|
||||
});
|
||||
|
||||
if (matchedKey && answers[matchedKey]) {
|
||||
const parent = label.closest('.fb-dash-form-element') || label.parentElement;
|
||||
const answerVal = String(answers[matchedKey]);
|
||||
|
||||
// 1. Fill Text inputs / Textareas
|
||||
const input = parent.querySelector('input[type="text"], textarea');
|
||||
if (input) {
|
||||
input.value = answerVal;
|
||||
input.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
input.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
filled++;
|
||||
}
|
||||
|
||||
// 2. Select dropdowns
|
||||
const select = parent.querySelector('select');
|
||||
if (select) {
|
||||
const options = Array.from(select.options);
|
||||
const matchedOpt = options.find(o => o.text.toLowerCase() === answerVal.toLowerCase() || o.value.toLowerCase() === answerVal.toLowerCase() || o.text.toLowerCase().includes(answerVal.toLowerCase()));
|
||||
if (matchedOpt) {
|
||||
select.value = matchedOpt.value;
|
||||
select.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
filled++;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Radio Buttons (Yes/No)
|
||||
const radios = parent.querySelectorAll('input[type="radio"]');
|
||||
if (radios.length > 0) {
|
||||
let radioClicked = false;
|
||||
radios.forEach(radio => {
|
||||
const radioLabel = radio.parentElement.textContent.trim().toLowerCase();
|
||||
const aLower = answerVal.toLowerCase();
|
||||
if (radioLabel === aLower || (aLower === 'yes' && radioLabel.includes('yes')) || (aLower === 'no' && radioLabel.includes('no'))) {
|
||||
radio.click();
|
||||
radioClicked = true;
|
||||
}
|
||||
});
|
||||
if (radioClicked) filled++;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
showPanelToast(root, filled > 0 ? `✅ Filled ${filled} fields` : '⚠️ Could not auto-fill. Copy answers manually.');
|
||||
showPanelToast(root, filled > 0 ? `✅ Filled ${filled} fields` : '⚠️ No matching fields found to auto-fill.');
|
||||
}
|
||||
|
||||
// ─── Utilities ───────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user