1 line
8.5 KiB
JavaScript
Raw Normal View History

"use strict";window.$=window.aero=(n=>document.getElementById(n)),$.lastRequest=null,$.currentUrl=$.originalUrl=window.location.pathname,$.classes={fadeIn:"fade-in",fadeOut:"fade-out"},$.init=function(){document.removeEventListener("DOMContentLoaded",$.init),$.content=$("content"),$.loadingAnimation=$("loading-animation"),$.content.addEventListener($.getTransitionEventName(),(n=>{return n.target===$.content&&n.target.classList.contains($.classes.fadeOut)?$.content.response?($.setContent($.content.response),void $.scrollToTop()):void($.content.transitionEnded=!0):void 0})),$.ajaxifyLinks(),$.markActiveLinks()},document.addEventListener("DOMContentLoaded",$.init),window.addEventListener("popstate",(n=>{n.state?$.load(n.state,!1):$.currentUrl!==$.originalUrl&&$.load($.originalUrl,!1)}));;let onLinkClick=function(i){if(2!==i.which){let n=this.getAttribute("href");i.preventDefault(),i.stopPropagation(),n!==window.location.pathname&&$.load(n)}};$.ajaxifyLinks=(i=>{i||(i=document.body);for(let n=i.querySelectorAll(".ajax"),o=0;o<n.length;o++){let t=n[o];t.classList.remove("ajax"),t.onclick=onLinkClick}});;$.emit=(e=>{document.dispatchEvent(new Event(e,{bubbles:!0,cancelable:!0}))});;$.executeScripts=(n=>{n||(n=$.content);for(let t=n.getElementsByTagName("script"),e=0;e<t.length;e++){let i=t[e];"application/json"!==i.type&&"application/ld+json"!==i.type&&new Function(i.innerHTML)()}});;$.fadeIn=(s=>{s&&(s.classList.remove($.classes.fadeOut),s.classList.add($.classes.fadeIn))});;$.fadeOut=(s=>{s&&(s.classList.remove($.classes.fadeIn),s.classList.add($.classes.fadeOut))});;$.get=(e=>{return new Promise(((t,o)=>{let n=new XMLHttpRequest;n.onerror=(()=>o(new Error("You are either offline or the requested page doesn't exist."))),n.ontimeout=(()=>o(new Error("The page took too much time to respond."))),n.onload=(()=>{n.status<200||n.status>=400?o(n.responseText):t(n.responseText)}),n.open("GET",e,!0),n.send(),$.lastRequest=n}))});;$.getJSON=(e=>$.get(e).then(JSON.parse));;$.getTransitionEventName=(()=>{let n=document.createElement("fakeelement"),i={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(let t in i)if(void 0!==n.style[t])return i[t]});;$.load=((t,n=true)=>{$.lastRequest&&($.lastRequest.abort(),$.lastRequest=null),$.currentUrl=t,n&&history.pushState(t,null,t),$.content.response=null,$.content.transitionEnded=!1,$.fadeIn($.loadingAnimation),$.fadeOut($.content);let e=n=>{return t===$.currentUrl?$.content.transitionEnded?($.setContent(n),void $.scrollToTop()):void($.content.response=n):void 0};$.get("/_"+t).then(e).catch(e),$.markActiveLinks(t)});;$.markActiveLinks=((e,t)=>{"object"==typeof e&&(t=e,e=void 0),void 0===e&&(e=window.location.pathname),void 0===t&&(t=document.body);for(let i=t.querySelectorAll("a"),o=0;o<i.length;o++){let a=i[o],c=a.getAttribute("href");e===c?a.classList.add("active"):a.classList.remove("active")}$.emit("ActiveLinksMarked")});;$.post=((e,t)=>{return new Promise(((n,o)=>{let r=new XMLHttpRequest;r.onerror=(()=>o(new Error("Error requesting "+e))),r.ontimeout=(()=>o(new Error("Timeout requesting "+e))),r.onload=(()=>{r.status<200||r.status>=400?o(r.responseText):n(r.responseText)}),r.open("POST",e,!0),"object"==typeof t?(r.setRequestHeader("Content-type","application/json"),r.send(JSON.stringify(t))):r.send(t),$.lastRequest=r}))});;$.scrollToTop=(()=>{for(let o=$.content;o=o.parentElement;)o.scrollTop=0});;$.setContent=(n=>{$.content.innerHTML=n,$.fadeIn($.content),$.fadeOut($.loadingAnimation),$.ajaxifyLinks($.content),$.markActiveLinks($.content),$.executeScripts($.content),$.emit("DOMContentLoaded")});document.addEventListener("keydown",(e=>{if(65===e.keyCode&&e.altKey){let l=$("staff-info");"block"!==l.style.display?l.style.display="block":l.style.display="none"}}));;function updateAvatars(){for(let t=document.querySelectorAll(".user-image"),e=0;e<t.length;++e){let a=t[e];0===a.naturalWidth?(a.onload=function(){this.style.opacity=1},a.onerror=function(){this.src="//media.notify.moe/images/elements/no-avatar.svg",this