console.log("loading config for destructoid");window.gamursInfScrollCustomSiteConfig={site:"destructoid",useCategories:true,useTags:true,categories:undefined,tags:undefined};window.gamursInfScroll={infScrollURL:"https://infinite-scroll-system.gamurs.workers.dev"};"use strict";console.log("Infinite scroll initialised");(function(){var R,L,M,U;let r=window.gamursInfScrollCustomSiteConfig,A=window.gamursInfScroll,$=r&&(R=r.categories)!=null?R:"",b=r&&(L=r.tags)!=null?L:"",C=!(r&&r.useCategories===!1),q=!(r&&r.useTags===!1),f=A&&(M=A.infScrollURL)!=null?M:"",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=${C}&useTags=${q}&forceCategories=${$}&forceTags=${b}`,j={root:document.querySelector("#scroll-area"),rootMargin:"0px",threshold:.5},N={rootMargin:"-50% 0% -50% 0%",threshold:0},B={rootMargin:"-50% 0% -10% 0%",threshold:0};function I(e,o,l){let t;return l==="middle"?(t=new IntersectionObserver(o,N),t=i(e,t,!1)):l==="middleofmiddle"?(t=new IntersectionObserver(o,B),t=i(e,t,!0)):(t=new IntersectionObserver(o,j),t=i(e,t,!1)),t}function O(e){if(typeof window.gamursInfScrollOnInfiniteScrollAppend=="function")try{window.gamursInfScrollOnInfiniteScrollAppend(e)}catch(o){console.log(o)}}function J(e,o){e[0].isIntersecting&&(w(),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="1px",e.appendChild(t)):t=e,o.observe(t),o}let u=[],d=document.querySelector(".gamurs-inf-scroll-post");u[d&&(U=d.dataset.id)!=null?U:0]=document.URL;let E=!1;history.scrollRestoration="manual";let h=!0,T=0;function P(e,o){e.forEach(l=>{if(l.isIntersecting&&window.location.href!==l.target.dataset.url){let t=u[l.target.dataset.id];if(l.boundingClientRect.y>T?history.pushState(null,"",t):(h=!1,history.back()),document.title=l.target.dataset.title,typeof window.gamursInfScrollOnUrlChange=="function")try{window.gamursInfScrollOnUrlChange(t)}catch(s){console.log(s)}window.snowplow&&window.snowplow("trackStructEvent",{category:"gamurs-infinite-scroll",action:"impression"})}T=l.boundingClientRect.y}),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 w(){E?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 s=document.querySelector("#gamurs-inf-scroll-main");if(s)s.appendChild(t);else throw"did not find #gamurs-inf-scroll-main";Array.from(t.querySelectorAll("script")).forEach(S=>{try{(0,eval)(S.innerText)}catch(v){console.log(v)}}),O(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],y,!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(s=>s.slice(0,5)!=="page=").join("&")}e!=="did not find #gamurs-inf-scroll-main"&&w()}}):(E=!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 s=document.querySelector("#gamurs-inf-scroll-main");if(s)s.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(S=>{try{(0,eval)(S.innerText)}catch(v){console.log(v)}}),O(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],y,!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"&&w()}))}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=${C}&useTags=${q}&forceCategories=${$}&forceTags=${b}`),x()}).catch(e=>{console.log(e),x()});let y,c;function x(){y=I(d,P,"middle"),c=I(d,J,"middleofmiddle")}})();
