var webAuthPageBridge=(function(){function w(e){return e==null||typeof e=="function"?{main:e}:e}var s="ofdl:web-auth-page-bridge:v1",g="REQUEST",p="RESPONSE",h="hlsdownloader-website",m="AUTH_CALLBACK",b=1e4,a=new Map;window.chrome;function u(e){return typeof e=="object"&&e!==null}function l(e){return u(e)&&e.source===h&&e.type===m}function E(){return`ofdl-web-auth-${Date.now()}-${Math.random().toString(36).slice(2)}`}function y(e){let t,n,o;return typeof e[0]=="string"?(t=e[0],n=e[1],o=typeof e[2]=="function"?e[2]:typeof e[3]=="function"?e[3]:void 0):(n=e[0],o=typeof e[1]=="function"?e[1]:typeof e[2]=="function"?e[2]:void 0),{extensionId:t,message:n,callback:o}}function I(e,t,n){if(!l(t)){n==null||n({ok:!1,error:"UNSUPPORTED_MESSAGE"});return}const o=E(),r=window.setTimeout(()=>{a.delete(o),n==null||n({ok:!1,error:"WEB_AUTH_BRIDGE_TIMEOUT"})},b);a.set(o,{callback:n,timeoutId:r}),window.postMessage({channel:s,type:g,requestId:o,extensionId:e,message:t},window.location.origin)}function A(){const e=window,t=e.chrome||{},n=t.runtime||{},o=n.sendMessage;n.sendMessage=(...r)=>{var f;const i=y(r);if(l(i.message)){I(i.extensionId,i.message,i.callback);return}if(typeof o=="function")return o.apply(n,r);(f=i.callback)==null||f.call(i,{ok:!1,error:"NATIVE_SEND_MESSAGE_UNAVAILABLE"})},t.runtime=n,e.chrome=t}var T=w(()=>{window.addEventListener("message",e=>{var t;if(e.source!==window||e.origin!==window.location.origin)return;const n=e.data;if(!u(n)||n.channel!==s||n.type!==p)return;const o=typeof n.requestId=="string"?n.requestId:"",r=a.get(o);r&&(a.delete(o),window.clearTimeout(r.timeoutId),(t=r.callback)==null||t.call(r,n.response))}),A()});function v(){}function c(e,...t){}var d={debug:(...e)=>c(console.debug,...e),log:(...e)=>c(console.log,...e),warn:(...e)=>c(console.warn,...e),error:(...e)=>c(console.error,...e)},S=(()=>{let e;try{e=T.main(),e instanceof Promise&&(e=e.catch(t=>{throw d.error('The unlisted script "web-auth-page-bridge" crashed on startup!',t),t}))}catch(t){throw d.error('The unlisted script "web-auth-page-bridge" crashed on startup!',t),t}return e})();return S})();
