import{S as f,L as v}from"../../../../loader-Bm49oqt2.js";import{e as d}from"../../../../index-v_bkl-X2.js";import{_ as A,r as x,o as p,c as m,a as n,f as b,e as c,t as y,b as h,i as S}from"../../../../_plugin-vue_export-helper-CHIglDgE.js";import{r as _}from"../../../../renderContent-D_UQzxvC.js";const T="/assets/d-logo-BNFRiB2S.png",w={components:{Selectbox:f,Loader:v},data(){return{logoUrl:new URL(T,import.meta.url).href,levelObj:null,level:null,options:[{name:"Select Extraction Level",value:null},{name:"First Level",value:1},{name:"Second Level",value:2},{name:"Third Level",value:3},{name:"Fourth Level (Around 1 Minute)",value:4},{name:"Fifth Level (Multiple Minutes)",value:5}],cache:{},lv:0,data:[],processing:!1,total:0,initialSearchText:""}},methods:{APPBAR(){return document.querySelector(".appbar")},PAA(){return Array.from(document.querySelectorAll(".related-question-pair")).map(r=>({el:r,level:r.getAttribute("data-level"),paaTitle:r.getAttribute("data-q"),parent:null,text:r.querySelector('[role="heading"]')&&r.querySelector('[role="heading"]').textContent,url:r.querySelector("a").getAttribute("href").split("#:~:text=")[0],urlTitle:r.querySelector("h3").innerText}))},async changeLevel(e){this.processing=!0,this.levelObj=e;const t=e.value;if(document.querySelectorAll(".related-question-pair[data-level]").length||(this.initialize(),await new Promise(l=>setTimeout(l,100))),this.cache[t]){this.downloadCSV(t),this.processing=!1;return}for(this.total+=Array.from(document.querySelectorAll(".related-question-pair[data-level]")).length;this.level!==t;){const l=Array.from(document.querySelectorAll(".related-question-pair[data-level]")).filter(o=>o.getAttribute("data-level")==this.level);this.cache[this.level]=l,this.level++;for(const o of l){o.querySelector("[role='button']").click(),await new Promise(s=>setTimeout(s,1e3));const i=document.querySelectorAll(".related-question-pair:not([data-level])");this.total+=i.length;for(const s of i){s.setAttribute("data-level",this.level);const a=this.extractInfo(s);s.setAttribute("data-parent",o.getAttribute("data-q")),s.setAttribute("data-text",a["data-text"]),s.setAttribute("data-url",a["data-url"]),s.setAttribute("data-url-title",a["data-url-title"])}}}this.downloadCSV(t),this.processing=!1},downloadCSV(e){const t=["Also Asked Headline","Parent","Text","URL","URL Title"],r=Array.from(document.querySelectorAll(".related-question-pair[data-level]")).map(s=>[s.getAttribute("data-q"),s.getAttribute("data-parent"),s.getAttribute("data-text"),s.getAttribute("data-url"),s.getAttribute("data-url-title")].map(a=>((a.includes(",")||a.includes('"')||a.includes("#"))&&(a=a.replace(/"/g,'""').replace(/#/g,"%23"),a=`"${a}"`),a)));r.unshift(t);const l=r.map(s=>s.join(",")).join(`
`),o=new Blob([l],{type:"text/csv;charset=utf-8"}),i=document.createElement("a");i.setAttribute("href",URL.createObjectURL(o)),i.setAttribute("download",`${this.initialSearchText}-Lv${e}-PAA-${r.length}-detailed-com.csv`),document.body.appendChild(i),i.click(),i.remove()},extractInfo(e){const t={},r=e.getAttribute("data-q")||"";let l=e.getAttribute("data-text");(typeof l>"u"||!l||l==""||l.trim()==""||l.toLowerCase()==="undefined")&&(l=L(e)),l=l.replace(r,""),t["data-text"]=l.trim();const o=e.querySelector("a");o&&(t["data-url"]=o.href.split("#:~:text=")[0]);const i=e.querySelector("h3");return i&&(t["data-url-title"]=i.textContent.trim()),t},initialize(){document.querySelectorAll(".related-question-pair").forEach(e=>{e.setAttribute("data-level",1),this.initialSearchText=document.querySelector("textarea").value,e.setAttribute("data-parent",this.initialSearchText);const t=this.extractInfo(e);e.setAttribute("data-text",t["data-text"]),e.setAttribute("data-url",t["data-url"]),e.setAttribute("data-url-title",t["data-url-title"])})}},mounted(){d.storage.onChanged.addListener((e,t)=>{e.isDarkMode&&(e.isDarkMode.newValue?this.$refs.detailedWrapper.classList.add("dark"):this.$refs.detailedWrapper.classList.remove("dark"))}),d.storage.local.get("isDarkMode",e=>{e.isDarkMode&&this.$refs.detailedWrapper.classList.add("dark")})},computed:{isRelatedQuestionPairExists(){return document.querySelectorAll(".related-question-pair").length},detailedLogo(){return d?d.runtime.getURL("logo/d-logo.png"):""}}};function L(e){if(!e)return"";const t=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,{acceptNode(o){const i=o.parentNode;return["STYLE","SCRIPT","NOSCRIPT"].includes(i.tagName)||i.closest(".g")?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}},!1);let r="",l;for(;l=t.nextNode();)r+=l.nodeValue.replace(/\s+/g," ").trim()+" ";return r.trim()}const q={key:0,class:"detailed-wrapper",ref:"detailedWrapper"},C={class:"flex items-center gap-4"},E=["src"],k=n("p",{class:"text-lg"},"Extract 'People Also Ask'",-1),P={key:0,id:"detailed-loader"},N={class:"text-lg detailed-gray"},R={class:"detailed-purple"},V=n("div",{class:"loader"},null,-1),j=n("p",{class:"text-lg detailed-gray detailed-info"},[c(" Downloads a .csv file when completed. This feature is in beta so go easy on us — we’re constantly making improvements. "),n("a",{class:"detailed-gray underline",target:"_blank",href:"https://detailed.com/people-also-ask/?utm_source=extensioninserp"},"Learn more"),c(" (includes instructions on how to disable). ")],-1);function F(e,t,r,l,o,i){const s=x("Selectbox");return i.isRelatedQuestionPairExists?(p(),m("div",q,[n("header",C,[n("img",{class:"d-logo",src:o.logoUrl,alt:"Detailed Logo"},null,8,E),k]),b(s,{onSelected:t[0]||(t[0]=a=>i.changeLevel(a)),modelValue:o.levelObj,"onUpdate:modelValue":t[1]||(t[1]=a=>o.levelObj=a),options:o.options,disabled:o.processing},null,8,["modelValue","options","disabled"]),o.processing?(p(),m("div",P,[n("p",N,[c(" We have found "),n("span",R,y(o.total),1),c(" PAA's so far. ")]),V])):h("",!0),j],512)):h("",!0)}const U=A(w,[["render",F]]),B=()=>document.querySelector("#detailed-wrapper");d.storage.local.get("isPaaActive",async function(e){if(await new Promise(i=>setTimeout(i,1e3)),e.isPaaActive){var r=document.createElement("div");r.id="paa-container",r.style.width="262px";const i=document.querySelector("#center_col");let s=i.nextElementSibling;const a=document.createElement("div");if(a.id="detailed-wrapper",a.style.display="flex",a.style.flexDirection="column",a.style.paddingTop="20px",a.style.paddingBottom="20px",B())return;s||(r.style.marginLeft="100px"),a.appendChild(r),s?s.prepend(a):i.insertAdjacentElement("afterend",a);var l=r.attachShadow({mode:"closed"});const g=await d.runtime.sendMessage({type:"getGoogleCSS"}),u=document.createElement("style");u.textContent=g,l.appendChild(u);var o=document.createElement("div");l.appendChild(o),setTimeout(()=>{_(["assets/index-BFMyTK83.css","assets/loader-wd32GVui.css"],W=>{S(U).mount(o)})},1e3)}});
