/* A note from Andrew, Do not download this. Instead, hotlink it in your projects so you are always running the latest version. Server side code changes often, client side code not being up to date can break chattable on your site. How to Hotlink: Add this inside your
element, Enjoy Chattable. Andrew P.S. Want to know what this code does? Read the not minified version here: https://iframe.chat/scripts/main.js */ var chattableLoadingLoop,chattable={user:{flair:localStorage.flair?localStorage.flair:null,name:null},loaded:!1,commands:!1,settings:{visible:!0,theme:!1,pendingMessages:[],initialized:!1},reload(){let e=document.getElementById("chattable");e.src=e.src},returnFrame:()=>document.getElementById("chattable"),frameReadyPromise:null,frameReadyResolve:null,initializeFramePromise(){return this.frameReadyPromise||(this.frameReadyPromise=new Promise((e=>{this.frameReadyResolve=e}))),this.frameReadyPromise},async sendMessageToFrame(e){await this.frameReadyPromise;const a=this.returnFrame();return!(!a||!a.contentWindow)&&(a.contentWindow.postMessage(e,"*"),!0)},async redraw(){window.chattableStylesheet?await this.sendMessageToFrame(window.chattableStylesheet):console.warn("Unable to redraw, no previous styles available")},async loadStyle(e){try{console.log("Loading CSS source file...");const a=await fetch(e);if(!a.ok)throw new Error(`HTTP error! status: ${a.status}`);const t=await a.text();window.chattableStylesheet=t,await this.sendMessageToFrame(t)}catch(e){return console.error("Error loading stylesheet:",e),!1}},async loadTheme(e){const a=`load_theme:${{"hacker terminal":"/demo/hacker.css",amber:"/demo/amber.css","comment section":"/demo/comment.css",confidential:"/demo/confidential.css",notepad:"/demo/notepad.css","pastel pink":"/demo/pastel.css",moderno:"/demo/moderno.css","retrowave red":"/demo/red.css","windows xp":"/demo/xp.css","wannabe xp":"/demo/xp.css",winbows:"/demo/xp.css","winbows xp":"/demo/xp.css",kick:"/demo/kick.css",tendo:"/demo/tendo.css",amdroid:"/demo/amdroid.css",android:"/demo/amdroid.css",glass:"/demo/glass.css",professional:"/demo/dashboard-chat.css",bytechat:"/demo/bytechat.css"}[e]}`;window.chattableStylesheet=a,await this.sendMessageToFrame(a)},reinitialize:function(e){if(e&&(e.stylesheet?chattable.loadStyle(e.stylesheet):e.theme?chattable.loadTheme(e.theme.toLowerCase()):chattable.sendMessageToFrame("body {}")),this.commands){let e={};for(command in this.commands)e[command]=!0;this.sendMessageToFrame({type:"storeCommands",commands:e})}},initialize(e){const a=[];let t=!1,s=!1;return console.log("Initializing..."),chattable.parameters=e,chattableLoadingLoop=setInterval((function(){if(chattable.loaded)clearInterval(chattableLoadingLoop);else if(chattable.returnFrame()){if(e&&(e.stylesheet?chattable.loadStyle(e.stylesheet):e.theme?chattable.loadTheme(e.theme.toLowerCase()):chattable.sendMessageToFrame("body {}")),chattable.commands){let e={};for(command in chattable.commands)e[command]=!0;chattable.sendMessageToFrame({type:"storeCommands",commands:e})}s=!0;let n=setInterval((function(){chattable.settings.initialized&&(clearInterval(n),t||(t=!0,a.forEach((function(e){e(s)}))))}),250);localStorage.flair&&chattable.setFlair(localStorage.flair)}}),500),{then:function(e){s&&chattable.settings.initialized?e(s):a.push(e)}}},minimize:function(){var e=chattable.returnFrame(),a=e.style.transition;chattable.settings.oldHeight=e.style.height?e.style.height:e.offsetHeight,chattable.settings.oldStyle=e.style,e.style.transition="all 500ms ease-out",e.style.minHeight="0",e.style.height="0",setTimeout((function(){e.style.transition=a,chattable.settings.visible=!1}),500)},maximize:function(){var e=chattable.returnFrame();e.style.transition="all 500ms ease-out",e.style.height=parseInt(chattable.settings.oldHeight)+"px",setTimeout((function(){e.style=chattable.settings.oldStyle,chattable.settings.visible=!0}),500)},changeRoom:function(e){var a="https://iframe.chat/embed?chat="+e;chattable.returnFrame().src=a},setFlair:function(e){chattable.sendMessageToFrame({type:"setFlair",flair:e.toString()}),localStorage.flair=e,chattable.user.flair=e},sendMessage:function(e,a,t,s,n){e&&"string"==typeof e?chattable.sendMessageToFrame({type:"sendMessage",text:e,name:a||void 0,flair:t||void 0,perms:!!s,object:n||void 0}):console.error("Failed to call chattable.sendMessage(), you must provide a string as a first parameter.")},request:function(e){chattable.sendMessageToFrame({type:"request",reqObj:e})},setName:function(e){confirm('This site wants to change your chat handle to "'+e+'". Do you accept?')&&(chattable.sendMessageToFrame({type:"setName",value:e.toString()}),chattable.user.name=e.toString())},handlers:{message:[],payload:[],connection:[],load:[]},on:function(e,a){switch(e){case"message":chattable.handlers.message.push(a);break;case"payload":chattable.handlers.payload.push(a);break;case"connection":chattable.handlers.connection.push(a);break;case"load":chattable.handlers.load.push(a)}},off:function(e,a){switch(e){case"message":if(chattable.handlers.message.includes(a)){const e=chattable.handlers.message.indexOf(a);e>-1&&chattable.handlers.message.splice(e,1)}else console.error("Can't turn off that handler, it doesn't exist.");break;case"payload":if(chattable.handlers.payload.includes(a)){const e=chattable.handlers.payload.indexOf(a);e>-1&&chattable.handlers.payload.splice(e,1)}else console.error("Can't turn off that handler, it doesn't exist.");break;case"connection":if(chattable.handlers.connection.includes(a)){const e=chattable.handlers.connection.indexOf(a);e>-1&&chattable.handlers.connection.splice(e,1)}else console.error("Can't turn off that handler, it doesn't exist.");break;case"load":if(chattable.handlers.load.includes(a)){const e=chattable.handlers.load.indexOf(a);e>-1&&chattable.handlers.load.splice(e,1)}else console.error("Can't turn off that handler, it doesn't exist.")}},sendPayload:function(e){try{e=JSON.stringify(e),chattable.sendMessageToFrame({type:"sendPayload",value:e})}catch(e){console.error(e)}}};window.addEventListener("message",(function(e){let a=e.data;if("object"==typeof a)switch(a.type){case"runCommand":a.name?chattable.commands[a.name]?chattable.commands[a.name](a.full,a):console.error(`Can not execute command, this command doesn't exist. Chattable.commands['${a.name}']`):console.error("Can not execute command, no command name provided.");break;case"init":console.log("Initializing Library...");let e=a.name;if(e.match(/^\&\&(.*?)\$$/gi)&&(e=new String(e).replace(/^\&\&|\$$/gi,"")),chattable.user.name=e,chattable.user.uid=a.uid,chattable.settings.initialized=!0,chattable.handlers.load.length>0)for(let e=0;e