/* ── SUPERCHARGED AI SMART EXTRACTOR LOGIC ── */ $("#qja-ai-extract-btn").on("click", function(e){ e.preventDefault(); var text = $("#qja-ai-paste").val(); var $btn = $(this); var $status = $("#qja-ai-status"); if(text.trim().length < 10) { $status.html("⚠️ Please paste valid notification text first.").css("color", "#d97706"); return; } $btn.text("⏳ Scanning..."); $status.html(""); setTimeout(function(){ var updates = 0; // 0. Clean the text: Replace line breaks with spaces so sentences don't break in half var cleanText = text.replace(/[\r\n]+/g, " ").replace(/\s{2,}/g, " "); // 1. Total Vacancies (Catches "Total Posts: 50" OR "50 Vacancies") var matchVac = cleanText.match(/(?:vacancies|posts|openings|no\.?\s+of\s+post|total).{0,30}?[:\-]?\s*(\d{1,5})\b/i); if(!matchVac) matchVac = cleanText.match(/\b(\d{1,5})\s+(?:vacancies|posts|openings)/i); if(matchVac && matchVac[1] && parseInt(matchVac[1]) < 90000) { fillField("total_vacancies", matchVac[1]); updates++; } // 2. Post Name (Catches "Name of the post: Clerk" OR "Recruitment for Clerk post") var matchPost = cleanText.match(/(?:name\s+of\s+(?:the\s+)?post|post\s+name|designation|post|title)\s*[:\-]\s*([A-Za-z0-9\s\(\)\-\,\&]{4,60})(?:\.|\n|;|$)/i); if(!matchPost) matchPost = cleanText.match(/(?:recruitment|opening)\s+(?:for|of)\s+([A-Za-z0-9\s\(\)\-\,\&]{4,60})\s+(?:post|vacancy)/i); if(matchPost && matchPost[1]) { fillField("post_name", matchPost[1].trim()); updates++; } // 3. Qualification var matchEdu = cleanText.match(/(?:educational\s+qualification|qualification|education|eligibility)\s*[:\-]?\s*([A-Za-z0-9\s\(\)\-\,\.\/]{4,80})(?:\.|\n|;|$)/i); if(!matchEdu) matchEdu = cleanText.match(/\b(10th|12th|ITI|Diploma|B\.?Tech|B\.?E|B\.?Sc|B\.?A|B\.?Com|M\.?Tech|Any Degree|Graduation)\b/i); if(matchEdu && matchEdu[1]) { fillField("education", matchEdu[1].trim()); updates++; } // 4. Age Limit var matchAge = cleanText.match(/(?:age\s+limit|age)\s*[:\-]?\s*(?:between\s+)?(\d{2}\s*(?:to|-|–|and)\s*\d{2}\s*(?:years|yrs)?)/i); if(!matchAge) matchAge = cleanText.match(/(?:maximum|max)\s+age.{0,15}?(\d{2})\s*(?:years|yrs)/i); if(matchAge) { fillField("age_limit", matchAge[1].trim()); updates++; } // 5. Advertisement Number var matchAdvt = cleanText.match(/(?:advt\.?\s*no\.?|advertisement\s*no\.?|notification\s*no\.?)\s*[:\-]?\s*([A-Za-z0-9\/\-\_]+)/i); if(matchAdvt && matchAdvt[1]) { fillField("advertisement_no", matchAdvt[1].trim()); updates++; } // 6. Apply Mode var lowerText = cleanText.toLowerCase(); if(lowerText.indexOf("walk-in") !== -1 || lowerText.indexOf("walk in") !== -1) { setMode("walkin"); updates++; } else if (lowerText.indexOf("apply offline") !== -1 || lowerText.indexOf("send application") !== -1 || lowerText.indexOf("postal address") !== -1) { setMode("offline"); updates++; } else if (lowerText.indexOf("apply online") !== -1) { setMode("online"); updates++; } // 7. Salary (Catches ranges like "10000 to 20000" OR single like "Rs 25000") var matchSalRange = cleanText.match(/(?:rs\.?|inr|₹|pay|salary|remuneration|stipend).{0,25}?([\d,]{4,7})\s*(?:to|-|–|and)\s*(?:rs\.?|inr|₹)?\s*([\d,]{4,7})/i); if(matchSalRange) { fillField("min_salary", matchSalRange[1].replace(/,/g,"")); fillField("max_salary", matchSalRange[2].replace(/,/g,"")); updates++; } else { var matchSalSingle = cleanText.match(/(?:rs\.?|inr|₹|pay|salary|remuneration|stipend).{0,20}?[:\-]?\s*(?:rs\.?|inr|₹)?\s*([\d,]{4,7})/i); if(matchSalSingle) { fillField("min_salary", matchSalSingle[1].replace(/,/g,"")); updates++; } } // 8. Last Date var matchDate = cleanText.match(/(?:last\s*date|closing\s*date|apply\s*before|deadline)\s*[:\-]?\s*(\d{1,2}[\/\-\.]\d{1,2}[\/\-\.]\d{2,4})/i); if(matchDate && matchDate[1]) { var cleanDate = matchDate[1].replace(/[\-\.]/g, "/"); fillField("last_date", cleanDate); updates++; } if(updates > 0) { $status.html("✅ " + updates + " fields extracted and filled!").css("color", "#16a34a"); buildYoastPreview(); } else { $status.html("⚠️ Could not find exact matches. Format might be unusual.").css("color", "#d97706"); } $btn.text("✨ Extract with AI"); }, 500); });