console.log("loading config for escapistmagazine");window.gamursInfScrollCustomSiteConfig={site:"escapistmagazine",useCategories:true,useTags:true,categories:undefined,tags:undefined,sameCategory:false,timeDecay:false,timeDecayOffset:"30d",timeDecayScale:"90d",timeDecayDecay:0.5,disableOn:undefined};window.gamursInfScroll={infScrollURL:"https://infinity-api.escapistmagazine.com"};"use strict";console.log("Infinite scroll initialised");(function(){var J,F,V,Y,z,G,K,Q;if(typeof window>"u")return;let l=window.gamursInfScrollCustomSiteConfig;if(l&&l.disableOn&&l.disableOn.referrer){let e=l.disableOn.referrer.values.map(t=>{if(t==="")return t;let r=t;t.startsWith("https://")||t.startsWith("http://")||(r=`http://${t}`);try{r=new URL(r)}catch{r=!1}return r&&r.hostname.split(".").slice(-2).join(".")});e.includes("")&&(e=[...e,new URL(document.location).hostname.split(".").slice(-2).join(".")]);let o=l.disableOn.referrer.invert||!1,s="";try{s=new URL(document.referrer).hostname.split(".").slice(-2).join(".")}catch{s=""}if(e.includes(s)&&!o||!e.includes(s)&&o)return}let L=window.gamursInfScroll,U=l&&(J=l.categories)!=null?J:"",q=l&&(F=l.tags)!=null?F:"",T=!(l&&l.useCategories===!1),M=!(l&&l.useTags===!1),N=!!(l&&l.sameCategory),R=!!(l&&l.timeDecay),j=l&&(V=l.timeDecayOffset)!=null?V:"",B=l&&(Y=l.timeDecayScale)!=null?Y:"",k=l&&(z=l.timeDecayDecay)!=null?z:"",v=L&&(G=L.infScrollURL)!=null?G:"",S=document.getElementsByClassName("gamurs-inf-scroll-post")[0].attributes["data-categories"].value,C=document.getElementsByClassName("gamurs-inf-scroll-post")[0].attributes["data-tags"].value,g=(K=document.getElementsByClassName("gamurs-inf-scroll-post")[0].attributes["data-experiments"])==null?void 0:K.value,Z=window.location.href;window.gamurs_inf_scroll_data=window.gamurs_inf_scroll_data||{};let O=document.getElementsByClassName("gamurs-inf-scroll-post")[0].dataset.id,n=window.location.hostname.split(".")[window.location.hostname.split(".").length-2];n==="lndo"?n=window.location.hostname.split(".")[0]:n==="go-vip"&&(n=window.location.hostname.split(".")[0],n=n.split("-")[0],(n==="www"||n==="cms")&&(n=window.location.hostname.split(".")[0].split("-")[1])),window.gamurs_inf_scroll_data.nextUrl=`${v}/infscroll/${n}/${O}?categories=${S}&tags=${C}&useCategories=${T}&useTags=${M}&forceCategories=${U}&forceTags=${q}&sameCategory=${N}${R?`&timeDecayOffset=${j}&timeDecayScale=${B}&timeDecayDecay=${k}`:""}${g?`&experiments="${g}"`:""}`;let ee={root:document.querySelector("#scroll-area"),rootMargin:"0px",threshold:.5},te={rootMargin:"-50% 0% -50% 0%",threshold:0},le={rootMargin:"-50% 0% -10% 0%",threshold:0},ie={rootMargin:"-75% 0% -25% 0%",threshold:0},oe={rootMargin:"-87.5% 0% -12.5% 0%",threshold:0};function P(e,o,s){let t;return s==="middle"?(t=new IntersectionObserver(o,te),t=p(e,t,!1)):s==="middleofmiddle"?(t=new IntersectionObserver(o,le),t=p(e,t,!0)):s==="middlelower"?(t=new IntersectionObserver(o,oe),t=p(e,t,!1)):(t=new IntersectionObserver(o,ee),t=p(e,t,!1)),t}function se(e){if(typeof window.gamursInfScrollOnInfiniteScrollAppend=="function")try{window.gamursInfScrollOnInfiniteScrollAppend(e)}catch(o){console.log(o)}}function ne(e,o){e[0].isIntersecting&&(x(),o.unobserve(e[0].target))}function p(e,o,s){let t;return s?(e.style.position="relative",t=document.createElement("div"),t.style.position="absolute",t.style.top="50%",t.style.width="100%",t.style.height="50%",t.style.pointerEvents="none",e.appendChild(t)):t=e,o.observe(t),o}let h=[],y=document.querySelector(".gamurs-inf-scroll-post");h[y&&(Q=y.dataset.id)!=null?Q:0]=document.URL;let W=!1;history.scrollRestoration="manual";let b=!0,E="down",_=0;document.addEventListener("scroll",function(){let e=window.pageYOffset||document.documentElement.scrollTop;e>_?E="down":e<_&&(E="up"),_=e<=0?0:e});function re(e,o){e.forEach(s=>{if(s.isIntersecting&&window.location.href!==s.target.dataset.url){let t=h[s.target.dataset.id];if(E==="down"?document.getElementsByClassName("gamurs-inf-scroll-post")[0].dataset.id!==s.target.dataset.id&&history.pushState(null,"",t):window.location.href!==Z&&(b=!1,history.back()),document.title=s.target.dataset.title,typeof window.gamursInfScrollOnUrlChange=="function")try{window.gamursInfScrollOnUrlChange(t)}catch(i){console.log(i)}let r=document.querySelector("link[rel='canonical']");r&&(r.href=t),window.snowplow&&window.snowplow("trackStructEvent",{category:"gamurs-infinite-scroll",action:"impression"})}}),Array.from(document.getElementsByClassName("gamurs-inf-scroll-post")).map(s=>o.observe(s))}addEventListener("popstate",e=>{try{b&&document.querySelector(`[data-url="${e.target.location.href.split("?")[0]}"]`).scrollIntoView()}catch(o){console.log(o)}b=!0});function x(){W?H(!1,h,D,A):(W=!0,H(!0,h,D,A))}async function H(e,o,s,t){let r=e?`${v}/campaign/${n}/${O}?categories=${S}&tags=${C}${g?`&experiments="${g}"`:""}`:window.gamurs_inf_scroll_data.nextUrl;await fetch(r).then(i=>{if(i.status!==200)throw e?"No Campaign":`request failed: ${i.text()}`;return i.json()}).then(function($){let a=$;if(a.html!=null){o[a.id]=a.url,e||(window.gamurs_inf_scroll_data.nextUrl=a.nextUrl);let c=document.createElement("div");c.innerHTML=a.html;let m=c.firstElementChild,X=document.querySelector("head");X&&c&&Array.from(c.querySelectorAll("link")).forEach(w=>{console.log(w),X.appendChild(w)});let f=document.querySelector("#gamurs-inf-scroll-main");if(f&&m)f.appendChild(m);else throw"did not find #gamurs-inf-scroll-main";window.snowplow&&window.snowplow("trackStructEvent",{category:"gamurs-infinite-scroll",action:"append-article",label:a.id}),[c,m].forEach(w=>{Array.from(w.querySelectorAll("script")).forEach(u=>{try{if(u.src){let d=document.createElement("script");d.src=u.src,d.type=u.type,d.id=u.id,d.async=!0,m&&w===m&&u.parentElement&&u.parentElement.removeChild(u),d.id?document.getElementById(d.id)||f==null||f.appendChild(d):f==null||f.appendChild(d)}else(0,eval)(u.innerText)}catch(d){console.log(d)}})}),se(a.id),p(document.querySelectorAll(".gamurs-inf-scroll-post")[document.querySelectorAll(".gamurs-inf-scroll-post").length-1],s,!0),p(document.querySelectorAll(".gamurs-inf-scroll-post")[document.querySelectorAll(".gamurs-inf-scroll-post").length-1],t,!1),s.unobserve(document.querySelectorAll(".gamurs-inf-scroll-post")[document.querySelectorAll(".gamurs-inf-scroll-post").length-2].lastChild)}}).catch(i=>{if(e)console.log(i),i!=="did not find #gamurs-inf-scroll-main"&&x();else{let $=window.gamurs_inf_scroll_data.nextUrl.split("?")[1].split("&").filter(c=>c.slice(0,5)==="page="),a=$.length?parseInt($[0].split("=")[1]):1;if(a<20){if(i.slice(0,15)==="request failed:"){let c=window.gamurs_inf_scroll_data.nextUrl.split("?");window.gamurs_inf_scroll_data.nextUrl=c[0]+"?page="+(a+1).toString()+"&"+c[1].split("&").filter(m=>m.slice(0,5)!=="page=").join("&")}i!=="did not find #gamurs-inf-scroll-main"&&x()}}})}let A,D;function I(){A=P(y,re,"middlelower"),D=P(y,ne,"middleofmiddle")}n==="dotesports"?fetch("/wp-json/gamurs/v1/infscroll/multisites").then(e=>e.json()).then(e=>{let o=new URL(window.location.href).pathname.split("/")[1];e.includes(o)&&(n=`${n}|${o}`,window.gamurs_inf_scroll_data.nextUrl=`${v}/infscroll/${n}/${O}?categories=${S}&tags=${C}&useCategories=${T}&useTags=${M}&forceCategories=${U}&forceTags=${q}&sameCategory=${N}${R?`&timeDecayOffset=${j}&timeDecayScale=${B}&timeDecayDecay=${k}`:""}${g?`&experiments="${g}"`:""}`),I()}).catch(e=>{console.log(e),I()}):I()})();
