(function(){console.log("ThisVid Downloader inject script loaded");const s={flashvars:null,hlsUrls:new Set,videoUrls:new Set,lastSignature:""};function f(){if(window.flashvars){s.flashvars=window.flashvars;return}for(const t in window)if(t.startsWith("flashvars_")&&window[t]){s.flashvars=window[t];break}}function a(t){!t||typeof t!="string"||t.includes(".m3u8")&&s.hlsUrls.add(t)}function o(t){!t||typeof t!="string"||/\/get_file\/|\.m3u8(?:[?#]|$)/i.test(t)&&(s.videoUrls.add(t),a(t))}function c(){if(!s.flashvars)return;const t=[s.flashvars.video_url,s.flashvars.video_alt_url,s.flashvars.video_alt_url2];t.forEach(a),t.forEach(o)}function u(){try{document.querySelectorAll("video, source").forEach(t=>{o(t.currentSrc||t.src||t.getAttribute("src"))})}catch{}}function d(t){try{return JSON.stringify({video_url:t.flashvars?.video_url||"",video_alt_url:t.flashvars?.video_alt_url||"",video_alt_url2:t.flashvars?.video_alt_url2||"",hlsUrls:t.hlsUrls,videoUrls:t.videoUrls})}catch{return String(Date.now())}}function i(t=!1){f(),c(),u();const r={flashvars:s.flashvars,hlsUrls:Array.from(s.hlsUrls),videoUrls:Array.from(s.videoUrls)},e=d(r);!t&&e===s.lastSignature||(s.lastSignature=e,console.log("Sending page data to content script:",r),window.postMessage({type:"THISVID_PAGE_DATA",data:r},"*"))}i(!0);let l=0;const h=setInterval(()=>{l+=1,i(!1),l>=40&&clearInterval(h)},500);window.addEventListener("message",function(t){t.data&&(t.data.type==="REQUEST_THISVID_DATA"||t.data.type==="REQUEST_PORNHUB_DATA")&&i(!0)});const v=window.XMLHttpRequest;window.XMLHttpRequest=function(){const t=new v,r=t.open;return t.open=function(e,n,...g){return n&&typeof n=="string"&&n.includes(".m3u8")&&(a(n),setTimeout(()=>i(!1),100)),o(n),r.apply(this,[e,n,...g])},t};const w=window.fetch;window.fetch=function(...t){const r=t[0],e=typeof r=="string"?r:r?.url,n=w.apply(this,t);return e&&typeof e=="string"&&e.includes(".m3u8")&&(a(e),setTimeout(()=>i(!1),100)),o(e),n}})();
