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 N,R,j,B;let r=window.gamursInfScrollCustomSiteConfig,q=window.gamursInfScroll,E=r&&(N=r.categories)!=null?N:"",b=r&&(R=r.tags)!=null?R:"",I=!(r&&r.useCategories===!1),O=!(r&&r.useTags===!1),T=!!(r&&r.sameCategory),m=q&&(j=q.infScrollURL)!=null?j:"",g=document.getElementsByClassName("gamurs-inf-scroll-post")[0].attributes["data-categories"].value,p=document.getElementsByClassName("gamurs-inf-scroll-post")[0].attributes["data-tags"].value,h=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=`${m}/infscroll/${n}/${h}?categories=${g}&tags=${p}&useCategories=${I}&useTags=${O}&forceCategories=${E}&forceTags=${b}&sameCategory=${T}`,J={root:document.querySelector("#scroll-area"),rootMargin:"0px",threshold:.5},P={rootMargin:"-50% 0% -50% 0%",threshold:0},D={rootMargin:"-50% 0% -10% 0%",threshold:0};function L(e,o,l){let t;return l==="middle"?(t=new IntersectionObserver(o,P),t=i(e,t,!1)):l==="middleofmiddle"?(t=new IntersectionObserver(o,D),t=i(e,t,!0)):(t=new IntersectionObserver(o,J),t=i(e,t,!1)),t}function x(e){if(typeof window.gamursInfScrollOnInfiniteScrollAppend=="function")try{window.gamursInfScrollOnInfiniteScrollAppend(e)}catch(o){console.log(o)}}function H(e,o){e[0].isIntersecting&&(v(),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 d=[],f=document.querySelector(".gamurs-inf-scroll-post");d[f&&(B=f.dataset.id)!=null?B:0]=document.URL;let M=!1;history.scrollRestoration="manual";let w=!0,y="down",S=0;document.addEventListener("scroll",function(){let e=window.pageYOffset||document.documentElement.scrollTop;e>S?y="down":e<S&&(y="up"),S=e<=0?0:e});function k(e,o){e.forEach(l=>{if(l.isIntersecting&&window.location.href!==l.target.dataset.url){let t=d[l.target.dataset.id];if(y==="down"?document.getElementsByClassName("gamurs-inf-scroll-post")[0].dataset.id!==l.target.dataset.id&&history.pushState(null,"",t):(w=!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"})}}),Array.from(document.getElementsByClassName("gamurs-inf-scroll-post")).map(l=>o.observe(l))}addEventListener("popstate",e=>{try{w&&document.querySelector(`[data-url="${e.target.location.href.split("?")[0]}"]`).scrollIntoView()}catch(o){console.log(o)}w=!0});function v(){M?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){d[l.id]=l.url,a=l.nextUrl;let t=document.createElement("div");t.innerHTML=l.html;let s=t.firstElementChild,u=document.querySelector("#gamurs-inf-scroll-main");if(u&&s)u.appendChild(s);else throw"did not find #gamurs-inf-scroll-main";Array.from(s.querySelectorAll("script")).forEach(A=>{try{(0,eval)(A.innerText)}catch(C){console.log(C)}}),x(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],$,!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"&&v()}}):(M=!0,fetch(`${m}/campaign/${n}/${h}?categories=${g}&tags=${p}`).then(e=>{if(e.status!==200)throw"No Campaign";return e.json()}).then(function(o){let l=o;if(l.html!=null){d[l.id]=l.url;let t=document.createElement("div");t.innerHTML=l.html;let s=t.firstElementChild,u=document.querySelector("#gamurs-inf-scroll-main");if(u&&s)u.appendChild(s);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(s.querySelectorAll("script")).forEach(A=>{try{(0,eval)(A.innerText)}catch(C){console.log(C)}}),x(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],$,!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"&&v()}))}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=`${m}/infscroll/${n}/${h}?categories=${g}&tags=${p}&useCategories=${I}&useTags=${O}&forceCategories=${E}&forceTags=${b}&sameCategory=${T}`),U()}).catch(e=>{console.log(e),U()});let $,c;function U(){$=L(f,k,"middle"),c=L(f,H,"middleofmiddle")}})();
