!function(e){var t={};function n(o){if(t[o])return t[o].exports;var s=t[o]={i:o,l:!1,exports:{}};return e[o].call(s.exports,s,s.exports,n),s.l=!0,s.exports}n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)n.d(o,s,function(t){return e[t]}.bind(null,s));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t,n){const{promiseFinally:o,toError:s}=n(1);e.exports=class e{static set(t,n){return(new e).set(t,n)}static wrap(t,n,o){return(new e).wrap(t,n,o)}constructor(){this._id=null,this._delay=null}get id(){return this._id}get delay(){return this._delay}set(e,t=""){return new Promise((n,o)=>{this.clear();const r=t?()=>o(s(t)):n;this._id=setTimeout(r,e),this._delay=e})}wrap(e,t,n=""){const s=o(e,()=>this.clear()),r=this.set(t,n);return Promise.race([s,r])}clear(){this._id&&clearTimeout(this._id)}}},function(e,t){t.promiseFinally=(e,t)=>Promise.resolve(e).then(e=>(t(),e),e=>(t(),Promise.reject(e))),t.toError=e=>"string"==typeof(e="function"==typeof e?e():e)?new Error(e):e},function(e,t,n){"use strict";n.r(t);var o={creativeAssetExtensions:["avi","css","csv","eot","gif","ico","jpg","js","json","map","mov","mp4","mpeg","mpg","ogg","ogv","ott","pdf","png","svg","ttf","webmanifest","wmv","woff","woff2","xml"],noCacheHeaders:{"Cache-Control":"no-cache, no-store, must-revalidate",Expires:"Fri, 01 Jan 1970 00:00:00 GMT",Pragma:"no-cache"},lottery:function(e){return Math.round(Math.random()*parseInt(e))},parseCookies:function(e){const t={};return e.cookie&&e.cookie.split(";").forEach(e=>{if(e){const n=e.split("=");t[n[0].trim()]=n[1].trim()}}),t},queryStringParse:function(e){const t=new URLSearchParams(e);let n={};for(let e of t)n[e[0]]=e[1];return n}};const s={result:{status:2,token:null,title:null,position:null,live_position:null,promoted:null,urlRedirect:null,onsale:null,message:null,slug:null,priority:null,priorityAvailable:null,logo:null,responseID:null,captchaRequired:null,ttl:null}};var r={processResponse:async function(e){let t,n={};return t=await e,t?(200!==t.status?n.body=s:n.body=await e.json(),n.status=t.status,n.statusText=t.statusText,n.success=t.ok,n):(n.body=s,n.status=null,n.statusText="Communication failure between Cloudflare and the CrowdHandler API occured.",n.success=!1,n)}};const a=n(0);async function c(e){const{request:t}=e,n=Date.now(),s=o.creativeAssetExtensions,c=t.url,l=new URL(c),i=l.hostname,u=l.pathname,d=Object.fromEntries(t.headers),h=l.search,p=d["cf-connecting-ip"],f=d["user-agent"],m=/(.*\d+.*)/;let y,g;if(console.log(l),!0===/^\/ch\/.*/.test(u)){const e=await async function(e){let t,n="/"+e.queryString,o=e.path.substring(4);t=o?"https://wait.crowdhandler.com/"+o:"https://wait.crowdhandler.com"+n;let s=await caches.open("crowdhandler:cache"),r=await s.match(t);if(r)return console.log("Serving waiting room template from cache."),{response:r,useCache:!0};let c,l,i,u={headers:{"content-type":"text/html;charset=UTF-8"},method:"GET"},d=0,h=await async function e(){let n,o=new a;c=null;try{if(d++,n=await Promise.race([fetch(t,u),o.set(6e3,"API Communication Timed Out!")]),200!==n.status)throw`${n.status} ${n.statusText}`}catch(e){c=!0,console.error("Template Fetch Failure"),console.log(e)}finally{return o.clear(),!0===c&&d<3&&(console.log("Retrying Template Fetch."),await e()),n}}();return h?(l=await async function(e){const{headers:t}=e,n=t.get("content-type")||"";return n.includes("application/json")?JSON.stringify(await e.json()):(n.includes("application/text")||n.includes("text/html"),e.text())}(h),i={headers:{"content-type":"text/html;charset=UTF-8"},status:h.status,statusText:h.statusText}):(l="

Service Temporarily Unavailable

",i={headers:{"content-type":"text/html;charset=UTF-8"},status:503,statusText:"Service Unavailable"}),{cache:s,results:l,resultsMeta:i,templateEndpoint:t}}({path:u,queryString:h});try{if(!0===e.useCache)return e.response}catch(e){console.log(e)}try{e.resultsMeta.headers["cache-control"]="public, max-age=60",200===e.resultsMeta.status&&(console.log("Storing template in cache"),await e.cache.put(e.templateEndpoint,new Response(e.results,e.resultsMeta)))}catch(e){console.log(e)}return new Response(e.results,e.resultsMeta)}try{y=d["accept-language"].split(",")[0]}catch(e){console.log("Failed to find a valid accept-language value"),console.log(e)}const w=new Request(c,{body:t.body,headers:t.headers,method:t.method,redirect:t.redirect});"undefined"!=typeof NO_BYPASS&&w.headers.append("x-ch-no-bypass",NO_BYPASS);let b,$=!0;"undefined"!=typeof FAIL_TRUST&&"false"===FAIL_TRUST&&($=!1),"undefined"!=typeof SAFETY_NET_SLUG&&(b=SAFETY_NET_SLUG);let T=!1;"undefined"!=typeof WHITELABEL&&"true"===WHITELABEL&&(T=!0),g=!0===T?i+"/ch":"wait.crowdhandler.com";let S,v=u.match(/\.(.*)/);if(null!==v&&(v=v[1]),-1!==s.indexOf(v))return console.log("Static file detected. Going straight to origin."),await fetch(w);h&&(S=o.queryStringParse(decodeURIComponent(h)));let x,{"ch-code":_,"ch-fresh":P,"ch-id":E,"ch-id-signature":O,"ch-public-key":R,"ch-requested":k}=S||{};_&&"undefined"!==_&&"null"!==_||(_=""),S&&(delete S["ch-code"],delete S["ch-fresh"],delete S["ch-id"],delete S["ch-id-signature"],delete S["ch-public-key"],delete S["ch-requested"]),S&&0!==Object.keys(S).length?(S=Object.keys(S).map(e=>e+"="+S[e]).join("&"),S="?"+S):S=null,x=S?encodeURIComponent(`https://${i}${u}${S}`):encodeURIComponent(`https://${i}${u}`);let C,j,I=o.parseCookies(d).crowdhandler;if(E?(C=E,j=!0):C=I||null,j){let e,t={"Set-Cookie":`crowdhandler=${C}; path=/; Secure; HttpOnly`};return e=S?{Location:`${u}${S}`}:{Location:u},new Response(null,{status:302,headers:Object.assign(o.noCacheHeaders,e,t)})}!0!==m.test(C)&&(C=null);const A=API_ENDPOINT;let U,L={headers:{"content-type":"application/json","x-api-key":API_KEY},method:void 0};if(C){L.method="GET";try{U=await fetch(`${A}/requests/${C}?url=${x}&agent=${encodeURIComponent(f)}&ip=${encodeURIComponent(p)}&lang=${encodeURIComponent(y)}`,L)}catch(e){console.error(e)}}else{L.body=JSON.stringify({agent:f,ip:p,lang:y,url:c}),L.method="POST";try{U=await fetch(A+"/requests",L)}catch(e){console.error(e)}}const F=r.processResponse,M=await F(U);let q,H,N;switch(!0!==M.success?(console.error(`API response returned a ${M.status} response with error ${M.statusText}`),q=M.body.result,console.log(q)):(q=M.body.result,console.log(q)),1!==q.promoted&&2!==q.status?(H=!0,N=`https://${g}/${q.slug}?url=${x}&ch-code=${_}&ch-id=${q.token}&ch-public-key=${API_KEY}`):!0!==$&&1!==q.promoted&&2===q.status?(H=!0,N=b?`https://${g}/${b}?url=${x}&ch-code=${_}&ch-id=${C}&ch-public-key=${API_KEY}`:`https://${g}/?url=${x}&ch-code=${_}&ch-id=${C}&ch-public-key=${API_KEY}`):H=!1,H){case!0:return console.log("redirecting..."),q.token?new Response(null,{status:302,headers:Object.assign(o.noCacheHeaders,{Location:N,"Set-Cookie":`crowdhandler=${q.token}; path=/; Secure; HttpOnly`})}):new Response(null,{status:302,headers:Object.assign(o.noCacheHeaders,{Location:N})});case!1:console.log("continue...")}const Y=await fetch(w);let G=new Response(Y.body,{status:Y.status,statusText:Y.statusText,headers:Y.headers});!0===m.test(q.token)&&G.headers.append("set-cookie",`crowdhandler=${q.token}; path=/; Secure; HttpOnly`),G.headers.append("set-cookie","crowdhandler_integration=cloudflare; path=/; Secure");const D=Date.now(),B=q.responseID;return e.waitUntil(new Promise(e=>{e(async function(){if(B&&0===o.lottery(2)){L.body=JSON.stringify({httpCode:Y.status,sampleRate:3,time:D-n}),L.method="PUT",U=await fetch(`${A}/responses/${B}`,L);const e=r.processResponse;return await e(U)}}())})),G}addEventListener("fetch",e=>{e.respondWith(c(e))})}]);