BetterDiscordApp-rauenzi/js/main.min.js

52 lines
79 KiB
JavaScript

(function(){let a=window.require("fs"),r=window.require("process"),o=r.platform,d=("win32"===o?r.env.APPDATA:"darwin"===o?r.env.HOME+"/Library/Preferences":process.env.HOME+"/.config")+"/BetterDiscord/",l="localStorage.json",u={};if(a.existsSync(`${d}${l}`))try{u=JSON.parse(a.readFileSync(`${d}${l}`))}catch(b){console.log(b)}else if(a.existsSync(l))try{u=JSON.parse(a.readFileSync(l))}catch(b){console.log(b)}var h=u;h.setItem=function(b,y){h[b]=y,this.save()},h.getItem=function(b){return h[b]||null},h.save=function(){a.writeFileSync(`${d}${l}`,JSON.stringify(this),null,4)};var g=new Proxy(h,{set:function(b,y,E){h[y]=E,h.save()},get:function(b,y){return h[y]||null}});window.localStorage=g})(),(()=>{let a=document.createElement("div");a.className="bd-loaderv2",a.title="BetterDiscord is loading...",document.body.appendChild(a)})(),window.bdStorage={},window.bdStorage.get=function(a){return betterDiscordIPC.sendSync("synchronous-message",{arg:"storage",cmd:"get","var":a})},window.bdStorage.set=function(a,r){betterDiscordIPC.sendSync("synchronous-message",{arg:"storage",cmd:"set","var":a,data:r})},window.bdPluginStorage={},window.bdPluginStorage.get=function(a,r){return betterDiscordIPC.sendSync("synchronous-message",{arg:"pluginstorage",cmd:"get",pn:a,"var":r})},window.bdPluginStorage.set=function(a,r,o){betterDiscordIPC.sendSync("synchronous-message",{arg:"pluginstorage",cmd:"set",pn:a,"var":r,data:o})},betterDiscordIPC.on("asynchronous-reply",(a,r)=>{console.log(a),console.log(r)});var settingsPanel,emoteModule,utils,quickEmoteMenu,voiceMode,pluginModule,themeModule,dMode,publicServersModule,jsVersion=1.792,supportedVersion="0.2.81",bbdVersion="0.0.5",mainObserver,twitchEmoteUrlStart="https://static-cdn.jtvnw.net/emoticons/v1/",twitchEmoteUrlEnd="/1.0",ffzEmoteUrlStart="https://cdn.frankerfacez.com/emoticon/",ffzEmoteUrlEnd="/1",bttvEmoteUrlStart="https://cdn.betterttv.net/emote/",bttvEmoteUrlEnd="/1x",mainCore,settings={"Save logs locally":{id:"bda-gs-0",info:"Saves chat logs locally",implemented:!1,hidden:!1,cat:"core"},"Public Servers":{id:"bda-gs-1",info:"Display public servers button",implemented:!0,hidden:!1,cat:"core"},"Minimal Mode":{id:"bda-gs-2",info:"Hide elements and reduce the size of elements.",implemented:!0,hidden:!1,cat:"core"},"Voice Mode":{id:"bda-gs-4",info:"Only show voice chat",implemented:!0,hidden:!1,cat:"core"},"Hide Channels":{id:"bda-gs-3",info:"Hide channels in minimal mode",implemented:!0,hidden:!1,cat:"core"},"Dark Mode":{id:"bda-gs-5",info:"Make certain elements dark by default(wip)",implemented:!0,hidden:!1,cat:"core"},"Override Default Emotes":{id:"bda-es-5",info:"Override default emotes",implemented:!1,hidden:!1,cat:"core"},"Voice Disconnect":{id:"bda-dc-0",info:"Disconnect from voice server when closing Discord",implemented:!0,hidden:!1,cat:"core"},"Custom css live update":{id:"bda-css-0",info:"",implemented:!0,hidden:!0,cat:"core"},"Custom css auto udpate":{id:"bda-css-1",info:"",implemented:!0,hidden:!0,cat:"core"},"24 Hour Timestamps":{id:"bda-gs-6",info:"Replace 12hr timestamps with proper ones",implemented:!0,hidden:!1,cat:"core"},"Coloured Text":{id:"bda-gs-7",info:"Make text colour the same as role colour",implemented:!0,hidden:!1,cat:"core"},"BetterDiscord Blue":{id:"bda-gs-b",info:"Replace Discord blue with BD Blue",implemented:!0,hidden:!1,cat:"core"},"Developer Mode":{id:"bda-gs-8",info:"Developer Mode",implemented:!0,hidden:!1,cat:"core"},"Startup Error Modal":{id:"fork-ps-1",info:"Show a modal with plugin/theme errors on startup",implemented:!0,hidden:!1,cat:"fork"},"Show Toasts":{id:"fork-ps-2",info:"Shows a small notification for starting and stopping plugins & themes",implemented:!0,hidden:!1,cat:"fork"},"Scroll To Settings":{id:"fork-ps-3",info:"Auto-scrolls to a plugin's settings when the button is clicked (only if out of view)",implemented:!0,hidden:!1,cat:"fork"},"Emote Modifier Tooltip":{id:"fork-es-1",info:"Shows the emote modifier in the tooltip.",implemented:!0,hidden:!1,cat:"fork"},"Animate On Hover":{id:"fork-es-2",info:"Only animate the emote modifiers on hover",implemented:!0,hidden:!1,cat:"fork"},"Copy Selector":{id:"fork-dm-1",info:"Adds a \"Copy Selector\" option to context menus when developer mode is active",implemented:!0,hidden:!1,cat:"fork"},"Twitch Emotes":{id:"bda-es-7",info:"Show Twitch emotes",implemented:!0,hidden:!1,cat:"emote"},"FrankerFaceZ Emotes":{id:"bda-es-1",info:"Show FrankerFaceZ Emotes",implemented:!0,hidden:!1,cat:"emote"},"BetterTTV Emotes":{id:"bda-es-2",info:"Show BetterTTV Emotes",implemented:!0,hidden:!1,cat:"emote"},"Emote Menu":{id:"bda-es-0",info:"Show Twitch/Favourite emotes in emote menu",implemented:!0,hidden:!1,cat:"emote"},"Emoji Menu":{id:"bda-es-9",info:"Show Discord emoji menu",implemented:!0,hidden:!1,cat:"emote"},"Emote Autocomplete":{id:"bda-es-3",info:"Autocomplete emote commands",implemented:!1,hidden:!1,cat:"emote"},"Emote Auto Capitalization":{id:"bda-es-4",info:"Autocapitalize emote commands",implemented:!0,hidden:!1,cat:"emote"},"Show Names":{id:"bda-es-6",info:"Show emote names on hover",implemented:!0,hidden:!1,cat:"emote"},"Show emote modifiers":{id:"bda-es-8",info:"Enable emote mods (flip, spin, pulse, spin2, spin3, 1spin, 2spin, 3spin, tr, bl, br, shake, shake2, shake3, flap)",implemented:!0,hidden:!1,cat:"emote"}},defaultCookie={version:jsVersion,"bda-gs-0":!1,"bda-gs-1":!1,"bda-gs-2":!1,"bda-gs-3":!1,"bda-gs-4":!1,"bda-gs-5":!0,"bda-gs-6":!1,"bda-gs-7":!1,"bda-gs-8":!1,"bda-es-0":!0,"bda-es-1":!0,"bda-es-2":!0,"bda-es-3":!1,"bda-es-4":!1,"bda-es-5":!0,"bda-es-6":!0,"bda-es-7":!0,"bda-gs-b":!0,"bda-es-8":!0,"bda-jd":!0,"bda-dc-0":!1,"bda-css-0":!1,"bda-css-1":!1,"bda-es-9":!0,"fork-dm-1":!1,"fork-ps-1":!0,"fork-ps-2":!0,"fork-ps-3":!0,"fork-es-1":!0,"fork-es-2":!1},settingsCookie={},bdpluginErrors,bdthemeErrors,bdConfig=null;function Core(a){a?a.newLoader=!0:a={branch:"master",repo:"rauenzi",updater:{CDN:"cdn.rawgit.com"}},window.bdConfig=a}Core.prototype.init=async function(){function a(){console.log(new Date().getTime()+" Defer"),0<document.querySelectorAll(".guilds .guild").length?(console.log(new Date().getTime()+" Defer Loaded"),r.injectExternals(),utils.log("Updating Settings"),settingsPanel=new V2_SettingsPanel,settingsPanel.updateSettings(),!bdpluginErrors&&(bdpluginErrors=[]),!bdthemeErrors&&(bdthemeErrors=[]),utils.log("Loading Plugins"),pluginModule=new PluginModule,pluginModule.loadPlugins(),utils.log("Loading Themes"),themeModule=new ThemeModule,themeModule.loadThemes(),$("#customcss").detach().appendTo(document.head),utils.log("Initializing QuickEmoteMenu"),quickEmoteMenu.init(),window.addEventListener("beforeunload",function(){settingsCookie["bda-dc-0"]&&document.querySelector(".btn.btn-disconnect").click()}),publicServersModule.initialize(),emoteModule.autoCapitalize(),settingsCookie.version<jsVersion&&(settingsCookie.version=jsVersion,r.saveSettings()),utils.log("Removing Loading Icon"),document.getElementsByClassName("bd-loaderv2")[0].remove(),utils.log("Initializing Main Observer"),r.initObserver(),settingsCookie["fork-ps-1"]&&(utils.log("Collecting Startup Errors"),r.showStartupErrors())):setTimeout(a,100)}var r=this,o="undefined"==typeof version?bdVersion:version;return o<supportedVersion?void this.alert("Not Supported","BetterDiscord v"+o+"(your version) is not supported by the latest js("+jsVersion+").<br><br> Please download the latest version from <a href='https://betterdiscord.net' target='_blank'>BetterDiscord.net</a>"):void(utils=new Utils,utils.getHash(),publicServersModule=new V2_PublicServers,emoteModule=new EmoteModule,utils.log("Initializing EmoteModule"),emoteModule.init(),quickEmoteMenu=new QuickEmoteMenu,voiceMode=new VoiceMode,dMode=new devMode,utils.log("Initializing Settings"),this.initSettings(),$(document).ready(function(){setTimeout(a,1e3)}))},Core.prototype.injectExternals=function(){utils.injectJs("https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.9/ace.js")},Core.prototype.initSettings=function(){if(void 0==$.cookie("better-discord"))settingsCookie=defaultCookie,this.saveSettings();else for(var a in this.loadSettings(),$("<style id=\"customcss\">").html(atob(window.bdStorage.get("bdcustomcss"))).appendTo(document.head),defaultCookie)void 0==settingsCookie[a]&&(settingsCookie[a]=defaultCookie[a],this.saveSettings())},Core.prototype.saveSettings=function(){$.cookie("better-discord",JSON.stringify(settingsCookie),{expires:365,path:"/"})},Core.prototype.loadSettings=function(){settingsCookie=JSON.parse($.cookie("better-discord"))},Core.prototype.initObserver=function(){let a=this;mainObserver=new MutationObserver(function(r){r.forEach(function(o){if("undefined"!=typeof pluginModule&&pluginModule.rawObserver(o),o.removedNodes.length&&o.removedNodes[0]instanceof Element){let l=o.removedNodes[0];(l.classList.contains("activityFeed-HeiGwL")||"friends"===l.id)&&pluginModule.channelSwitch()}if(o.addedNodes.length&&o.addedNodes[0]instanceof Element){let d=o.addedNodes[0];(d.classList.contains("layer")||d.classList.contains("layer-kosS71"))&&(d.querySelector(".guild-settings-base-section")&&d.setAttribute("layer-id","server-settings"),d.getElementsByClassName("socialLinks-1oZoF3").length&&(d.setAttribute("layer-id","user-settings"),!d.querySelector("#bd-settings-sidebar")&&settingsPanel.renderSidebar())),d.classList.contains("popout")&&!d.classList.contains("popout-left")&&(d.getElementsByClassName("emoji-picker").length||d.getElementsByClassName("emojiPicker-3g68GS").length)&&quickEmoteMenu.obsCallback(d),(d.classList.contains("activityFeed-HeiGwL")||"friends"===d.id)&&pluginModule.channelSwitch(),(d.classList.contains("messages-wrapper")||d.querySelector(".messages-wrapper"))&&(a.inject24Hour(d),a.injectColoredText(d),pluginModule.channelSwitch()),d.classList.contains("message-group")&&(a.inject24Hour(d),a.injectColoredText(d),!d.querySelector(".message-sending")&&d.parentElement&&d.parentElement.children&&d==d.parentElement.children[d.parentElement.children.length-1]&&pluginModule.newMessage()),d.classList.contains("message-text")&&a.injectColoredText(d.parentElement.parentElement.parentElement.parentElement),d.classList.contains("message")&&(a.injectColoredText(d.parentElement.parentElement),!d.classList.contains("message-sending")&&pluginModule.newMessage())}})}),mainObserver.observe(document,{childList:!0,subtree:!0})},Core.prototype.inject24Hour=function(a){settingsCookie["bda-gs-6"]&&a.querySelectorAll(".timestamp").forEach(r=>{if(!r.getAttribute("data-24")){let o=r.innerText||r.textContent,d=/([^0-9]*)([0-9]?[0-9]:[0-9][0-9])([^0-9]*)/.exec(o);if(null!=d&&!(4>d.length)){let l=d[2].split(":"),u=parseInt(l[0]),h=l[1],g=d[3].toLowerCase();g.includes("am")&&12==u?u-=12:g.includes("pm")&&12>u&&(u+=12),u=("0"+u).slice(-2),r.innerText=d[1]+u+":"+h+d[3],r.setAttribute("data-24",d[2])}}})},Core.prototype.remove24Hour=function(a){a.querySelectorAll(".timestamp").forEach(r=>{if(r.getAttribute("data-24")){let o=r.getAttribute("data-24");r.removeAttribute("data-24");let d=r.innerText||r.textContent,l=/([^0-9]*)([0-9]?[0-9]:[0-9][0-9])([^0-9]*)/.exec(d);null==l||4>l.length||(r.innerText=l[1]+o+l[3])}})},Core.prototype.injectColoredText=function(a){settingsCookie["bda-gs-7"]&&a.querySelectorAll(".user-name").forEach(r=>{let o=r.style.color;"rgb(255, 255, 255)"===o||r.closest(".message-group").querySelectorAll(".markup").forEach(d=>{d.getAttribute("data-colour")||(d.setAttribute("data-colour",!0),d.style.setProperty("color",o))})})},Core.prototype.removeColoredText=function(a){a.querySelectorAll(".user-name").forEach(r=>{r.closest(".message-group").querySelectorAll(".markup").forEach(o=>{o.getAttribute("data-colour")&&(o.removeAttribute("data-colour"),o.style.setProperty("color",""))})})},Core.prototype.alert=function(a,r){let o=$(`<div class="bd-modal-wrapper theme-dark">
<div class="bd-backdrop backdrop-2ohBEd"></div>
<div class="bd-modal modal-2LIEKY">
<div class="bd-modal-inner inner-1_1f7b">
<div class="header header-3sp3cE">
<div class="title">${a}</div>
</div>
<div class="bd-modal-body">
<div class="scroller-wrap fade">
<div class="scroller">
${r}
</div>
</div>
</div>
<div class="footer footer-1PYmcw">
<button type="button">Okay</button>
</div>
</div>
</div>
</div>`);o.find(".footer button").on("click",()=>{o.addClass("closing"),setTimeout(()=>{o.remove()},300)}),o.find(".bd-backdrop").on("click",()=>{o.addClass("closing"),setTimeout(()=>{o.remove()},300)}),o.appendTo("#app-mount")},Core.prototype.showStartupErrors=function(){function a(d){let l=$(`<div class="errors">`);for(let u of d){let h=$(`<div class="error">
<div class="table-column column-name">${u.name?u.name:u.file}</div>
<div class="table-column column-reason">${u.reason}</div>
<div class="table-column column-error"><a class="error-link" href="">${u.error?u.error.message:""}</a></div>
</div>`);l.append(h),u.error&&h.find("a").on("click",g=>{g.preventDefault(),utils.err(`Error details for ${u.name?u.name:u.file}.`,u.error)})}return l}if(bdpluginErrors&&bdthemeErrors&&(bdpluginErrors.length||bdthemeErrors.length)){let r=$(`<div class="bd-modal-wrapper theme-dark">
<div class="bd-backdrop backdrop-2ohBEd"></div>
<div class="bd-modal bd-startup-modal modal-2LIEKY">
<div class="bd-modal-inner inner-1_1f7b">
<div class="header header-3sp3cE"><div class="title">Startup Errors</div></div>
<div class="bd-modal-body">
<div class="tab-bar-container">
<div class="tab-bar TOP">
<div class="tab-bar-item">Plugins</div>
<div class="tab-bar-item">Themes</div>
</div>
</div>
<div class="table-header">
<div class="table-column column-name">Name</div>
<div class="table-column column-reason">Reason</div>
<div class="table-column column-error">Error</div>
</div>
<div class="scroller-wrap fade">
<div class="scroller">
</div>
</div>
</div>
<div class="footer footer-1PYmcw">
<button type="button">Okay</button>
</div>
</div>
</div>
</div>`),o=[a(bdpluginErrors),a(bdthemeErrors)];r.find(".tab-bar-item").on("click",d=>{d.preventDefault(),r.find(".tab-bar-item").removeClass("selected"),$(d.target).addClass("selected"),r.find(".scroller").empty().append(o[$(d.target).index()])}),r.find(".footer button").on("click",()=>{r.addClass("closing"),setTimeout(()=>{r.remove()},300)}),r.find(".bd-backdrop").on("click",()=>{r.addClass("closing"),setTimeout(()=>{r.remove()},300)}),r.appendTo("#app-mount"),r.find(".tab-bar-item")[0].click()}},Core.prototype.showToast=function(a,r={}){if(!document.querySelector(".bd-toasts")){let h=document.createElement("div");h.classList.add("bd-toasts");let g=document.querySelector(".chat form, #friends, .noChannel-2EQ0a9, .activityFeed-HeiGwL");h.style.setProperty("left",g?g.getBoundingClientRect().left+"px":"0px"),h.style.setProperty("width",g?g.offsetWidth+"px":"100%"),h.style.setProperty("bottom",(document.querySelector(".chat form")?document.querySelector(".chat form").offsetHeight:80)+"px"),document.querySelector(".app").appendChild(h)}const{type:o="",icon:d=!0,timeout:l=3e3}=r;let u=document.createElement("div");u.classList.add("bd-toast"),o&&u.classList.add("toast-"+o),o&&d&&u.classList.add("icon"),u.innerText=a,document.querySelector(".bd-toasts").appendChild(u),setTimeout(()=>{u.classList.add("closing"),setTimeout(()=>{u.remove(),document.querySelectorAll(".bd-toasts .bd-toast").length||document.querySelector(".bd-toasts").remove()},300)},l)};var emotesFfz={},emotesBTTV={},emotesBTTV2={},emotesTwitch={},subEmotesTwitch={};window.bdEmotes={TwitchGlobal:{},TwitchSubscriber:{},BTTV:{},FrankerFaceZ:{},BTTV2:{}},window.bdEmoteSettingIDs={TwitchGlobal:"bda-es-7",TwitchSubscriber:"bda-es-7",BTTV:"bda-es-2",FrankerFaceZ:"bda-es-1",BTTV2:"bda-es-2"};function EmoteModule(){}EmoteModule.prototype.init=async function(){this.modifiers=["flip","spin","pulse","spin2","spin3","1spin","2spin","3spin","tr","bl","br","shake","shake2","shake3","flap"],this.overrides=["twitch","bttv","ffz"],this.categories=["TwitchGlobal","TwitchSubscriber","BTTV","FrankerFaceZ","BTTV2"];let a={TwitchGlobal:{url:"https://twitchemotes.com/api_cache/v3/global.json",backup:"https://"+bdConfig.updater.CDN+"/"+bdConfig.repo+"/BetterDiscordApp/"+bdConfig.hash+"/data/emotedata_twitch_global.json",variable:"TwitchGlobal",oldVariable:"emotesTwitch",getEmoteURL:r=>`https://static-cdn.jtvnw.net/emoticons/v1/${r.id}/1.0`,getOldData:(r,o)=>{return{id:r.match(/\/([0-9]+)\//)[1],code:o,emoticon_set:0,description:null}}},TwitchSubscriber:{url:"https://twitchemotes.com/api_cache/v3/subscriber.json",backup:"https://"+bdConfig.updater.CDN+"/"+bdConfig.repo+"/BetterDiscordApp/"+bdConfig.hash+"/data/emotedata_twitch_subscriber.json",variable:"TwitchSubscriber",oldVariable:"subEmotesTwitch",parser:r=>{let o={};for(let d in r){let l=r[d];for(let g,u=0,h=l.emotes.length;u<h;u++)g=l.emotes[u],o[g.code]=g.id}return o},getEmoteURL:r=>`https://static-cdn.jtvnw.net/emoticons/v1/${r}/1.0`,getOldData:r=>r.match(/\/([0-9]+)\//)[1]},FrankerFaceZ:{url:"https://"+bdConfig.updater.CDN+"/"+bdConfig.repo+"/BetterDiscordApp/"+bdConfig.hash+"/data/emotedata_ffz.json",variable:"FrankerFaceZ",oldVariable:"emotesFfz",getEmoteURL:r=>`https://cdn.frankerfacez.com/emoticon/${r}/1`,getOldData:r=>r.match(/\/([0-9]+)\//)[1]},BTTV:{url:"https://api.betterttv.net/emotes",variable:"BTTV",oldVariable:"emotesBTTV",parser:r=>{let o={};for(let u,d=0,l=r.emotes.length;d<l;d++)u=r.emotes[d],o[u.regex]=u.url;return o},getEmoteURL:r=>`${r}`,getOldData:r=>r},BTTV2:{url:"https://"+bdConfig.updater.CDN+"/"+bdConfig.repo+"/BetterDiscordApp/"+bdConfig.hash+"/data/emotedata_bttv.json",variable:"BTTV2",oldVariable:"emotesBTTV2",getEmoteURL:r=>`https://cdn.betterttv.net/emote/${r}/1x`,getOldData:r=>r.match(/emote\/(.+)\//)[1]}};if(!bdConfig.newLoader){for(let r in window.bdEmotes={TwitchGlobal:emotesTwitch,TwitchSubscriber:subEmotesTwitch,BTTV:emotesBTTV,FrankerFaceZ:emotesFfz,BTTV2:emotesBTTV2},window.bdEmotes)for(let o in window.bdEmotes[r])window.bdEmotes[r][o]=a[r].getEmoteURL(window.bdEmotes[r][o]);return}this.loadEmoteData(a),BDV2.ReactComponents.get("Message").then(r=>{this.cancel1=Utils.monkeyPatch(r.prototype,"componentDidMount",{after:o=>{let d=BDV2.reactDom.findDOMNode(o.thisObject);d=d.querySelector(".markup"),$(d).children(".emotewrapper").remove(),emoteModule.injectEmote(d)}}),this.cancel2=Utils.monkeyPatch(r.prototype,"componentDidUpdate",{after:o=>{let d=BDV2.reactDom.findDOMNode(o.thisObject);d=d.querySelector(".markup");d&&($(d).children(".emotewrapper").remove(),emoteModule.injectEmote(d))}})})},EmoteModule.prototype.clearEmoteData=async function(){let a=require("fs"),o=bdConfig.dataPath+"emote_data.json",d=a.existsSync(o);d&&a.unlinkSync(o),window.bdEmotes={TwitchGlobal:{},TwitchSubscriber:{},BTTV:{},FrankerFaceZ:{},BTTV2:{}}},EmoteModule.prototype.goBack=async function(a){for(let r in a)for(let o in bdEmotes[a[r].variable])window[a[r].oldVariable][o]=a[r].getOldData(bdEmotes[a[r].variable][o],o)},EmoteModule.prototype.loadEmoteData=async function(a){let r=require("fs"),d=bdConfig.dataPath+"emote_data.json",l=r.existsSync(d);if(l&&!bdConfig.cache.expired){settingsCookie["fork-ps-2"]&&mainCore.showToast("Loading emotes from cache.",{type:"info"}),utils.log("[Emotes] Loading emotes from local cache.");let u=r.readFileSync(d,"utf8"),h=this.testJSON(u);for(let g in h&&(bdEmotes=JSON.parse(u)),a)h=0<Object.keys(bdEmotes[a[g].variable]).length;if(h)return await this.goBack(a),void(settingsCookie["fork-ps-2"]&&mainCore.showToast("Emotes successfully loaded.",{type:"success"}));utils.log("[Emotes] Cache was corrupt, downloading..."),r.unlinkSync(d)}for(let u in settingsCookie["fork-ps-2"]&&mainCore.showToast("Downloading emotes in the background do not reload.",{type:"info"}),a){let h=await this.downloadEmotes(a[u]);bdEmotes[a[u].variable]=h}await this.goBack(a),settingsCookie["fork-ps-2"]&&mainCore.showToast("All emotes successfully downloaded.",{type:"success"});try{r.writeFileSync(d,JSON.stringify(bdEmotes),"utf8")}catch(u){utils.err("[Emotes] Could not save emote data.",u)}quickEmoteMenu.init()},EmoteModule.prototype.downloadEmotes=function(a){let r=require("request"),o={url:a.url,timeout:a.timeout?a.timeout:5e3};return utils.log("[Emotes] Downloading: "+a.variable),new Promise((d,l)=>{r(o,(u,h,g)=>{if(u){if(utils.err("[Emotes] Could not download "+a.variable,u),a.backup)return a.url=a.backup,a.backup=null,this.downloadEmotes(a);l({})}else{let b=JSON.parse(g);for(let y in"function"==typeof a.parser&&(b=a.parser(b)),b)b[y]=a.getEmoteURL(b[y]);d(b),utils.log("[Emotes] Downloaded: "+a.variable)}})})},EmoteModule.prototype.testJSON=function(a){try{JSON.parse(a);return!0}catch(r){return!1}return!1},EmoteModule.prototype.getBlacklist=function(){$.getJSON("https://cdn.rawgit.com/Jiiks/betterDiscordApp/"+_hash+"/data/emotefilter.json",function(a){bemotes=a.blacklist})},EmoteModule.prototype.obsCallback=function(a){},EmoteModule.prototype.getNodes=function(a){for(var r,o=[],d=document.createTreeWalker(a,NodeFilter.SHOW_TEXT,null,!1);r=d.nextNode();)o.push(r);return o};var bemotes=[];EmoteModule.prototype.injectEmote=async function(a){let o=document.querySelector(".messages.scroller"),d=a,u=utils.getTextNodes(d),h=u.map(b=>b.data).join(" ").split(/([^\s]+)([\s]|$)/g).filter(function(b){return b}),g=function(b,y,E,C,S){let T=bdEmotes[E].hasOwnProperty(C);if(!T||!settingsCookie[bdEmoteSettingIDs[E]])return!1;let N=bdEmotes[E][C],D=this.createEmoteElement(C,N,S),P=b.offsetHeight;return utils.insertElement(b,new RegExp(`([\\s]|^)${utils.escape(S?C+":"+S:C)}([\\s]|$)`),$(D)[0]),y.scrollTop+=b.offsetHeight-P,!0};g=g.bind(this,d,o);for(let b=0,y=h.length;b<y;b++){let E=h[b],C=E.split(":"),S=C[0],T=C[1]?C[1]:"",N=T.slice(0);if(!(bemotes.includes(S)||4>S.length)){if(this.modifiers.includes(T)&&settingsCookie["bda-es-8"]||(T=""),this.overrides.includes(N)||(N=""),"twitch"===N){let j=!1,L=!1;if(j=g("TwitchGlobal",S,N),j||(L=g("TwitchSubscriber",S,N)),j||L)continue}else if("bttv"===N){let j=!1,L=!1;if(j=g("BTTV",S,N),j||(L=g("BTTV2",S,N)),j||L)continue}else if("ffz"===N){let j=g("FrankerFaceZ",S,N);if(j)continue}for(let j=0,L=this.categories.length;j<L;j++)g(this.categories[j],S,T);"[!s]"==E&&d.classList.add("spoiler")}}},EmoteModule.prototype.createEmoteElement=function(a,r,o){var d=Math.round(a.length/4),l=a.substr(0,d)+"\uFDD9"+a.substr(d,d)+"\uFDD9"+a.substr(2*d,d)+"\uFDD9"+a.substr(3*d),u=settingsCookie["fork-es-2"]?" stop-animation":"",h=o?"emote"+o:"";return("<span class=\"emotewrapper\"><img draggable=\"false\" style=\"max-height:32px;\" data-modifier=\""+o+"\" class=\"emote "+h+u+"\" alt=\""+l+"\" src=\""+r+"\"/><input onclick='quickEmoteMenu.favorite(\""+l+"\", \""+r+"\");' class=\"fav\" title=\"Favorite!\" type=\"button\"></span>").replace(/﷙/g,"")},EmoteModule.prototype.autoCapitalize=function(){var a=this;$("body").delegate($(".channelTextArea-1HTP3C textarea:first"),"keyup change paste",function(){if(settingsCookie["bda-es-4"]){var r=$(".channelTextArea-1HTP3C textarea:first").val();if(void 0!=r){var o=r.split(" ").pop();if(3<o.length){if("danSgame"==o)return;var d=a.capitalize(o.toLowerCase());null!==d&&void 0!==d&&utils.insertText(utils.getTextArea()[0],r.replace(o,d))}}}})},EmoteModule.prototype.capitalize=function(a){var r=bdEmotes.TwitchGlobal;for(var o in r)if(r.hasOwnProperty(o)&&a==(o+"").toLowerCase())return o};function QuickEmoteMenu(){}QuickEmoteMenu.prototype.init=function(){$(document).on("mousedown",function(u){"rmenu"!=u.target.id&&$("#rmenu").remove()}),this.favoriteEmotes={};var a=window.bdStorage.get("bdfavemotes");""!==a&&null!==a&&(this.favoriteEmotes=JSON.parse(atob(a)));var r="";r+="<div id=\"bda-qem\">",r+=" <button class=\"active\" id=\"bda-qem-twitch\" onclick='quickEmoteMenu.switchHandler(this); return false;'>Twitch</button>",r+=" <button id=\"bda-qem-favourite\" onclick='quickEmoteMenu.switchHandler(this); return false;'>Favourite</button>",r+=" <button id=\"bda-qem-emojis\" onclick='quickEmoteMenu.switchHandler(this); return false;'>Emojis</buttond>",r+="</div>",this.qmeHeader=r;var o="";for(let u in o+="<div id=\"bda-qem-twitch-container\">",o+=" <div class=\"scroller-wrap fade\">",o+=" <div class=\"scroller\">",o+=" <div class=\"emote-menu-inner\">",bdEmotes.TwitchGlobal)if(bdEmotes.TwitchGlobal.hasOwnProperty(u)){var d=bdEmotes.TwitchGlobal[u];o+="<div class=\"emote-container\">",o+=" <img class=\"emote-icon\" alt=\"\" src=\""+d+"\" title=\""+u+"\">",o+=" </img>",o+="</div>"}o+=" </div>",o+=" </div>",o+=" </div>",o+="</div>",this.teContainer=o;var l="";for(let u in l+="<div id=\"bda-qem-favourite-container\">",l+=" <div class=\"scroller-wrap fade\">",l+=" <div class=\"scroller\">",l+=" <div class=\"emote-menu-inner\">",this.favoriteEmotes){var d=this.favoriteEmotes[u];l+="<div class=\"emote-container\">",l+=" <img class=\"emote-icon\" alt=\"\" src=\""+d+"\" title=\""+u+"\" oncontextmenu='quickEmoteMenu.favContext(event, this);'>",l+=" </img>",l+="</div>"}l+=" </div>",l+=" </div>",l+=" </div>",l+="</div>",this.faContainer=l},QuickEmoteMenu.prototype.favContext=function(a,r){a.stopPropagation();var o=$("<div>",{id:"rmenu","data-emoteid":$(r).prop("title"),text:"Remove",class:"context-menu theme-dark"});return o.css({top:a.pageY-$("#bda-qem-favourite-container").offset().top,left:a.pageX-$("#bda-qem-favourite-container").offset().left}),$(r).parent().append(o),o.on("click",function(d){return d.preventDefault(),d.stopPropagation(),$(this).remove(),delete quickEmoteMenu.favoriteEmotes[$(this).data("emoteid")],quickEmoteMenu.updateFavorites(),!1}),!1},QuickEmoteMenu.prototype.switchHandler=function(a){this.switchQem($(a).attr("id"))},QuickEmoteMenu.prototype.switchQem=function(a){var r=$("#bda-qem-twitch"),o=$("#bda-qem-favourite"),d=$("#bda-qem-emojis");r.removeClass("active"),o.removeClass("active"),d.removeClass("active"),$(".emoji-picker, .emojiPicker-3g68GS").hide(),$("#bda-qem-favourite-container").hide(),$("#bda-qem-twitch-container").hide();"bda-qem-twitch"===a?(r.addClass("active"),$("#bda-qem-twitch-container").show()):"bda-qem-favourite"===a?(o.addClass("active"),$("#bda-qem-favourite-container").show()):"bda-qem-emojis"===a?(d.addClass("active"),$(".emoji-picker, .emojiPicker-3g68GS").show(),$(".emoji-picker .search-bar-inner input, .emojiPicker-3g68GS .search-bar-inner input").focus()):void 0;this.lastTab=a;var l=$(".emote-icon");l.off(),l.on("click",function(){var u=$(this).attr("title"),h=utils.getTextArea();utils.insertText(h[0]," "==h.val().slice(-1)?h.val()+u:h.val()+" "+u)})},QuickEmoteMenu.prototype.obsCallback=function(a){var r=$(a);settingsCookie["bda-es-9"]?r.removeClass("bda-qme-hidden"):r.addClass("bda-qme-hidden");settingsCookie["bda-es-0"]&&(r.prepend(this.qmeHeader),r.append(this.teContainer),r.append(this.faContainer),this.lastTab==void 0&&(this.lastTab="bda-qem-favourite"),this.switchQem(this.lastTab))},QuickEmoteMenu.prototype.favorite=function(a,r){this.favoriteEmotes.hasOwnProperty(a)||(this.favoriteEmotes[a]=r),this.updateFavorites()},QuickEmoteMenu.prototype.updateFavorites=function(){var a="";for(var r in a+="<div id=\"bda-qem-favourite-container\">",a+=" <div class=\"scroller-wrap fade\">",a+=" <div class=\"scroller\">",a+=" <div class=\"emote-menu-inner\">",this.favoriteEmotes){var o=this.favoriteEmotes[r];a+="<div class=\"emote-container\">",a+=" <img class=\"emote-icon\" alt=\"\" src=\""+o+"\" title=\""+r+"\" oncontextmenu=\"quickEmoteMenu.favContext(event, this);\">",a+=" </img>",a+="</div>"}a+=" </div>",a+=" </div>",a+=" </div>",a+="</div>",this.faContainer=a,$("#bda-qem-favourite-container").replaceWith(a),window.bdStorage.set("bdfavemotes",btoa(JSON.stringify(this.favoriteEmotes)))};var _hash;function Utils(){}Utils.prototype.getTextArea=function(){return $(".channelTextArea-1HTP3C textarea")},Utils.prototype.insertText=function(a,r){a.focus(),a.selectionStart=0,a.selectionEnd=a.value.length,document.execCommand("insertText",!1,r)},Utils.prototype.jqDefer=function(a){window.jQuery?a():setTimeout(function(){this.jqDefer(a)},100)},Utils.prototype.getHash=function(){$.getJSON("https://api.github.com/repos/Jiiks/BetterDiscordApp/commits/master",function(a){_hash=a.sha,emoteModule.getBlacklist()})},Utils.prototype.loadHtml=function(a,r){var o=$("<div/>",{class:"bd-container"}).appendTo("body");a="//cdn.rawgit.com/Jiiks/BetterDiscordApp/"+_hash+"/html/"+a+".html",o.load(a,r())},Utils.prototype.injectJs=function(a){$("<script/>",{type:"text/javascript",src:a}).appendTo($("body"))},Utils.prototype.injectCss=function(a){$("<link/>",{type:"text/css",rel:"stylesheet",href:a}).appendTo($("head"))},Utils.prototype.escapeID=function(a){return a.replace(/^[^a-z]+|[^\w-]+/gi,"")},Utils.prototype.log=function(a){console.log("%c[BetterDiscord] %c"+a+"","color: #3a71c1; font-weight: 700;","")},Utils.prototype.err=function(a,r){console.log("%c[BetterDiscord] %c"+a+"","color: red; font-weight: 700;",""),r&&(console.groupCollapsed("%cError: "+r.message,"color: red;"),console.error(r.stack),console.groupEnd())},Utils.prototype.escape=function(a){return a.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")},Utils.prototype.insertElement=function(a,r,o){for(var d=a.firstChild;d;){if(d.nodeType!=Node.TEXT_NODE){d=d.nextSibling;continue}var l=0;d.data.replace(r,function(u){var y,h=[].slice.call(arguments),g=h[h.length-2],b=d.splitText(g+l);l-=d.data.length+u.length,b.data=b.data.substr(u.length),y=o,d.parentNode.insertBefore(y,b),d=b}),r.lastIndex=0,d=d.nextSibling}return a},Utils.prototype.getTextNodes=function(a){for(var d,r=[],o=0;o<a.childNodes.length;o++)d=a.childNodes[o],d.nodeType===Node.TEXT_NODE&&r.push(d);return r},Utils.suppressErrors=(a,r)=>(...o)=>{try{return a(...o)}catch(d){console.error("Error occurred in "+r,d)}},Utils.monkeyPatch=(a,r,o)=>{const{before:d,after:l,instead:u,once:h=!1,silent:g=!1}=o,b=o.displayName||a.displayName||a.name||a.constructor.displayName||a.constructor.name;g||console.log("patch",r,"of",b);const y=a[r],E=()=>{g||console.log("unpatch",r,"of",b),a[r]=y};return a[r]=function(){const C={thisObject:this,methodArguments:arguments,cancelPatch:E,originalMethod:y,callOriginalMethod:()=>C.returnValue=C.originalMethod.apply(C.thisObject,C.methodArguments)};if(u){const S=Utils.suppressErrors(u,"`instead` callback of "+a[r].displayName)(C);void 0!==S&&(C.returnValue=S)}else d&&Utils.suppressErrors(d,"`before` callback of "+a[r].displayName)(C),C.callOriginalMethod(),l&&Utils.suppressErrors(l,"`after` callback of "+a[r].displayName)(C);return h&&E(),C.returnValue},a[r].__monkeyPatched=!0,a[r].displayName="patched "+(a[r].displayName||r),E};function VoiceMode(){}VoiceMode.prototype.obsCallback=function(){var a=this;settingsCookie["bda-gs-4"]&&(a.disable(),setTimeout(function(){a.enable()},300))},VoiceMode.prototype.enable=function(){$(".scroller.guild-channels ul").first().css("display","none"),$(".scroller.guild-channels header").first().css("display","none"),$(".app.flex-vertical").first().css("overflow","hidden"),$(".chat.flex-vertical.flex-spacer").first().css("visibility","hidden").css("min-width","0px"),$(".flex-vertical.channels-wrap").first().css("flex-grow","100000"),$(".guild-header .btn.btn-hamburger").first().css("visibility","hidden")},VoiceMode.prototype.disable=function(){$(".scroller.guild-channels ul").first().css("display",""),$(".scroller.guild-channels header").first().css("display",""),$(".app.flex-vertical").first().css("overflow",""),$(".chat.flex-vertical.flex-spacer").first().css("visibility","").css("min-width",""),$(".flex-vertical.channels-wrap").first().css("flex-grow",""),$(".guild-header .btn.btn-hamburger").first().css("visibility","")};var pluginCookie={};function PluginModule(){}PluginModule.prototype.loadPlugins=function(){this.loadPluginData();for(var a=Object.keys(bdplugins),r=0;r<a.length;r++){var o,d;try{o=bdplugins[a[r]].plugin,d=o.getName(),o.load()}catch(l){pluginCookie[d]=!1,utils.err("Plugin "+d+" could not be loaded.",l),bdpluginErrors.push({name:d,file:bdplugins[a[r]].filename,reason:"load() could not be fired.",error:{message:l.message,stack:l.stack}});continue}if(pluginCookie[d]||(pluginCookie[d]=!1),pluginCookie[d])try{o.start(),settingsCookie["fork-ps-2"]&&mainCore.showToast(`${o.getName()} v${o.getVersion()} has started.`)}catch(l){pluginCookie[d]=!1,utils.err("Plugin "+d+" could not be started.",l),bdpluginErrors.push({name:d,file:bdplugins[a[r]].filename,reason:"start() could not be fired.",error:{message:l.message,stack:l.stack}})}}this.savePluginData()},PluginModule.prototype.startPlugin=function(a){try{bdplugins[a].plugin.start(),settingsCookie["fork-ps-2"]&&mainCore.showToast(`${bdplugins[a].plugin.getName()} v${bdplugins[a].plugin.getVersion()} has started.`)}catch(r){pluginCookie[a]=!1,this.savePluginData(),utils.err("Plugin "+name+" could not be started.",r)}},PluginModule.prototype.stopPlugin=function(a){try{bdplugins[a].plugin.stop(),settingsCookie["fork-ps-2"]&&mainCore.showToast(`${bdplugins[a].plugin.getName()} v${bdplugins[a].plugin.getVersion()} has stopped.`)}catch(r){utils.err("Plugin "+name+" could not be stopped.",r)}},PluginModule.prototype.enablePlugin=function(a){pluginCookie[a]=!0,this.savePluginData(),this.startPlugin(a)},PluginModule.prototype.disablePlugin=function(a){pluginCookie[a]=!1,this.savePluginData(),this.stopPlugin(a)},PluginModule.prototype.togglePlugin=function(a){pluginCookie[a]?this.disablePlugin(a):this.enablePlugin(a)},PluginModule.prototype.loadPluginData=function(){var a=$.cookie("bd-plugins");a!=void 0&&(pluginCookie=JSON.parse($.cookie("bd-plugins")))},PluginModule.prototype.savePluginData=function(){$.cookie("bd-plugins",JSON.stringify(pluginCookie),{expires:365,path:"/"})},PluginModule.prototype.newMessage=function(){for(var o,a=Object.keys(bdplugins),r=0;r<a.length;r++)if(o=bdplugins[a[r]].plugin,pluginCookie[o.getName()]&&"function"==typeof o.onMessage)try{o.onMessage()}catch(E){utils.err("Unable to fire onMessage for "+o.getName()+".",E)}},PluginModule.prototype.channelSwitch=function(){for(var o,a=Object.keys(bdplugins),r=0;r<a.length;r++)if(o=bdplugins[a[r]].plugin,pluginCookie[o.getName()]&&"function"==typeof o.onSwitch)try{o.onSwitch()}catch(C){utils.err("Unable to fire onSwitch for "+o.getName()+".",C)}},PluginModule.prototype.rawObserver=function(a){for(var d,r=Object.keys(bdplugins),o=0;o<r.length;o++)if(d=bdplugins[r[o]].plugin,pluginCookie[d.getName()]&&"function"==typeof d.observer)try{d.observer(a)}catch(S){utils.err("Unable to fire observer for "+d.getName()+".",S)}};var themeCookie={};function ThemeModule(){}ThemeModule.prototype.loadThemes=function(){this.loadThemeData();for(var o,a=Object.keys(bdthemes),r=0;r<a.length;r++)o=bdthemes[a[r]].name,themeCookie[o]||(themeCookie[o]=!1),themeCookie[o]&&$("head").append($("<style>",{id:utils.escapeID(o),html:unescape(bdthemes[o].css)}))},ThemeModule.prototype.enableTheme=function(a){themeCookie[a]=!0,this.saveThemeData(),$("head").append(`<style id="${utils.escapeID(bdthemes[a].name)}">${unescape(bdthemes[a].css)}</style>`),settingsCookie["fork-ps-2"]&&mainCore.showToast(`${bdthemes[a].name} v${bdthemes[a].version} has been applied.`)},ThemeModule.prototype.disableTheme=function(a){themeCookie[a]=!1,this.saveThemeData(),$(`#${utils.escapeID(bdthemes[a].name)}`).remove(),settingsCookie["fork-ps-2"]&&mainCore.showToast(`${bdthemes[a].name} v${bdthemes[a].version} has been removed.`)},ThemeModule.prototype.toggleTheme=function(a){themeCookie[a]?this.disableTheme(a):this.enableTheme(a)},ThemeModule.prototype.loadThemeData=function(){var a=$.cookie("bd-themes");a!=void 0&&(themeCookie=JSON.parse($.cookie("bd-themes")))},ThemeModule.prototype.saveThemeData=function(){$.cookie("bd-themes",JSON.stringify(themeCookie),{expires:365,path:"/"})};function BdApi(){}BdApi.injectCSS=function(a,r){$("head").append($("<style>",{id:utils.escapeID(a),html:r}))},BdApi.clearCSS=function(a){$("#"+utils.escapeID(a)).remove()},BdApi.linkJS=function(a,r){$("head").append($("<script>",{id:utils.escapeID(a),src:r,type:"text/javascript"}))},BdApi.unlinkJS=function(a){$("#"+utils.escapeID(a)).remove()},BdApi.getPlugin=function(a){return bdplugins.hasOwnProperty(a)?bdplugins[a].plugin:null},BdApi.getIpc=function(){return betterDiscordIPC},BdApi.getCore=function(){return mainCore},BdApi.alert=function(a,r){mainCore.alert(a,r)},BdApi.showToast=function(a,r={}){mainCore.showToast(a,r)};function devMode(){}devMode.prototype.enable=function(a){var r=this;this.disable(),$(window).on("keydown.bdDevmode",function(o){if(119===o.which){console.log("%c[%cDevMode%c] %cBreak/Resume","color: red;","color: #303030; font-weight:700;","color:red;","");debugger}});a&&$(document).on("contextmenu.bdDevmode",function(o){var l=[];$(o.toElement).parents().addBack().not("html").each(function(){var u="";this.classList&&this.classList.length&&(u+="."+Array.prototype.join.call(this.classList,"."),l.push(u))}),r.lastSelector=l.join(" ").trim(),setImmediate(function(){var u=$(".context-menu");0>=u.length&&(u=$("<div class=\"context-menu bd-context-menu\"></div>"),u.addClass($(".app").hasClass("theme-dark")?"theme-dark":"theme-light"),u.appendTo(".app"),u.css("top",o.clientY),u.css("left",o.clientX),$(document).on("click.bdDevModeCtx",()=>{u.remove(),$(document).off(".bdDevModeCtx")}),$(document).on("contextmenu.bdDevModeCtx",()=>{u.remove(),$(document).off(".bdDevModeCtx")}),$(document).on("keyup.bdDevModeCtx",b=>{27===b.keyCode&&(u.remove(),$(document).off(".bdDevModeCtx"))}));var h=$("<div/>",{class:"item-group"}),g=$("<div/>",{class:"item",click:function(){var b=$("<textarea/>",{text:r.lastSelector}).appendTo("body");b.select(),document.execCommand("copy"),b.remove(),u.hide()}}).append($("<span/>",{text:"Copy Selector"}));h.append(g),u.append(h),u.css("top","-="+h.outerHeight())}),o.stopPropagation()})},devMode.prototype.disable=function(){$(window).off("keydown.bdDevmode"),$(document).off("contextmenu.bdDevmode"),$(document).off("contextmenu.bdDevModeCtx")},window.bdtemp={editorDetached:!1};class V2{constructor(){this.WebpackModules=(()=>{const a=webpackJsonp([],{__extra_id__:(l,u,h)=>u.default=h},["__extra_id__"]).default;delete a.m.__extra_id__,delete a.c.__extra_id__;const r=(l,u={})=>{const{cacheOnly:h=!0}=u;for(let g in a.c)if(a.c.hasOwnProperty(g)){let b=a.c[g].exports;if(b&&b.__esModule&&b.default&&l(b.default))return b.default;if(b&&l(b))return b}if(h)return console.warn("Cannot find loaded module in cache"),null;console.warn("Cannot find loaded module in cache. Loading all modules may have unexpected side effects");for(let g=0;g<a.m.length;++g)try{let b=a(g);if(b&&b.__esModule&&b.default&&l(b.default))return b.default;if(b&&l(b))return b}catch(b){console.error(b)}return console.warn("Cannot find module"),null};return{find:r,findByUniqueProperties:(l,u)=>r(h=>l.every(g=>h[g]!==void 0),u),findByDisplayName:(l,u)=>r(h=>h.displayName===l,u)}})(),this.internal={react:this.WebpackModules.findByUniqueProperties(["Component","PureComponent","Children","createElement","cloneElement"]),"react-dom":this.WebpackModules.findByUniqueProperties(["findDOMNode"])},this.getInternalInstance=a=>a[Object.keys(a).find(r=>r.startsWith("__reactInternalInstance"))],this.Renderer=(()=>{const a=()=>this.getInternalInstance(document.getElementById("app-mount").firstElementChild),r=function*(o=a()){o.stateNode&&(yield o.stateNode),o.sibling&&(yield*r(o.sibling)),o.child&&(yield*r(o.child))};return{recursiveComponents:r}})(),this.ReactComponents=(()=>{const a={},r={},o=new Set,d=new Set,l={},u=(b,y)=>`Several name setters for one component is detected! Old name is ${b}, new name is ${y}. Only new name will be available as displayName, but all getters will resolve`,h=b=>{if("function"==typeof b){const y=b.displayName;if(y)a[y]||(a[y]=b,r[y]&&(r[y].forEach(E=>E(b)),r[y]=null),l[y]&&delete l[y]);else if(!o.has(b)){for(const[E,C]of Object.entries(l))C(b)&&(b.displayName&&console.warn(u(b.displayName,E),b),b.displayName=E,delete l[E],h(b));b.displayName?d.add(b):o.add(b)}}};Utils.monkeyPatch(this.react,"createElement",{displayName:"React",before:({methodArguments:b})=>{h(b[0])}});for(let b of this.Renderer.recursiveComponents())h(b.constructor);return{get:(b,y=null)=>new Promise(E=>{const C=S=>{y&&y(S),E(S)};a[b]?C(a[b]):(!r[b]&&(r[b]=[]),r[b].push(C))})}})()}get reactComponent(){return this.internal.react.Component}get react(){return this.internal.react}get reactDom(){return this.internal["react-dom"]}parseSettings(a){return Object.keys(settings).reduce((r,o)=>{let d=settings[o];return d.cat===a&&d.implemented&&!d.hidden&&(d.text=o,r.push(d)),r},[])}}window.BDV2=new V2;class V2C_SettingsPanel extends BDV2.reactComponent{constructor(a){super(a)}render(){let{settings:a}=this.props;return BDV2.react.createElement("div",{className:"content-column default"},BDV2.react.createElement(V2Components.SettingsTitle,{text:this.props.title}),this.props.button&&BDV2.react.createElement("button",{key:"title-button",className:"bd-pfbtn",onClick:this.props.button.onClick},this.props.button.title),a.map(r=>{return BDV2.react.createElement(V2Components.Switch,{id:r.id,key:r.id,data:r,checked:settingsCookie[r.id],onChange:(o,d)=>{this.props.onChange(o,d)}})}))}}class V2C_Switch extends BDV2.reactComponent{constructor(a){super(a),this.setInitialState(),this.onChange=this.onChange.bind(this)}setInitialState(){this.state={checked:this.props.checked}}render(){let{text:a,info:r}=this.props.data,{checked:o}=this.state;return BDV2.react.createElement("div",{className:"ui-flex flex-vertical flex-justify-start flex-align-stretch flex-nowrap ui-switch-item"},BDV2.react.createElement("div",{className:"ui-flex flex-horizontal flex-justify-start flex-align-stretch flex-nowrap"},BDV2.react.createElement("h3",{className:"ui-form-title h3 margin-reset margin-reset ui-flex-child"},a),BDV2.react.createElement("label",{className:"ui-switch-wrapper ui-flex-child",style:{flex:"0 0 auto"}},BDV2.react.createElement("input",{className:"ui-switch-checkbox",type:"checkbox",checked:o,onChange:d=>this.onChange(d)}),BDV2.react.createElement("div",{className:`ui-switch ${o?"checked":""}`}))),BDV2.react.createElement("div",{className:"ui-form-text style-description margin-top-4",style:{flex:"1 1 auto"}},r))}onChange(){this.props.onChange(this.props.id,!this.state.checked),this.setState({checked:!this.state.checked})}}class V2C_Scroller extends BDV2.reactComponent{constructor(a){super(a)}render(){let a=`scroller-wrap${this.props.fade?" fade":""} ${this.props.dark?" dark":""}`,{children:r}=this.props;return BDV2.react.createElement("div",{key:"scrollerwrap",className:a},BDV2.react.createElement("div",{key:"scroller",ref:"scroller",className:"scroller"},r))}}class V2C_TabBarItem extends BDV2.reactComponent{constructor(a){super(a),this.setInitialState(),this.onClick=this.onClick.bind(this)}setInitialState(){this.state={selected:this.props.selected||!1}}render(){return BDV2.react.createElement("div",{className:`ui-tab-bar-item${this.props.selected?" selected":""}`,onClick:this.onClick},this.props.text)}onClick(){this.props.onClick&&this.props.onClick(this.props.id)}}class V2C_TabBarSeparator extends BDV2.reactComponent{constructor(a){super(a)}render(){return BDV2.react.createElement("div",{className:"ui-tab-bar-separator margin-top-8 margin-bottom-8"})}}class V2C_TabBarHeader extends BDV2.reactComponent{constructor(a){super(a)}render(){return BDV2.react.createElement("div",{className:"ui-tab-bar-header"},this.props.text)}}class V2C_SideBar extends BDV2.reactComponent{constructor(a){super(a);let r=this;const o=$("[class*=side] > [class*=selected]");o.length&&(r.scn=o.attr("class"));const d=$("[class*=side] > [class*=notSelected]");d.length&&(r.nscn=d.attr("class")),$("[class*='side-'] > [class*='item-']").on("click",()=>{r.setState({selected:null})}),r.setInitialState(),r.onClick=r.onClick.bind(r)}setInitialState(){let a=this;a.state={selected:null,items:a.props.items};let r=a.props.items.find(o=>{return o.selected});r&&(a.state.selected=r.id)}render(){let a=this,{headerText:r}=a.props,{items:o,selected:d}=a.state;return BDV2.react.createElement("div",null,BDV2.react.createElement(V2Components.TabBar.Separator,null),BDV2.react.createElement(V2Components.TabBar.Header,{text:r}),o.map(l=>{let{id:u,text:h}=l;return BDV2.react.createElement(V2Components.TabBar.Item,{key:u,selected:d===u,text:h,id:u,onClick:a.onClick})}))}onClick(a){let r=this;const o=$("[class*=side] > [class*=selected]");o.length&&(o.off("click.bdsb").on("click.bsb",d=>{$(d.target).attr("class",r.scn)}),o.attr("class",r.nscn)),r.setState({selected:null}),r.setState({selected:a}),r.props.onClick&&r.props.onClick(a)}}class V2C_XSvg extends BDV2.reactComponent{constructor(a){super(a)}render(){return BDV2.react.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 12 12",style:{width:"18px",height:"18px"}},BDV2.react.createElement("g",{className:"background",fill:"none",fillRule:"evenodd"},BDV2.react.createElement("path",{d:"M0 0h12v12H0"}),BDV2.react.createElement("path",{className:"fill",fill:"#dcddde",d:"M9.5 3.205L8.795 2.5 6 5.295 3.205 2.5l-.705.705L5.295 6 2.5 8.795l.705.705L6 6.705 8.795 9.5l.705-.705L6.705 6"})))}}class V2C_Tools extends BDV2.reactComponent{constructor(a){super(a),this.onClick=this.onClick.bind(this)}render(){return BDV2.react.createElement("div",{className:"tools"},BDV2.react.createElement("div",{className:"btn-close",onClick:this.onClick},BDV2.react.createElement(V2Components.XSvg,null)),BDV2.react.createElement("div",{className:"esc-text"},"ESC"))}onClick(){this.props.onClick&&this.props.onClick(),$(".btn-close").first().click()}}class V2C_SettingsTitle extends BDV2.reactComponent{constructor(a){super(a)}render(){return BDV2.react.createElement("h2",{className:"ui-form-title h2 margin-reset margin-bottom-20"},this.props.text)}}class V2C_Checkbox extends BDV2.reactComponent{constructor(a){super(a),this.onClick=this.onClick.bind(this),this.setInitialState()}setInitialState(){this.state={checked:this.props.checked||!1}}render(){return BDV2.react.createElement("li",null,BDV2.react.createElement("div",{className:"checkbox",onClick:this.onClick},BDV2.react.createElement("div",{className:"checkbox-inner"},BDV2.react.createElement("input",{checked:this.state.checked,onChange:()=>{},type:"checkbox"}),BDV2.react.createElement("span",null)),BDV2.react.createElement("span",null,this.props.text)))}onClick(){this.props.onChange(this.props.id,!this.state.checked),this.setState({checked:!this.state.checked})}}class V2C_CssEditorDetached extends BDV2.reactComponent{constructor(a){super(a);let r=this;r.onClick=r.onClick.bind(r),r.updateCss=r.updateCss.bind(r),r.saveCss=r.saveCss.bind(r),r.onChange=r.onChange.bind(r)}componentDidMount(){$("#app-mount").addClass("bd-detached-editor"),window.bdtemp.editorDetached=!0,this.editor=ace.edit("bd-customcss-editor-detached"),this.editor.setTheme("ace/theme/monokai"),this.editor.session.setMode("ace/mode/css"),this.editor.setShowPrintMargin(!1),this.editor.setFontSize(14),this.editor.on("change",()=>{settingsCookie["bda-css-0"]&&(this.saveCss(),this.updateCss())})}componentWillUnmount(){$("#app-mount").removeClass("bd-detached-editor"),window.bdtemp.editorDetached=!1,this.editor.destroy()}updateLineCount(){let a=this.refs.editor.value.split("\n").length;a==this.props.lines||(this.refs.lines.textContent=Array.from(Array(a),(r,o)=>o+1).join(".\n")+".",this.props.lines=a)}get options(){return{lineNumbers:!0,mode:"css",indentUnit:4,theme:"material",scrollbarStyle:"simple"}}get css(){let a=window.bdStorage.get("bdcustomcss"),r="";return a&&""!==a&&(r=atob(a)),r}get root(){let a=$("#bd-customcss-detach-container");return a.length?a[0]:this.injectRoot()?this.detachedRoot:null}injectRoot(){return!!$(".app").length&&($("<div/>",{id:"bd-customcss-detach-container"}).insertAfter($(".app")),!0)}render(){let a=this;return BDV2.react.createElement("div",{className:"bd-detached-css-editor",id:"bd-customcss-detach-editor"},BDV2.react.createElement("div",{id:"bd-customcss-innerpane"},BDV2.react.createElement("div",{className:"editor-wrapper"},BDV2.react.createElement("div",{id:"bd-customcss-editor-detached",className:"editor",ref:"editor"},a.css)),BDV2.react.createElement("div",{id:"bd-customcss-attach-controls"},BDV2.react.createElement("ul",{className:"checkbox-group"},BDV2.react.createElement(V2Components.Checkbox,{id:"live-update",text:"Live Update",onChange:a.onChange,checked:settingsCookie["bda-css-0"]})),BDV2.react.createElement("div",{id:"bd-customcss-detach-controls-button"},BDV2.react.createElement("button",{style:{borderRadius:"3px 0 0 3px",borderRight:"1px solid #3f4146"},className:"btn btn-primary",onClick:()=>{a.onClick("update")}},"Update"),BDV2.react.createElement("button",{style:{borderRadius:"0",borderLeft:"1px solid #2d2d2d",borderRight:"1px solid #2d2d2d"},className:"btn btn-primary",onClick:()=>{a.onClick("save")}},"Save"),BDV2.react.createElement("button",{style:{borderRadius:"0 3px 3px 0",borderLeft:"1px solid #3f4146"},className:"btn btn-primary",onClick:()=>{a.onClick("attach")}},"Attach"),BDV2.react.createElement("span",{style:{fontSize:"10px",marginLeft:"5px"}},"Unsaved changes are lost on attach")))))}onChange(a,r){"live-update"===a?(settingsCookie["bda-css-0"]=r,mainCore.saveSettings()):void 0}onClick(a){let r=this;"attach"===a?($("#editor-detached").length&&r.props.attach(),BDV2.reactDom.unmountComponentAtNode(r.root),r.root.remove()):"update"===a?r.updateCss():"save"===a?r.saveCss():void 0}updateCss(){0==$("#customcss").length&&$("head").append("<style id=\"customcss\"></style>"),$("#customcss").html(this.editor.session.getValue()).detach().appendTo(document.head)}saveCss(){window.bdStorage.set("bdcustomcss",btoa(this.editor.session.getValue()))}}class V2C_CssEditor extends BDV2.reactComponent{constructor(a){super(a);let r=this;r.props.lines=0,r.setInitialState(),r.attach=r.attach.bind(r),r.detachedEditor=BDV2.react.createElement(V2C_CssEditorDetached,{attach:r.attach}),r.onClick=r.onClick.bind(r),r.updateCss=r.updateCss.bind(r),r.saveCss=r.saveCss.bind(r),r.detach=r.detach.bind(r)}setInitialState(){this.state={detached:this.props.detached||window.bdtemp.editorDetached}}componentDidMount(){this.editor=ace.edit("bd-customcss-editor"),this.editor.setTheme("ace/theme/monokai"),this.editor.session.setMode("ace/mode/css"),this.editor.setShowPrintMargin(!1),this.editor.setFontSize(14),this.editor.on("change",()=>{settingsCookie["bda-css-0"]&&(this.saveCss(),this.updateCss())})}componentWillUnmount(){this.editor.destroy()}componentDidUpdate(a,r){let o=this;r.detached&&!o.state.detached&&BDV2.reactDom.unmountComponentAtNode(o.detachedRoot)}codeMirror(){}get options(){return{lineNumbers:!0,mode:"css",indentUnit:4,theme:"material",scrollbarStyle:"simple"}}get css(){let a=window.bdStorage.get("bdcustomcss"),r="";return a&&""!==a&&(r=atob(a)),r}updateLineCount(){let a=this.refs.editor.value.split("\n").length;a==this.props.lines||(this.refs.lines.textContent=Array.from(Array(a),(r,o)=>o+1).join(".\n")+".",this.props.lines=a)}render(){let a=this,{detached:r}=a.state;return BDV2.react.createElement("div",{className:"content-column default",style:{padding:"60px 40px 0px"}},r&&BDV2.react.createElement("div",{id:"editor-detached"},BDV2.react.createElement(V2Components.SettingsTitle,{text:"Custom CSS Editor"}),BDV2.react.createElement("h3",null,"Editor Detached"),BDV2.react.createElement("button",{className:"btn btn-primary",onClick:()=>{a.attach()}},"Attach")),!r&&BDV2.react.createElement("div",null,BDV2.react.createElement(V2Components.SettingsTitle,{text:"Custom CSS Editor"}),BDV2.react.createElement("div",{className:"editor-wrapper"},BDV2.react.createElement("div",{id:"bd-customcss-editor",className:"editor",ref:"editor"},a.css)),BDV2.react.createElement("div",{id:"bd-customcss-attach-controls"},BDV2.react.createElement("ul",{className:"checkbox-group"},BDV2.react.createElement(V2Components.Checkbox,{id:"live-update",text:"Live Update",onChange:this.onChange,checked:settingsCookie["bda-css-0"]})),BDV2.react.createElement("div",{id:"bd-customcss-detach-controls-button"},BDV2.react.createElement("button",{style:{borderRadius:"3px 0 0 3px",borderRight:"1px solid #3f4146"},className:"btn btn-primary",onClick:()=>{a.onClick("update")}},"Update"),BDV2.react.createElement("button",{style:{borderRadius:"0",borderLeft:"1px solid #2d2d2d",borderRight:"1px solid #2d2d2d"},className:"btn btn-primary",onClick:()=>{a.onClick("save")}},"Save"),BDV2.react.createElement("button",{style:{borderRadius:"0 3px 3px 0",borderLeft:"1px solid #3f4146"},className:"btn btn-primary",onClick:()=>{a.onClick("detach")}},"Detach"),BDV2.react.createElement("span",{style:{fontSize:"10px",marginLeft:"5px"}},"Unsaved changes are lost on detach")))))}onClick(a){let r=this;"update"===a?r.updateCss():"save"===a?r.saveCss():"detach"===a?r.detach():void 0}onChange(a,r){"live-update"===a?(settingsCookie["bda-css-0"]=r,mainCore.saveSettings()):void 0}updateCss(){0==$("#customcss").length&&$("head").append("<style id=\"customcss\"></style>"),$("#customcss").html(this.editor.session.getValue()).detach().appendTo(document.head)}saveCss(){window.bdStorage.set("bdcustomcss",btoa(this.editor.session.getValue()))}detach(){let a=this;a.setState({detached:!0});let r=a.detachedRoot;return r?void BDV2.reactDom.render(a.detachedEditor,r):void console.log("FAILED TO INJECT ROOT: .app")}get detachedRoot(){let a=$("#bd-customcss-detach-container");return a.length?a[0]:this.injectDetachedRoot()?this.detachedRoot:null}injectDetachedRoot(){return!!$(".app").length&&($("<div/>",{id:"bd-customcss-detach-container"}).insertAfter($(".app")),!0)}attach(){let a=this;a.setState({detached:!1})}}class V2C_List extends BDV2.reactComponent{constructor(a){super(a)}render(){return BDV2.react.createElement("ul",{className:this.props.className},this.props.children)}}class V2C_ContentColumn extends BDV2.reactComponent{constructor(a){super(a)}render(){return BDV2.react.createElement("div",{className:"content-column default"},BDV2.react.createElement("h2",{className:"ui-form-title h2 margin-reset margin-bottom-20"},this.props.title),this.props.children)}}class V2C_PluginCard extends BDV2.reactComponent{constructor(a){super(a);let r=this;r.onChange=r.onChange.bind(r),r.showSettings=r.showSettings.bind(r),r.setInitialState(),r.hasSettings="function"==typeof r.props.plugin.getSettingsPanel,r.settingsPanel=""}setInitialState(){this.state={checked:pluginCookie[this.props.plugin.getName()],settings:!1}}componentDidUpdate(){if(this.state.settings){if("object"==typeof this.settingsPanel&&this.refs.settingspanel.appendChild(this.settingsPanel),!settingsCookie["fork-ps-3"])return;var a=(d,l)=>{let u=d.scrollTop,h=u+d.clientHeight,g=l.offsetTop,b=g+l.clientHeight;return g<u||b>h};let r=$(BDV2.reactDom.findDOMNode(this)),o=r.parents(".scroller");if(!a(o[0],r[0]))return;o.animate({scrollTop:r.offset().top-o.offset().top+o.scrollTop()-30},300)}}render(){let a=this,{plugin:r}=this.props,o=r.getName(),d=r.getAuthor(),l=r.getDescription(),u=r.getVersion(),h=bdplugins[o].website,g=bdplugins[o].source;if(this.state.settings){try{a.settingsPanel=r.getSettingsPanel()}catch(b){utils.err("Unable to get settings panel for "+r.getName()+".",b)}return BDV2.react.createElement("li",{className:"settings-open ui-switch-item"},BDV2.react.createElement("div",{style:{float:"right",cursor:"pointer"},onClick:()=>{this.refs.settingspanel.innerHTML="",a.setState({settings:!1})}},BDV2.react.createElement(V2Components.XSvg,null)),"object"==typeof a.settingsPanel&&BDV2.react.createElement("div",{id:`plugin-settings-${o}`,className:"plugin-settings",ref:"settingspanel"}),"object"!=typeof a.settingsPanel&&BDV2.react.createElement("div",{id:`plugin-settings-${o}`,className:"plugin-settings",ref:"settingspanel",dangerouslySetInnerHTML:{__html:a.settingsPanel}}))}return BDV2.react.createElement("li",{"data-name":o,"data-version":u,className:"settings-closed ui-switch-item"},BDV2.react.createElement("div",{className:"bda-header"},BDV2.react.createElement("span",{className:"bda-header-title"},BDV2.react.createElement("span",{className:"bda-name"},o)," v",BDV2.react.createElement("span",{className:"bda-version"},u)," by ",BDV2.react.createElement("span",{className:"bda-author"},d)),BDV2.react.createElement("label",{className:"ui-switch-wrapper ui-flex-child",style:{flex:"0 0 auto"}},BDV2.react.createElement("input",{checked:this.state.checked,onChange:this.onChange,className:"ui-switch-checkbox",type:"checkbox"}),BDV2.react.createElement("div",{className:this.state.checked?"ui-switch checked":"ui-switch"}))),BDV2.react.createElement("div",{className:"bda-description-wrap scroller-wrap fade"},BDV2.react.createElement("div",{className:"bda-description scroller"},l)),(h||g||this.hasSettings)&&BDV2.react.createElement("div",{className:"bda-footer"},BDV2.react.createElement("span",{className:"bda-links"},h&&BDV2.react.createElement("a",{className:"bda-link",href:h,target:"_blank"},"Website"),h&&g&&" | ",g&&BDV2.react.createElement("a",{className:"bda-link",href:g,target:"_blank"},"Source")),this.hasSettings&&BDV2.react.createElement("button",{onClick:this.showSettings,className:"bda-settings-button",disabled:!this.state.checked},"Settings")))}onChange(){this.setState({checked:!this.state.checked}),pluginModule.togglePlugin(this.props.plugin.getName())}showSettings(){this.hasSettings&&this.setState({settings:!0})}}class V2C_ThemeCard extends BDV2.reactComponent{constructor(a){super(a),this.setInitialState(),this.onChange=this.onChange.bind(this)}setInitialState(){this.state={checked:themeCookie[this.props.theme.name]}}render(){let{theme:a}=this.props,r=a.name,o=a.description,d=a.version,l=a.author,u=bdthemes[r].website,h=bdthemes[r].source;return BDV2.react.createElement("li",{"data-name":r,"data-version":d,className:"settings-closed ui-switch-item"},BDV2.react.createElement("div",{className:"bda-header"},BDV2.react.createElement("span",{className:"bda-header-title"},BDV2.react.createElement("span",{className:"bda-name"},r)," v",BDV2.react.createElement("span",{className:"bda-version"},d)," by ",BDV2.react.createElement("span",{className:"bda-author"},l)),BDV2.react.createElement("label",{className:"ui-switch-wrapper ui-flex-child",style:{flex:"0 0 auto"}},BDV2.react.createElement("input",{checked:this.state.checked,onChange:this.onChange,className:"ui-switch-checkbox",type:"checkbox"}),BDV2.react.createElement("div",{className:this.state.checked?"ui-switch checked":"ui-switch"}))),BDV2.react.createElement("div",{className:"bda-description-wrap scroller-wrap fade"},BDV2.react.createElement("div",{className:"bda-description scroller"},o)),(u||h)&&BDV2.react.createElement("div",{className:"bda-footer"},BDV2.react.createElement("span",{className:"bda-links"},u&&BDV2.react.createElement("a",{className:"bda-link",href:u,target:"_blank"},"Website"),u&&h&&" | ",h&&BDV2.react.createElement("a",{className:"bda-link",href:h,target:"_blank"},"Source"))))}onChange(){this.setState({checked:!this.state.checked}),themeModule.toggleTheme(this.props.theme.name)}}class V2Cs_TabBar{static get Item(){return V2C_TabBarItem}static get Header(){return V2C_TabBarHeader}static get Separator(){return V2C_TabBarSeparator}}class V2Components{static get SettingsPanel(){return V2C_SettingsPanel}static get Switch(){return V2C_Switch}static get Scroller(){return V2C_Scroller}static get TabBar(){return V2Cs_TabBar}static get SideBar(){return V2C_SideBar}static get Tools(){return V2C_Tools}static get SettingsTitle(){return V2C_SettingsTitle}static get CssEditor(){return V2C_CssEditor}static get Checkbox(){return V2C_Checkbox}static get List(){return V2C_List}static get PluginCard(){return V2C_PluginCard}static get ThemeCard(){return V2C_ThemeCard}static get ContentColumn(){return V2C_ContentColumn}static get XSvg(){return V2C_XSvg}static get Layer(){return V2C_Layer}static get SidebarView(){return V2C_SidebarView}static get ServerCard(){return V2C_ServerCard}}class V2_SettingsPanel_Sidebar{constructor(a){this.onClick=a}get items(){return[{text:"Core",id:"core"},{text:"Zere's Fork",id:"fork"},{text:"Emotes",id:"emotes"},{text:"Custom CSS",id:"customcss"},{text:"Plugins",id:"plugins"},{text:"Themes",id:"themes"}]}get component(){return BDV2.react.createElement("span",null,BDV2.react.createElement(V2Components.SideBar,{onClick:this.onClick,headerText:"Bandaged BD",items:this.items}),BDV2.react.createElement("div",{style:{fontSize:"12px",fontWeight:"600",color:"#72767d",padding:"2px 10px"}},`BD v${bdVersion}, JS v${jsVersion} by `,BDV2.react.createElement("a",{href:"https://github.com/Jiiks/",target:"_blank"},"Jiiks")),BDV2.react.createElement("div",{style:{fontSize:"12px",fontWeight:"600",color:"#72767d",padding:"2px 10px"}},`BBD v${bbdVersion} by `,BDV2.react.createElement("a",{href:"https://github.com/rauenzi/",target:"_blank"},"Zerebos")))}get root(){let a=$("#bd-settings-sidebar");return a.length?a[0]:this.injectRoot()?this.root:null}injectRoot(){let a=$("[class*='side-'] > [class*='item-']:not([class*=Danger])").last();return!!a.length&&($("<span/>",{id:"bd-settings-sidebar"}).insertBefore(a.prev()),!0)}render(){let a=this.root;return a?void BDV2.reactDom.render(this.component,a):void console.log("FAILED TO LOCATE ROOT: [class*='side-'] > [class*='item-']:not([class*=Danger])")}}class V2_SettingsPanel{constructor(){let a=this;a.sideBarOnClick=a.sideBarOnClick.bind(a),a.onChange=a.onChange.bind(a),a.updateSettings=this.updateSettings.bind(a),a.sidebar=new V2_SettingsPanel_Sidebar(a.sideBarOnClick)}get root(){let a=$("#bd-settingspane-container");return a.length?a[0]:this.injectRoot()?this.root:null}injectRoot(){return!!$(".layer .ui-standard-sidebar-view, .layer-kosS71 .ui-standard-sidebar-view").length&&($(".layer .ui-standard-sidebar-view, .layer-kosS71 .ui-standard-sidebar-view").append($("<div/>",{class:"content-region",id:"bd-settingspane-container"})),!0)}get coreSettings(){return this.getSettings("core")}get forkSettings(){return this.getSettings("fork")}get emoteSettings(){return this.getSettings("emote")}getSettings(a){return Object.keys(settings).reduce((r,o)=>{let d=settings[o];return d.cat===a&&d.implemented&&!d.hidden&&(d.text=o,r.push(d)),r},[])}sideBarOnClick(a){let r=this;$(".content-region").first().hide(),$(r.root).show();"core"===a?r.renderCoreSettings():"fork"===a?r.renderForkSettings():"emotes"===a?r.renderEmoteSettings():"customcss"===a?r.renderCustomCssEditor():"plugins"===a?r.renderPluginPane():"themes"===a?r.renderThemePane():void 0}onClick(){}onChange(a,r){settingsCookie[a]=r,this.updateSettings()}updateSettings(){let a=settingsCookie;if(a["bda-es-0"]?$("#twitchcord-button-container").show():$("#twitchcord-button-container").hide(),a["bda-gs-b"]?$("body").addClass("bd-blue"):$("body").removeClass("bd-blue"),a["bda-gs-2"]?$("body").addClass("bd-minimal"):$("body").removeClass("bd-minimal"),a["bda-gs-3"]?$("body").addClass("bd-minimal-chan"):$("body").removeClass("bd-minimal-chan"),a["bda-gs-1"]?$("#bd-pub-li").show():$("#bd-pub-li").hide(),a["bda-gs-4"]?voiceMode.enable():voiceMode.disable(),a["bda-gs-5"]?$("#app-mount").addClass("bda-dark"):$("#app-mount").removeClass("bda-dark"),document.querySelector(".messages")){let o=document.querySelector(".messages");a["bda-gs-6"]?mainCore.inject24Hour(o):mainCore.remove24Hour(o),a["bda-gs-7"]&&document.querySelector(".messages")?mainCore.injectColoredText(o):mainCore.removeColoredText(o)}a["fork-es-2"]?$(".emote").each(()=>{$(this).addClass("stop-animation")}):$(".emote").each(()=>{$(this).removeClass("stop-animation")}),$(document).off("mouseover",".emote");var r=$("<div class='tipsy tipsy-se' style='display: block; top: 82px; left: 1630.5px; visibility: visible; opacity: 0.8;'><div class='tipsy-inner'></div></div>");$(document).on("mouseover",".emote",function(){var o=$(this);if(a["fork-es-2"]&&a["bda-es-8"]&&o.removeClass("stop-animation"),!!a["bda-es-6"]){var d=o.offset(),l=o.attr("alt"),u=o.attr("data-modifier");u&&a["fork-es-1"]&&(l=l+":"+u),r.find(".tipsy-inner").text(l),$(".app").append($(r));var h=d.left+o.outerWidth()/2;r.css("left",h-r.outerWidth()/2),r.css("top",d.top-r.outerHeight())}}),$(document).on("mouseleave",".emote",function(){a["bda-es-6"]&&$(".tipsy").remove(),a["fork-es-2"]&&a["bda-es-8"]&&$(this).addClass("stop-animation")}),a["bda-gs-8"]?dMode.enable(a["fork-dm-1"]):dMode.disable(),mainCore.saveSettings()}renderSidebar(){let a=this;$("[class*='side-'] > [class*='item-']").off("click.v2settingspanel").on("click.v2settingspanel",()=>{BDV2.reactDom.unmountComponentAtNode(a.root),$(a.root).hide(),$(".content-region").first().show()}),a.sidebar.render()}get coreComponent(){return BDV2.react.createElement(V2Components.Scroller,{fade:!0,dark:!0,children:[BDV2.react.createElement(V2Components.SettingsPanel,{key:"cspanel",title:"Core Settings",onChange:this.onChange,settings:this.coreSettings}),BDV2.react.createElement(V2Components.Tools,{key:"tools"})]})}get forkComponent(){return BDV2.react.createElement(V2Components.Scroller,{fade:!0,dark:!0,children:[BDV2.react.createElement(V2Components.SettingsPanel,{key:"fspanel",title:"Zere's Fork Settings",onChange:this.onChange,settings:this.forkSettings,button:{title:"Clear Emote Cache",onClick:()=>{emoteModule.clearEmoteData(),emoteModule.init(),quickEmoteMenu.init()}}}),BDV2.react.createElement(V2Components.Tools,{key:"tools"})]})}get emoteComponent(){return BDV2.react.createElement(V2Components.Scroller,{fade:!0,dark:!0,children:[BDV2.react.createElement(V2Components.SettingsPanel,{key:"espanel",title:"Emote Settings",onChange:this.onChange,settings:this.emoteSettings}),BDV2.react.createElement(V2Components.Tools,{key:"tools"})]})}get customCssComponent(){return BDV2.react.createElement(V2Components.Scroller,{fade:!0,dark:!0,children:[BDV2.react.createElement(V2Components.CssEditor,{key:"csseditor"}),BDV2.react.createElement(V2Components.Tools,{key:"tools"})]})}get pluginsComponent(){let a=Object.keys(bdplugins).reduce((l,u)=>{return l.push(BDV2.react.createElement(V2Components.PluginCard,{key:u,plugin:bdplugins[u].plugin})),l},[]),r=BDV2.react.createElement(V2Components.List,{key:"plugin-list",className:"bda-slist",children:a}),o=BDV2.react.createElement("button",{key:"folder-button",className:"bd-pfbtn",onClick:()=>{betterDiscordIPC.send("asynchronous-message",{arg:"opendir",path:"plugindir"})}},"Open Plugin Folder"),d=BDV2.react.createElement(V2Components.ContentColumn,{key:"pcolumn",title:"Plugins",children:[o,r]});return BDV2.react.createElement(V2Components.Scroller,{fade:!0,dark:!0,children:[d,BDV2.react.createElement(V2Components.Tools,{key:"tools"})]})}get themesComponent(){let a=Object.keys(bdthemes).reduce((l,u)=>{return l.push(BDV2.react.createElement(V2Components.ThemeCard,{key:u,theme:bdthemes[u]})),l},[]),r=BDV2.react.createElement(V2Components.List,{key:"theme-list",className:"bda-slist",children:a}),o=BDV2.react.createElement("button",{key:"folder-button",className:"bd-pfbtn",onClick:()=>{betterDiscordIPC.send("asynchronous-message",{arg:"opendir",path:"themedir"})}},"Open Theme Folder"),d=BDV2.react.createElement(V2Components.ContentColumn,{key:"tcolumn",title:"Themes",children:[o,r]});return BDV2.react.createElement(V2Components.Scroller,{fade:!0,dark:!0,children:[d,BDV2.react.createElement(V2Components.Tools,{key:"tools"})]})}renderCoreSettings(){let a=this.root;return a?void BDV2.reactDom.render(this.coreComponent,a):void console.log("FAILED TO LOCATE ROOT: .layer .ui-standard-sidebar-view")}renderForkSettings(){let a=this.root;return a?void BDV2.reactDom.render(this.forkComponent,a):void console.log("FAILED TO LOCATE ROOT: .layer .ui-standard-sidebar-view")}renderEmoteSettings(){let a=this.root;return a?void BDV2.reactDom.render(this.emoteComponent,a):void console.log("FAILED TO LOCATE ROOT: .layer .ui-standard-sidebar-view")}renderCustomCssEditor(){let a=this.root;return a?void BDV2.reactDom.render(this.customCssComponent,a):void console.log("FAILED TO LOCATE ROOT: .layer .ui-standard-sidebar-view")}renderPluginPane(){let a=this.root;return a?void BDV2.reactDom.render(this.pluginsComponent,a):void console.log("FAILED TO LOCATE ROOT: .layer .ui-standard-sidebar-view")}renderThemePane(){let a=this.root;return a?void BDV2.reactDom.render(this.themesComponent,a):void console.log("FAILED TO LOCATE ROOT: .layer .ui-standard-sidebar-view")}}class V2C_Layer extends BDV2.reactComponent{constructor(a){super(a)}componentDidMount(){$(window).on(`keyup.${this.props.id}`,a=>{27===a.which&&BDV2.reactDom.unmountComponentAtNode(this.refs.root.parentNode)})}componentWillUnmount(){$(window).off(`keyup.${this.props.id}`),$(`#${this.props.rootId}`).remove()}render(){return BDV2.react.createElement("div",{className:"layer bd-layer layer-kosS71",id:this.props.id,ref:"root"},this.props.children)}}class V2C_SidebarView extends BDV2.reactComponent{constructor(a){super(a)}render(){let{sidebar:a,content:r,tools:o}=this.props.children;return BDV2.react.createElement("div",{className:"ui-standard-sidebar-view"},BDV2.react.createElement("div",{className:"sidebar-region"},BDV2.react.createElement(V2Components.Scroller,{key:"sidebarScroller",ref:"sidebarScroller",fade:a.fade||!0,dark:a.dark||!0,children:a.component})),BDV2.react.createElement("div",{className:"content-region"},BDV2.react.createElement("div",{className:"content-transition-wrap"},BDV2.react.createElement("div",{className:"scrollerWrap-2uBjct content-region-scroller-wrap scrollerThemed-19vinI themeGhost-10fio9 scrollerTrack-3hhmU0"},BDV2.react.createElement("div",{className:"scroller-fzNley content-region-scroller",ref:"contentScroller"},BDV2.react.createElement("div",{className:"content-column default"},r.component),o.component)))))}}class V2_PublicServers{constructor(){}get component(){return BDV2.react.createElement(V2Components.Layer,{rootId:"pubslayerroot",id:"pubslayer",children:BDV2.react.createElement(V2C_PublicServers,{rootId:"pubslayerroot"})})}get root(){let a=document.getElementById("pubslayerroot");return a?a:this.injectRoot()?this.root:null}injectRoot(){return!!$(".layers, .layers-20RVFW").length&&($(".layers, .layers-20RVFW").append($("<div/>",{id:"pubslayerroot"})),!0)}render(){let a=this.root;return a?void BDV2.reactDom.render(this.component,a):void console.log("FAILED TO LOCATE ROOT: .layers")}get button(){let a=$("<div/>",{class:"guild",id:"bd-pub-li",css:{height:"20px",display:settingsCookie["bda-gs-1"]?"":"none"}}).append($("<div/>",{class:"guild-inner",css:{height:"20px","border-radius":"4px"}}).append($("<a/>",{}).append($("<div/>",{text:"public",id:"bd-pub-button",css:{"line-height":"20px","font-size":"12px"},click:()=>{this.render()}}))));return a}initialize(){let a=$(".guilds>:first-child");a.after(this.button)}}class V2C_ServerCard extends BDV2.reactComponent{constructor(a){super(a),this.state={imageError:!1,joined:this.props.guildList.includes(this.props.server.identifier)}}render(){let{server:a}=this.props;return BDV2.react.createElement("div",{className:`ui-card ui-card-primary bd-server-card${a.pinned?" bd-server-card-pinned":""}`,style:{marginTop:"5px"}},BDV2.react.createElement("div",{className:"ui-flex horizontal",style:{display:"flex",flexFlow:"row nowrap",justifyContent:"flex-start",alignItems:"stretch",flex:"1 1 auto"}},BDV2.react.createElement("div",{className:"ui-flex-child",style:{flex:"0 1 auto",padding:"5px"}},BDV2.react.createElement("img",{ref:"img",className:"bd-pubs-server-icon",src:a.icon,style:{width:"100px",height:"100px"},onError:this.handleError.bind(this)})),BDV2.react.createElement("div",{className:"ui-flex-child",style:{flex:"1 1 auto",padding:"5px"}},BDV2.react.createElement("div",{className:"ui-flex horizontal"},BDV2.react.createElement("div",{className:"ui-form-item",style:{flex:"1 1 auto"}},BDV2.react.createElement("h5",{className:"ui-form-title h5 margin-reset"},a.name)),BDV2.react.createElement("div",{className:"ui-form-item"},BDV2.react.createElement("h5",{className:"ui-form-title h5 margin-reset"},a.online,"/",a.members," Members"))),BDV2.react.createElement("div",{className:"ui-flex horizontal"},BDV2.react.createElement("div",{className:"scroller-wrap fade dark",style:{minHeight:"60px",maxHeight:"60px",borderTop:"1px solid #3f4146",borderBottom:"1px solid #3f4146",paddingTop:"5px"}},BDV2.react.createElement("div",{className:"scroller"},BDV2.react.createElement("div",{style:{fontSize:"13px",color:"#b9bbbe"}},a.description)))),BDV2.react.createElement("div",{className:"ui-flex horizontal"},BDV2.react.createElement("div",{className:"ui-flex-child bd-server-tags",style:{flex:"1 1 auto"}},a.categories.join(", ")),this.state.joined&&BDV2.react.createElement("button",{type:"button",className:"ui-button filled brand small grow disabled",style:{minHeight:"12px",marginTop:"4px",backgroundColor:"#3ac15c"}},BDV2.react.createElement("div",{className:"ui-button-contents"},"Joined")),a.error&&BDV2.react.createElement("button",{type:"button",className:"ui-button filled brand small grow disabled",style:{minHeight:"12px",marginTop:"4px",backgroundColor:"#c13a3a"}},BDV2.react.createElement("div",{className:"ui-button-contents"},"Error")),!a.error&&!this.state.joined&&a.invite_code&&BDV2.react.createElement("button",{type:"button",className:"ui-button filled brand small grow",style:{minHeight:"12px",marginTop:"4px"},onClick:()=>{this.join()}},BDV2.react.createElement("div",{className:"ui-button-contents"},"Join"))))))}handleError(){this.props.server.icon=this.props.fallback,this.setState({imageError:!0})}join(){this.props.join(this.props.server),this.setState({joined:!0})}}class V2C_PublicServers extends BDV2.reactComponent{constructor(a){super(a),this.setInitialState(),this.close=this.close.bind(this),this.changeCategory=this.changeCategory.bind(this),this.search=this.search.bind(this),this.searchKeyDown=this.searchKeyDown.bind(this),this.checkConnection=this.checkConnection.bind(this),this.join=this.join.bind(this),this.GuildStore=BDV2.WebpackModules.findByUniqueProperties(["getGuilds"]),this.AvatarDefaults=BDV2.WebpackModules.findByUniqueProperties(["getUserAvatarURL","DEFAULT_AVATARS"]),this.InviteActions=BDV2.WebpackModules.findByUniqueProperties(["acceptInvite"])}componentDidMount(){this.checkConnection()}setInitialState(){this.state={selectedCategory:-1,title:"Loading...",loading:!0,servers:[],next:null,connection:{state:0,user:null}}}close(){BDV2.reactDom.unmountComponentAtNode(document.getElementById(this.props.rootId))}search(a,r){let o=this;$.ajax({method:"GET",url:`${o.endPoint}${a}`,success:d=>{let l=d.results.reduce((g,b)=>{return b.joined=!1,g.push(b),g},[]);r||(l=o.state.servers.concat(l));let u=d.size+d.from;u>=d.total&&(u=d.total,d.next=null);let h=`Showing 1-${u} of ${d.total} results in ${o.categoryButtons[o.state.selectedCategory]}`;o.state.term&&(h+=` for ${o.state.term}`),o.setState({loading:!1,title:h,servers:l,next:d.next}),r&&(o.refs.sbv.refs.contentScroller.scrollTop=0)},error:d=>{o.setState({loading:!1,title:"Failed to load servers. Check console for details"}),console.log(d)}})}join(a){this.InviteActions.acceptInvite(a.invite_code)}get bdServer(){let r=Object.keys(this.GuildStore.getGuilds()),o=this.AvatarDefaults.DEFAULT_AVATARS;return BDV2.react.createElement(V2Components.ServerCard,{server:{name:"BetterDiscord",online:"7500+",members:"20000+",categories:["community","programming","support"],description:"Official BetterDiscord server for support etc",identifier:"86004744966914048",icon:"https://cdn.discordapp.com/icons/86004744966914048/c8d49dc02248e1f55caeb897c3e1a26e.png",nativejoin:!0,invite_code:"0Tmfo5ZbORCRqbAd",pinned:!0},pinned:!0,join:this.join,guildList:r,fallback:o[Math.floor(5*Math.random())]})}get endPoint(){return"https://search.discordservers.com"}get joinEndPoint(){return"https://join.discordservers.com"}get connectEndPoint(){return"https://join.discordservers.com/connect"}checkConnection(){let a=this;try{$.ajax({method:"GET",url:`${a.endPoint}`,success:r=>{a.setState({selectedCategory:0,connection:{state:2,user:r}}),a.search("",!0)},error:r=>{return 403===r.status||404===r.status?void a.setState({title:"Not connected to discordservers.com!",loading:!0,selectedCategory:-1,connection:{state:1,user:null}}):void console.log(r)}})}catch(r){a.setState({title:"Not connected to discordservers.com!",loading:!0,selectedCategory:-1,connection:{state:1,user:null}})}}render(){return BDV2.react.createElement(V2Components.SidebarView,{ref:"sbv",children:this.component})}get component(){return{sidebar:{component:this.sidebar},content:{component:this.content},tools:{component:BDV2.react.createElement(V2Components.Tools,{key:"pt",ref:"tools",onClick:this.close})}}}get sidebar(){return BDV2.react.createElement("div",{className:"sidebar",key:"ps"},BDV2.react.createElement("div",{className:"ui-tab-bar SIDE"},BDV2.react.createElement("div",{className:"ui-tab-bar-header",style:{fontSize:"16px"}},"Public Servers"),BDV2.react.createElement(V2Components.TabBar.Separator,null),this.searchInput,BDV2.react.createElement(V2Components.TabBar.Separator,null),BDV2.react.createElement(V2Components.TabBar.Header,{text:"Categories"}),this.categoryButtons.map((a,r)=>{return BDV2.react.createElement(V2Components.TabBar.Item,{id:r,onClick:this.changeCategory,key:r,text:a,selected:this.state.selectedCategory===r})}),BDV2.react.createElement(V2Components.TabBar.Separator,null),this.footer))}get searchInput(){return BDV2.react.createElement("div",{className:"ui-form-item"},BDV2.react.createElement("div",{className:"ui-text-input flex-vertical",style:{width:"172px",marginLeft:"10px"}},BDV2.react.createElement("input",{ref:"searchinput",onKeyDown:this.searchKeyDown,onChange:()=>{},type:"text",className:"input default",placeholder:"Search...",maxLength:"50"})))}searchKeyDown(a){let r=this;if(!(r.state.loading||13!==a.which)){r.setState({loading:!0,title:"Loading...",term:a.target.value});let o=`?term=${a.target.value}`;0!==r.state.selectedCategory&&(o+=`&category=${r.categoryButtons[r.state.selectedCategory]}`),r.search(o,!0)}}get categoryButtons(){return["All","FPS Games","MMO Games","Strategy Games","Sports Games","Puzzle Games","Retro Games","Party Games","Tabletop Games","Sandbox Games","Simulation Games","Community","Language","Programming","Other"]}changeCategory(a){let r=this;if(!r.state.loading)return r.refs.searchinput.value="",r.setState({loading:!0,selectedCategory:a,title:"Loading...",term:null}),0===a?void r.search("",!0):void r.search(`?category=${r.categoryButtons[a]}`,!0)}get content(){let a=this,r=Object.keys(this.GuildStore.getGuilds()),o=this.AvatarDefaults.DEFAULT_AVATARS;return 1===a.state.connection.state?a.notConnected:[BDV2.react.createElement("div",{ref:"content",key:"pc",className:"content-column default"},BDV2.react.createElement(V2Components.SettingsTitle,{text:a.state.title}),a.bdServer,a.state.servers.map((d,l)=>{return BDV2.react.createElement(V2Components.ServerCard,{key:l,server:d,join:a.join,guildList:r,fallback:o[Math.floor(5*Math.random())]})}),a.state.next&&BDV2.react.createElement("button",{type:"button",onClick:()=>{a.state.loading||(a.setState({loading:!0}),a.search(a.state.next,!1))},className:"ui-button filled brand small grow",style:{width:"100%",marginTop:"10px",marginBottom:"10px"}},BDV2.react.createElement("div",{className:"ui-button-contents"},a.state.loading?"Loading":"Load More")),0<a.state.servers.length&&BDV2.react.createElement(V2Components.SettingsTitle,{text:a.state.title}))]}get footer(){return BDV2.react.createElement("div",{className:"ui-tab-bar-header"},BDV2.react.createElement("a",{href:"https://discordservers.com",target:"_blank"},"Discordservers.com"))}}