// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0-or-later
import{get as f,hideSitePane as l,PopStateHandlers as h,setLastLocation as p}from"/static/js/utils/utils.js?v=de549338ff5782e1";var i=document.getElementById("main"),c={},a=[];function d(t,e){if(!t){console.error("No data received");return}if(t.redirect){location.href=t.redirect;return}let n=t.url;if(!n){console.error("No URL in data ",t);return}if(!e){if(a.length===1&&a[0]===n)return;history.pushState({data:t,url:n,stateType:"dynLoad"},t.title,n),p(n)}if(!t.body){location.reload();return}if(document.onkeydown=()=>{},i.innerHTML=t.body,t.css){let o=document.createElement("style");o.innerHTML=t.css,i.appendChild(o)}for(let o of t.stylesheets){let r=document.createElement("link");r.rel="stylesheet",r.type="text/css",r.href=o,i.appendChild(r)}for(let o of t.scripts)if(o.src){let r=document.createElement("script");r.type=o.type,r.src=o.src,i.appendChild(r)}else console.error("Script without src",o);l(),document.title=t.title;let s=document.getElementById("title");return s&&(s.setAttribute("short_title",t.short_title||t.title),s.innerText=t.title),c=t,!0}function g(t){return history.replaceState({data:c,url:location.href,scrollPos:[document.documentElement.scrollLeft||document.body.scrollLeft,document.documentElement.scrollTop||document.body.scrollTop],stateType:"dynLoad"},document.title,location.href),u(t)}async function u(t,e=!1){if(!e&&t===location.href){l();return}i.prepend("Laden... Wenn dies zu lange (über ein paar Sekunden) dauert, lade bitte die Seite neu."),await f(t,"",n=>d(n,!1),n=>{t===location.href?location.reload():location.href=t},"application/vnd.asozial.dynload+json")}async function m(t){if(t.state){let e=t.state;if(t.state.data&&d(e,!0)||await u(e.url||location.href,!0),e.scrollPos){scrollTo(e.scrollPos[0],e.scrollPos[1]);return}}console.error("Couldn't handle state.",t.state),location.reload()}h.dynLoad=m,document.addEventListener("click",t=>{var o,r;if(((o=t.target)==null?void 0:o.tagName)!=="A")return;let e=t.target;if(e.target==="_blank")return;let n=(e.href.startsWith("/")?location.origin+e.href:e.href).trim(),s=n.split("?")[0];!n.startsWith(location.origin)||((r=s.split("/").pop())!=null?r:"").includes(".")&&s!==location.origin+"/redirect"||s===location.origin+"/chat"||n.startsWith("#")||n.startsWith("".concat(location.href.split("#")[0],"#"))||(t.preventDefault(),g(n).then(()=>{e.blur()}))});
// @license-end
//# sourceMappingURL=dynload.js.map
