(function(){"use strict";window.addEventListener("DOMContentLoaded",()=>{const o="chatrix-logout";!document.cookie.split(";").some(s=>s.trim().startsWith(`${o}=`))||(console.log("Logging out all chatrix sessions"),c().then(()=>{const s=new Date().toUTCString();document.cookie=`${o}=false; expires=${s};path=/;`}).catch(s=>console.error(s)))});async function c(){var i,n;let o="";for(const[t]of Object.entries(localStorage))if(t.startsWith("chatrix_sessions")){o=t;break}const a=JSON.parse((i=localStorage.getItem(o))!=null?i:"[]");let e=[];Array.isArray(a)&&a.forEach(t=>e.push(l(t))),await Promise.all(e);for(const[t]of Object.entries(localStorage))(t.startsWith("chatrix")||t.startsWith("hydrogen"))&&localStorage.removeItem(t);const s=await indexedDB.databases();for(const t of s){const r=(n=t.name)!=null?n:"";(r.startsWith("chatrix")||r.startsWith("hydrogen"))&&await indexedDB.deleteDatabase(r)}}async function l(o){let a=fetch(o.homeserver+"/_matrix/client/v3/logout",{method:"POST",headers:{Authorization:"Bearer "+o.accessToken}}).then(e=>{if(!e.ok)throw e;return e});return a.catch(e=>{console.error(`Failed to logout chatrix session. deviceId: ${o.deviceId}`)}),a}})();
