@nickbusey/thelounge
Version:
The self-hosted Web IRC client
1 lines • 2.23 kB
JavaScript
;(function(){const msg=document.getElementById("loading-page-message");msg&&(msg.textContent="Loading the app…"),document.getElementById("loading-reload")?.addEventListener("click",(()=>location.reload()));const displayReload=()=>{const e=document.getElementById("loading-reload");e&&(e.style.visibility="visible")},loadingSlowTimeout=setTimeout((()=>{const e=document.getElementById("loading-slow");e&&(e.style.visibility="visible"),displayReload()}),5e3),errorHandler=e=>{if(!msg)return;msg.textContent="An error has occurred that prevented the client from loading correctly.";const t=document.createElement("summary");t.textContent="More details";const r=document.createElement("pre");r.textContent=e.message;const n=document.createElement("p");n.textContent="Open the developer tools of your browser for more information.";const o=document.createElement("details");o.appendChild(t),o.appendChild(r),o.appendChild(n),msg.parentNode?.insertBefore(o,msg.nextSibling),window.clearTimeout(loadingSlowTimeout),displayReload()};window.addEventListener("error",errorHandler),window.g_TheLoungeRemoveLoading=()=>{delete window.g_TheLoungeRemoveLoading,window.clearTimeout(loadingSlowTimeout),window.removeEventListener("error",errorHandler),document.getElementById("loading")?.remove()};try{const userSettings=JSON.parse(localStorage.getItem("settings")||"{}"),themeEl=document.getElementById("theme");if(!themeEl)return;if("string"==typeof userSettings.theme&&themeEl?.dataset.serverTheme!==userSettings.theme&&themeEl.setAttribute("href",`themes/${userSettings.theme}.css`),"string"==typeof userSettings.userStyles&&!/[?&]nocss/.test(window.location.search)){const e=document.getElementById("user-specified-css");if(!e)return;e.innerHTML=userSettings.userStyles}"string"!=typeof userSettings.userScripts||/[?&]nocss/.test(window.location.search)||eval(userSettings.userScripts)}catch(e){}if("serviceWorker"in navigator){navigator.serviceWorker.register("service-worker.js");const e=t=>{"fetch-error"===t.data.type&&(errorHandler({message:`Service worker failed to fetch an url: ${t.data.message}`}),navigator.serviceWorker.removeEventListener("message",e))};navigator.serviceWorker.addEventListener("message",e)}})();