console.log("loading config for destructoid");window.gamursInfScrollCustomSiteConfig={site:"destructoid",useCategories:true,useTags:true,categories:undefined,tags:undefined,sameCategory:false};window.gamursInfScroll={infScrollURL:"https://infinite-scroll-system.gamurs.workers.dev"};"use strict";console.log("Infinite scroll initialised");(function(){var U,N,R,j;let s=window.gamursInfScrollCustomSiteConfig,C=window.gamursInfScroll,q=s&&(U=s.categories)!=null?U:"",b=s&&(N=s.tags)!=null?N:"",E=!(s&&s.useCategories===!1),I=!(s&&s.useTags===!1),O=!!(s&&s.sameCategory),f=C&&(R=C.infScrollURL)!=null?R:"",g=document.getElementsByClassName("gamurs-inf-scroll-post")[0].attributes["data-categories"].value,m=document.getElementsByClassName("gamurs-inf-scroll-post")[0].attributes["data-tags"].value,p=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=window.location.hostname.split(".")[0].split("-")[1]));let a=`${f}/infscroll/${n}/${p}?categories=${g}&tags=${m}&useCategories=${E}&useTags=${I}&forceCategories=${q}&forceTags=${b}&sameCategory=${O}`,B={root:document.querySelector("#scroll-area"),rootMargin:"0px",threshold:.5},J={rootMargin:"-50% 0% -50% 0%",threshold:0},P={rootMargin:"-50% 0% -10% 0%",threshold:0};function T(e,o,l){let t;return l==="middle"?(t=new IntersectionObserver(o,J),t=i(e,t,!1)):l==="middleofmiddle"?(t=new IntersectionObserver(o,P),t=i(e,t,!0)):(t=new IntersectionObserver(o,B),t=i(e,t,!1)),t}function L(e){if(typeof window.gamursInfScrollOnInfiniteScrollAppend=="function")try{window.gamursInfScrollOnInfiniteScrollAppend(e)}catch(o){console.log(o)}}function H(e,o){e[0].isIntersecting&&(S(),o.unobserve(e[0].target))}function i(e,o,l){let t;return l?(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 u=[],d=document.querySelector(".gamurs-inf-scroll-post");u[d&&(j=d.dataset.id)!=null?j:0]=document.URL;let x=!1;history.scrollRestoration="manual";let h=!0,w="down",y=0;document.addEventListener("scroll",function(){let e=window.pageYOffset||document.documentElement.scrollTop;e>y?w="down":e<y&&(w="up"),y=e<=0?0:e});function k(e,o){e.forEach(l=>{if(l.isIntersecting&&window.location.href!==l.target.dataset.url){let t=u[l.target.dataset.id];if(w==="down"?document.getElementsByClassName("gamurs-inf-scroll-post")[0].dataset.id!==l.target.dataset.id&&history.pushState(null,"",t):(h=!1,history.back()),document.title=l.target.dataset.title,typeof window.gamursInfScrollOnUrlChange=="function")try{window.gamursInfScrollOnUrlChange(t)}catch(r){console.log(r)}window.snowplow&&window.snowplow("trackStructEvent",{category:"gamurs-infinite-scroll",action:"impression"})}}),Array.from(document.getElementsByClassName("gamurs-inf-scroll-post")).map(l=>o.observe(l))}addEventListener("popstate",e=>{try{h&&document.querySelector(`[data-url="${e.target.location.href.split("?")[0]}"]`).scrollIntoView()}catch(o){console.log(o)}h=!0});function S(){x?fetch(a).then(e=>{if(e.status!==200)throw`request failed: ${e.text()}`;return e.json()}).then(function(o){let l=o;if(l.html!=null){u[l.id]=l.url,a=l.nextUrl;let t=document.createElement("div");t.innerHTML=l.html;let r=document.querySelector("#gamurs-inf-scroll-main");if(r)r.appendChild(t);else throw"did not find #gamurs-inf-scroll-main";Array.from(t.querySelectorAll("script")).forEach($=>{try{(0,eval)($.innerText)}catch(A){console.log(A)}}),L(l.id),i(document.querySelectorAll(".gamurs-inf-scroll-post")[document.querySelectorAll(".gamurs-inf-scroll-post").length-1],c,!0),i(document.querySelectorAll(".gamurs-inf-scroll-post")[document.querySelectorAll(".gamurs-inf-scroll-post").length-1],v,!1),c.unobserve(document.querySelectorAll(".gamurs-inf-scroll-post")[document.querySelectorAll(".gamurs-inf-scroll-post").length-2])}}).catch(e=>{let o=a.split("?")[1].split("&").filter(t=>t.slice(0,5)==="page="),l=o.length?parseInt(o[0].split("=")[1]):1;if(l<20){if(e.slice(0,15)==="request failed:"){let t=a.split("?");a=t[0]+"?page="+(l+1).toString()+"&"+t[1].split("&").filter(r=>r.slice(0,5)!=="page=").join("&")}e!=="did not find #gamurs-inf-scroll-main"&&S()}}):(x=!0,fetch(`${f}/campaign/${n}/${p}?categories=${g}&tags=${m}`).then(e=>{if(e.status!==200)throw"No Campaign";return e.json()}).then(function(o){let l=o;if(l.html!=null){u[l.id]=l.url;let t=document.createElement("div");t.innerHTML=l.html;let r=document.querySelector("#gamurs-inf-scroll-main");if(r)r.appendChild(t);else throw"did not find #gamurs-inf-scroll-main";window.snowplow&&window.snowplow("trackStructEvent",{category:"gamurs-infinite-scroll",action:"append-article",label:l.id}),Array.from(t.querySelectorAll("script")).forEach($=>{try{(0,eval)($.innerText)}catch(A){console.log(A)}}),L(l.id),i(document.querySelectorAll(".gamurs-inf-scroll-post")[document.querySelectorAll(".gamurs-inf-scroll-post").length-1],c,!0),i(document.querySelectorAll(".gamurs-inf-scroll-post")[document.querySelectorAll(".gamurs-inf-scroll-post").length-1],v,!1),c.unobserve(document.querySelectorAll(".gamurs-inf-scroll-post")[document.querySelectorAll(".gamurs-inf-scroll-post").length-2].lastChild)}}).catch(e=>{console.log(e),e!=="did not find #gamurs-inf-scroll-main"&&S()}))}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}`,a=`${f}/infscroll/${n}/${p}?categories=${g}&tags=${m}&useCategories=${E}&useTags=${I}&forceCategories=${q}&forceTags=${b}&sameCategory=${O}`),M()}).catch(e=>{console.log(e),M()});let v,c;function M(){v=T(d,k,"middle"),c=T(d,H,"middleofmiddle")}})();
