(function(){(function(){var n=window.CoverLetterGen;if(!n||!n.fieldFiller||!n.storage)return;var f="fillydash-ashby-autofill-btn";function m(e){if(!e)return!1;if(e.offsetParent!==null)return!0;var r=window.getComputedStyle(e);if(r.display==="none"||r.visibility==="hidden")return!1;if(r.position==="fixed"||r.position==="sticky")return!0;var t=e.getBoundingClientRect();return t.width>0||t.height>0}function p(){try{var e=new URL(window.location.href);return e.hostname==="jobs.ashbyhq.com"}catch{return!1}}function d(){for(var e=document.querySelectorAll('button, [type="submit"], input[type="submit"], [role="button"]'),r=0;r<e.length;r++){var t=e[r];if(t.id!==f){var o=(t.textContent||t.innerText||"").trim();if(/Submit|Apply|Continue|Next/i.test(o)&&m(t))return t}}return null}function v(){for(var e=n.formFiller&&n.formFiller.getFieldLabel?n.formFiller.getFieldLabel:function(u){for(var a=u.parentElement,l=0;l<5&&a;l++){if(a.tagName==="LABEL")return(a.textContent||"").trim();var w=a.querySelector("label");if(w)return(w.textContent||"").trim();a=a.parentElement}return(u.getAttribute("placeholder")||"").trim()},r=document.querySelectorAll("textarea"),t=0;t<r.length;t++){var o=r[t];if(m(o)){var i=e(o),c=(o.getAttribute("placeholder")||"").trim(),s=(i+" "+c).toLowerCase();if(/cover\s*letter|letter\s*\/\s*message|note\s+to|message\s+to|paste\s*(your|a)\s*cover|why\s+(you|this)/i.test(s))return o}}return null}function y(){for(var e=document.querySelectorAll("article, section, [role='main'], main, [class*='content'], [class*='description'], .job-description"),r="",t=0;t<e.length;t++){var o=e[t],i=(o.innerText||o.textContent||"").trim();i.length>r.length&&i.length>200&&(r=i)}return r}function h(){if(document.getElementById(f))return!0;var e=d(),r=v(),t=document.createElement("button");if(t.id=f,t.type="button",t.textContent=r?"FillyDash":"Fill application fields",t.style.cssText="display:block;width:100%;margin:0 0 12px 0;padding:10px 16px;background:#4B1D5E;color:#fff;border:none;border-radius:6px;font-size:13px;font-weight:500;cursor:pointer;box-sizing:border-box;",t.addEventListener("click",function(){if(r){t.disabled=!0,t.textContent="Generating cover letter...";var c=y();if(!c){n.toast&&n.toast.show&&n.toast.show("Could not find job description.",!0),t.disabled=!1,t.textContent="FillyDash";return}n.storage.getApiKeyAndProfile(function(s){var u=s.apiKey,a=s.userProfile||{};if(!u){n.toast&&n.toast.show&&n.toast.show("Set your Groq API key in the extension popup first.",!0),t.disabled=!1,t.textContent="FillyDash";return}chrome.runtime.sendMessage({action:"generate",payload:{apiKey:u,userProfile:a,jobDescription:c}},function(l){if(!l||!l.success){n.toast&&n.toast.show&&n.toast.show("Failed: "+(l&&l.error?l.error:"Unknown"),!0),t.disabled=!1,t.textContent="FillyDash";return}n.fieldFiller.fillElement(r,l.text),n.toast&&n.toast.show&&n.toast.show("Cover letter inserted.",!1),t.textContent="Done!",setTimeout(function(){t.disabled=!1,t.textContent="FillyDash"},2e3)})})}else n.formFiller&&n.formFiller.fillFromStoredQA?n.formFiller.fillFromStoredQA(function(s){var u=s.filled||0,a=(s.unfilled||[]).length;n.toast&&n.toast.show&&n.toast.show("Filled "+u+" field(s)."+(a?" Some need AI or manual input.":""),!1)}):n.toast&&n.toast.show&&n.toast.show("Use the extension popup 'Fill application fields' button.",!1)}),e&&e.parentNode)return e.parentNode.insertBefore(t,e),!0;var o=document.querySelector("form");if(o)return o.insertBefore(t,o.firstChild),!0;var i=document.querySelector("main, [role='main'], .content");return i?(i.insertBefore(t,i.firstChild),!0):!1}function x(){if(p()){var e=h();if(g(),!e){var r=setInterval(function(){if(document.getElementById(f)){clearInterval(r);return}d()&&(h(),g(),clearInterval(r))},1e3);setTimeout(function(){clearInterval(r)},15e3)}}}function C(){return v()}function F(){return y()}function b(){var e="",r="",t=document.querySelector("h1");t&&(t.innerText||t.textContent)&&(e=(t.innerText||t.textContent||"").trim());var o=document.querySelector("[class*='job-title'], [class*='JobTitle'], [class*='position']");o&&!e&&(o.innerText||o.textContent)&&(e=(o.innerText||o.textContent||"").trim());var i=document.querySelector("[class*='company'], [class*='Company']");return i&&(i.innerText||i.textContent)&&(r=(i.innerText||i.textContent||"").trim()),e||(e="Unknown role"),r||(r="Unknown company"),{company:r,role:e,jobUrl:typeof window<"u"&&window.location?window.location.href:""}}function g(){var e=d();!e||e.dataset.clgSubmitWatched||(e.dataset.clgSubmitWatched="1",e.addEventListener("click",function(){var r=b();chrome.runtime.sendMessage({action:"addJobToTracker",payload:{company:r.company,role:r.role,status:"applied",jobUrl:r.jobUrl||(typeof window<"u"&&window.location?window.location.href:""),source:"Ashby"}},function(){chrome.runtime.lastError})},!0))}n.adapters=n.adapters||{},n.adapters.ashby={name:"ashby",isActive:p,getCoverLetterTarget:C,getJobDescriptionFromPage:F,getJobInfo:b,runSetup:x}})();
//# sourceMappingURL=ashby.js-S7Zt456v.js.map
})()
