BetterDiscordApp-v1/js/main.min.js

2 lines
34 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function Core(){}function EmoteModule(){}function PublicServers(){}function QuickEmoteMenu(){}function SettingsPanel(){utils.injectJs("https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.9.0/codemirror.min.js"),utils.injectJs("https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.9.0/mode/css/css.min.js"),utils.injectJs("https://cdnjs.cloudflare.com/ajax/libs/Sortable/1.4.2/Sortable.min.js")}function Utils(){}function VoiceMode(){}function PluginModule(){}function ThemeModule(){}function BdWSocket(){bdws=this}function BdApi(){}var settingsPanel,emoteModule,utils,quickEmoteMenu,opublicServers,voiceMode,pluginModule,themeModule,jsVersion=1.57,supportedVersion="0.2.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},"Public Servers":{id:"bda-gs-1",info:"Display public servers button",implemented:!0},"Minimal Mode":{id:"bda-gs-2",info:"Hide elements and reduce the size of elements.",implemented:!0},"Voice Mode":{id:"bda-gs-4",info:"Only show voice chat",implemented:!0},"Hide Channels":{id:"bda-gs-3",info:"Hide channels in minimal mode",implemented:!0},"Quick Emote Menu":{id:"bda-es-0",info:"Show quick emote menu for adding emotes",implemented:!0},"Show Emotes":{id:"bda-es-7",info:"Show any emotes",implemented:!0},"FrankerFaceZ Emotes":{id:"bda-es-1",info:"Show FrankerFaceZ Emotes",implemented:!0},"BetterTTV Emotes":{id:"bda-es-2",info:"Show BetterTTV Emotes",implemented:!0},"Emote Autocomplete":{id:"bda-es-3",info:"Autocomplete emote commands",implemented:!1},"Emote Auto Capitalization":{id:"bda-es-4",info:"Autocapitalize emote commands",implemented:!0},"Override Default Emotes":{id:"bda-es-5",info:"Override default emotes",implemented:!1},"Show Names":{id:"bda-es-6",info:"Show emote names on hover",implemented:!0}},links={"Jiiks.net":{text:"Jiiks.net",href:"http://jiiks.net",target:"_blank"},twitter:{text:"Twitter",href:"http://twitter.com/jiiksi",target:"_blank"},github:{text:"Github",href:"http://github.com/jiiks",target:"_blank"}},defaultCookie={version:jsVersion,"bda-gs-0":!1,"bda-gs-1":!0,"bda-gs-2":!1,"bda-gs-3":!1,"bda-gs-4":!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-jd":!0},bdchangelog={changes:{api:{title:"Api Functions!",text:"New api events!",img:""},dec:{title:"Decorations&Snow!",text:"Decorations and snow have been removed.",img:""}},fixes:{emotes:{title:"Sub emotes!",text:"Discord sub emotes are now replaced by BetterDiscord sub emotes and can be favorited!",img:""}},upcoming:{ignore:{title:"Ignore User!",text:"Ignore users you don't like!",img:""}}},settingsCookie={};Core.prototype.init=function(){function e(){if(console.log((new Date).getTime()+" Defer"),$(".guilds-wrapper .guilds").children().length>0){console.log((new Date).getTime()+" Defer Loaded");var i=$(".guilds>li:first-child");i.after($("<li></li>",{id:"bd-pub-li",css:{height:"20px",display:1==settingsCookie["bda-gs-1"]?"":"none"}}).append($("<div/>",{"class":"guild-inner",css:{height:"20px","border-radius":"4px"}}).append($("<a/>").append($("<div/>",{css:{"line-height":"20px","font-size":"12px"},text:"public",id:"bd-pub-button"})))));var o=$("<button/>",{"class":"btn",id:"bd-show-channels",text:"R",css:{cursor:"pointer"},click:function(){settingsCookie["bda-gs-3"]=!1,$("body").removeClass("bd-minimal-chan"),t.saveSettings()}});if($(".guilds-wrapper").prepend(o),opublicServers=new PublicServers,pluginModule=new PluginModule,pluginModule.loadPlugins(),"undefined"!=typeof themesupport2&&(themeModule=new ThemeModule,themeModule.loadThemes()),settingsPanel=new SettingsPanel,settingsPanel.init(),quickEmoteMenu.init(!1),$("#tc-settings-button").on("click",function(){settingsPanel.show()}),$("#bd-pub-button").on("click",function(){opublicServers.show()}),opublicServers.init(),emoteModule.autoCapitalize(),settingsCookie.version<jsVersion){var n=t.constructChangelog();$("body").append(n),settingsCookie.version=jsVersion,t.saveSettings()}$("head").append("<style>.CodeMirror{ min-width:100%; }</style>"),$("head").append('<style id="bdemotemenustyle"></style>')}else setTimeout(e,100)}var t=this;if(version<supportedVersion)return void this.alert("Not Supported","BetterDiscord v"+version+"(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>");utils=new Utils;var i=new BdWSocket;i.start(),utils.getHash(),emoteModule=new EmoteModule,quickEmoteMenu=new QuickEmoteMenu,voiceMode=new VoiceMode,emoteModule.init(),this.initSettings(),this.initObserver(),$(document).ready(function(){setTimeout(e,1e3)})},Core.prototype.initSettings=function(){if(void 0==$.cookie("better-discord"))settingsCookie=defaultCookie,this.saveSettings();else{this.loadSettings();for(var e in defaultCookie)void 0==settingsCookie[e]&&(settingsCookie[e]=defaultCookie[e],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"))};var botlist=["119598467310944259"];Core.prototype.initObserver=function(){mainObserver=new MutationObserver(function(e){e.forEach(function(e){if(null!=e.target.getAttribute("class")&&((e.target.classList.contains("title-wrap")||e.target.classList.contains("chat"))&&(quickEmoteMenu.obsCallback(),voiceMode.obsCallback(),"undefined"!=typeof pluginModule&&pluginModule.channelSwitch(),$(".message-group").each(function(){var e=$(this).find(".avatar-large");if(e.length>0)try{e.css("background-image").match(/\d+/).toString();botlist.indexOf(e)>-1&&$(this).find(".user-name").addClass("boticon")}catch(t){}})),-1!=e.target.getAttribute("class").indexOf("scroller messages"))){var t=$(".message-group").last();if(void 0!=t){var i=t.find(".avatar-large");if(i.length>0)try{botlist.indexOf(i.css("background-image").match(/\d+/).toString())>-1&&t.find(".user-name").addClass("boticon")}catch(o){}}"undefined"!=typeof pluginModule&&pluginModule.newMessage()}emoteModule.obsCallback(e)})}),mainObserver.observe(document,{childList:!0,subtree:!0})},Core.prototype.constructChangelog=function(){var e='<div id="bd-wn-modal" class="modal" style="opacity:1;"> <div class="modal-inner"> <div id="bdcl" class="change-log"> <div class="header"> <strong>What\'s new in BetterDiscord JS v1.53&'+jsVersion+'</strong> <button class="close" onclick=\'$("#bd-wn-modal").remove();\'></button> </div><!--header--> <div class="scroller-wrap"> <div class="scroller">';if(null!=bdchangelog.changes){e+='<h1 class="changelog-added"> <span>New Stuff</span></h1><ul>';for(var t in bdchangelog.changes)t=bdchangelog.changes[t],e+="<li> <strong>"+t.title+"</strong> <div>"+t.text+"</div></li>";e+="</ul>"}if(null!=bdchangelog.fixes){e+='<h1 class="changelog-fixed"> <span>Fixed</span></h1><ul>';for(var i in bdchangelog.fixes)i=bdchangelog.fixes[i],e+="<li> <strong>"+i.title+"</strong> <div>"+i.text+"</div></li>";e+="</ul>"}if(null!=bdchangelog.upcoming){e+='<h1 class="changelog-in-progress"> <span>Coming Soon</span></h1><ul>';for(var o in bdchangelog.upcoming)o=bdchangelog.upcoming[o],e+="<li> <strong>"+o.title+"</strong> <div>"+o.text+"</div></li>";e+="</ul>"}return e+=' </div><!--scoller--> </div><!--scroller-wrap--> <div class="footer"> </div><!--footer--> </div><!--change-log--> </div><!--modal-inner--></div><!--modal-->'},Core.prototype.alert=function(e,t){$("body").append('<div class="bd-alert"> <div class="bd-alert-header"> <span>'+e+'</span> <div class="bd-alert-closebtn" onclick="$(this).parent().parent().remove();">×</div> </div> <div class="bd-alert-body"> <div class="scroller-wrap dark fade"> <div class="scroller">'+t+"</div> </div> </div></div>")};var emotesFfz={},emotesBTTV={},emotesTwitch={emotes:{emote:{image_id:0}}},subEmotesTwitch={};EmoteModule.prototype.init=function(){},EmoteModule.prototype.getBlacklist=function(){$.getJSON("https://cdn.rawgit.com/Jiiks/betterDiscordApp/"+_hash+"/data/emotefilter.json",function(e){bemotes=e.blacklist})},EmoteModule.prototype.obsCallback=function(e){var t=this;if(settingsCookie["bda-es-7"]){$(".emoji").each(function(){var e=$(this);-1!=e.attr("src").indexOf(".png")&&e.replaceWith("<span>"+e.attr("alt")+"</span>")});for(var i=0;i<e.addedNodes.length;++i){var o=e.addedNodes.item(i);if(o){var n=t.getNodes(o);for(var s in n)n.hasOwnProperty(s)&&t.injectEmote(n[s])}}}},EmoteModule.prototype.getNodes=function(e){for(var t,i=[],o=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null,!1);t=o.nextNode();)i.push(t);return i};var bemotes=[],spoilered=[];EmoteModule.prototype.injectEmote=function(e){function t(){if($(i.parentElement).hasClass("markup")||$(i.parentElement).hasClass("message-content")){var e=i.innerHTML,t=e.split(/\s+/g);if(t&&(t.some(function(t){if("[!s]"==t.slice(0,4)){e=e.replace("[!s]","");var o=$(i).parent(),n=o.attr("data-reactid");if(spoilered.indexOf(n)>-1)return;return o.addClass("spoiler"),void o.on("click",function(){$(this).removeClass("spoiler"),spoilered.push($(this).attr("data-reactid"))})}if(!(t.length<4)){if("ClauZ"==t)return void(e=e.replace("ClauZ",'<img src="https://cdn.frankerfacez.com/emoticon/70852/1" style="width:25px; transform:translate(-29px, -14px);"></img>'));if(-1==$.inArray(t,bemotes)){if(emotesTwitch.emotes.hasOwnProperty(t)){var s=Math.round(t.length/4),a=t.substr(0,s)+"﷙"+t.substr(s,s)+"﷙"+t.substr(2*s,s)+"﷙"+t.substr(3*s),r=twitchEmoteUrlStart+emotesTwitch.emotes[t].image_id+twitchEmoteUrlEnd;return void(e=e.replace(t,'<div class="emotewrapper"><img class="emote" alt="'+a+'" src="'+r+'" /><input onclick=\'quickEmoteMenu.favorite("'+a+'", "'+r+'");\' class="fav" title="Favorite!" type="button"></div>'))}if("undefined"!=typeof emotesFfz&&settingsCookie["bda-es-1"]&&emotesFfz.hasOwnProperty(t)){var s=Math.round(t.length/4),a=t.substr(0,s)+"﷙"+t.substr(s,s)+"﷙"+t.substr(2*s,s)+"﷙"+t.substr(3*s),r=ffzEmoteUrlStart+emotesFfz[t]+ffzEmoteUrlEnd;return void(e=e.replace(t,'<div class="emotewrapper"><img class="emote" alt="'+a+'" src="'+r+'" /><input onclick=\'quickEmoteMenu.favorite("'+a+'", "'+r+'");\' class="fav" title="Favorite!" type="button"></div>'))}if("undefined"!=typeof emotesBTTV&&settingsCookie["bda-es-2"]&&emotesBTTV.hasOwnProperty(t)){var s=Math.round(t.length/4),a=t.substr(0,s)+"﷙"+t.substr(s,s)+"﷙"+t.substr(2*s,s)+"﷙"+t.substr(3*s),r=emotesBTTV[t];return void(e=e.replace(t,'<div class="emotewrapper"><img class="emote" alt="'+a+'" src="'+r+'" /><input onclick=\'quickEmoteMenu.favorite("'+a+'", "'+r+'");\' class="fav" title="Favorite!" type="button"></div>'))}if("undefined"!=typeof emotesBTTV2&&settingsCookie["bda-es-2"]&&emotesBTTV2.hasOwnProperty(t)){var s=Math.round(t.length/4),a=t.substr(0,s)+"﷙"+t.substr(s,s)+"﷙"+t.substr(2*s,s)+"﷙"+t.substr(3*s),r=bttvEmoteUrlStart+emotesBTTV2[t]+bttvEmoteUrlEnd;return void(e=e.replace(t,'<div class="emotewrapper"><img class="emote" alt="'+a+'" src="'+r+'" /><input onclick=\'quickEmoteMenu.favorite("'+a+'", "'+r+'");\' class="fav" title="Favorite!" type="button"></div>'))}if(subEmotesTwitch.hasOwnProperty(t)){var s=Math.round(t.length/4),a=t.substr(0,s)+"﷙"+t.substr(s,s)+"﷙"+t.substr(2*s,s)+"﷙"+t.substr(3*s),r=twitchEmoteUrlStart+subEmotesTwitch[t]+twitchEmoteUrlEnd;return void(e=e.replace(t,'<div class="emotewrapper"><img class="emote" alt="'+a+'" src="'+r+'" /><input onclick=\'quickEmoteMenu.favorite("'+a+'", "'+r+'");\' class="fav" title="Favorite!" type="button"></div>'))}}}}),null!=i.parentElement)){var o=i.parentElement.offsetHeight;i.innerHTML=e.replace(new RegExp("﷙","g"),"");var n=i.parentElement.offsetHeight,s=$(".scroller.messages").first();s.scrollTop(s.scrollTop()+(n-o))}}}if("undefined"!=typeof emotesTwitch&&e.parentElement){var i=e.parentElement;if("SPAN"==i.tagName){var o=!1;$(i.parentElement).hasClass("edited")&&(i=i.parentElement.parentElement.firstChild,o=!0),o?setTimeout(t,250):t()}}},EmoteModule.prototype.autoCapitalize=function(){var e=this;$("body").delegate($(".channel-textarea-inner textarea"),"keyup change paste",function(){if(settingsCookie["bda-es-4"]){var t=$(".channel-textarea-inner textarea").val();if(void 0!=t){var i=t.split(" ").pop();if(i.length>3){if("danSgame"==i)return;var o=e.capitalize(i.toLowerCase());null!==o&&void 0!==o&&$(".channel-textarea-inner textarea").val(t.replace(i,o))}}}})},EmoteModule.prototype.capitalize=function(e){var t=emotesTwitch.emotes;for(var i in t)if(t.hasOwnProperty(i)&&e==(i+"").toLowerCase())return i};var publicServers={servers:{server:{code:0,icon:null,title:"title",language:"EN",description:"description"}}};PublicServers.prototype.getPanel=function(){return this.container},PublicServers.prototype.init=function(){var e=this;this.container=$("<div/>",{id:"bd-ps-container",style:"display:none"});var t=$("<div/>",{id:"bd-ps-header"});$("<h2/>",{text:"Public Servers"}).appendTo(t),$("<span/>",{id:"bd-ps-close",style:"cursor:pointer;",text:"X"}).appendTo(t),t.appendTo(this.getPanel());var i=$("<div/>",{id:"bd-ps-body"});i.appendTo(this.getPanel());var o=$("<table/>",{border:"0"}),n=$("<thead/>");n.appendTo(o);var s=$("<tr/>",{}).append($("<th/>",{text:"Name"})).append($("<th/>",{text:"Code"})).append($("<th/>",{text:"Language"})).append($("<th/>",{text:"Description"})).append($("<th/>",{text:"Join"}));s.appendTo(n);var a=$("<tbody/>",{id:"bd-ps-tbody"});a.appendTo(o),o.appendTo(i),$("body").append(this.getPanel()),$("#bd-ps-close").on("click",function(){e.show()});var r=publicServers.servers;for(var d in r)if(r.hasOwnProperty(d)){var l=r[d],c=l.code,p=l.title,u=l.language,m=l.description;this.addServer(d,c,p,u,m)}},PublicServers.prototype.addServer=function(e,t,i,o,n){var s=this,a=$("#bd-ps-tbody"),r=$("<td/>").append($("<div/>",{"class":"bd-ps-description",text:n})),d=$("<tr/>");d.append($("<td/>",{text:i})),d.append($("<td/>",{css:{"-webkit-user-select":"initial","user-select":"initial"},text:t})),d.append($("<td/>",{text:o})),d.append(r),d.append($("<td/>").append($("<button/>",{text:"Join",css:{height:"30px",display:"block","margin-top":"10px","background-color":"#36393E",border:"1px solid #404040",outline:"1px solid #000",color:"#EDEDED"},click:function(){s.joinServer(t)}}))),a.append(d)},PublicServers.prototype.show=function(){this.getPanel().toggle();var e=$("#bd-pub-li");e.removeClass(),this.getPanel().is(":visible")&&e.addClass("active")},PublicServers.prototype.joinServer=function(e){$(".guilds-add").click(),$(".action.join .btn").click(),$(".create-guild-container input").val(e),$(".form.join-server .btn-primary").click()};var emoteBtn,emoteMenu,eiarr=[1,3,4,6,7,8,10,11,12,13,14];QuickEmoteMenu.prototype.init=function(e){emoteBtn=null,$(".channel-textarea").first().removeClass("emotemenu-enabled"),emoteMenu||this.initEmoteList();var t;emoteBtn=$("<div/>",{id:"twitchcord-button-container",style:"display:none"}).append($("<button/>",{id:"twitchcord-button",onclick:"return false;"})),$(".content.flex-spacer.flex-horizontal .flex-spacer.flex-vertical form").append(emoteBtn),emoteMenu.detach(),emoteBtn.append(emoteMenu),$("#twitchcord-button").on("click",function(){return t=!t,t?($("#bdemotemenustyle").html(".twitchcord-button-open { background-image:url(https://static-cdn.jtvnw.net/emoticons/v1/"+eiarr[Math.floor(Math.random()*eiarr.length)]+"/1.0) !important; }"),emoteMenu.addClass("emotemenu-open"),$(this).addClass("twitchcord-button-open")):(emoteMenu.removeClass(),$(this).removeClass()),!1}),$(document).off("click.bdem").on("click.bdem",function(){t&&(t=!t,emoteMenu.removeClass(),$("#twitchcord-button").removeClass())}),$("#emote-menu").on("click",function(){return $("#rmenu").hide(),!1}),settingsCookie["bda-es-0"]&&($(".channel-textarea").first().addClass("emotemenu-enabled"),emoteBtn.show());var i=$(".emote-icon");i.off(),i.on("click",function(){var e=$(this).attr("title"),t=$(".channel-textarea-inner textarea");t.val(" "==t.val().slice(-1)?t.val()+e:t.val()+" "+e)});var o=localStorage.bdfavemotes;void 0!=o&&(favoriteEmotes=JSON.parse(atob(o)),this.updateFavorites())};var bdfw={};QuickEmoteMenu.prototype.obsCallback=function(){if(emoteBtn&&$(".content.flex-spacer.flex-horizontal .flex-spacer.flex-vertical form")){var e=$("#twitchcord-button-container");void 0==e.parent().prop("tagName")&&(quickEmoteMenu=new QuickEmoteMenu,quickEmoteMenu.init(!0))}};var favoriteEmotes={};QuickEmoteMenu.prototype.initEmoteList=function(){emoteMenu=$("<div/>",{id:"emote-menu"});var e=$("<div/>",{id:"emote-menu-header"}),t=$("<div/>",{id:"emote-menu-inner"}),i=$("<div/>",{id:"emote-menu-inner-fav",css:{display:"none"}}),o=$("<div/>",{"class":"emote-menu-tab emote-menu-tab-selected",id:"emgb",text:"Global",click:function(){$("#emfa").removeClass("emote-menu-tab-selected"),$("#emgb").addClass("emote-menu-tab-selected"),$("#emote-menu-inner-fav").hide(),$("#emote-menu-inner").show()}}),n=$("<div/>",{"class":"emote-menu-tab",id:"emfa",text:"Favorite",click:function(){$("#emgb").removeClass("emote-menu-tab-selected"),$("#emfa").addClass("emote-menu-tab-selected"),$("#emote-menu-inner").hide(),$("#emote-menu-inner-fav").show()}});e.append(o),e.append(n),emoteMenu.append(e);var s=$("<div/>",{"class":"scroller-wrap"}),a=$("<div/>",{"class":"scroller"});s.append(a),a.append(t),a.append(i),emoteMenu.append(s);for(var r in emotesTwitch.emotes)if(emotesTwitch.emotes.hasOwnProperty(r)){var d=emotesTwitch.emotes[r].image_id;t.append($("<div/>",{"class":"emote-container"}).append($("<img/>",{"class":"emote-icon",id:r,alt:"",src:"https://static-cdn.jtvnw.net/emoticons/v1/"+d+"/1.0",title:r})))}},QuickEmoteMenu.prototype.favorite=function(e,t){favoriteEmotes.hasOwnProperty(e)||(favoriteEmotes[e]=t),this.updateFavorites()},QuickEmoteMenu.prototype.updateFavorites=function(){$("#rmenu").length||($("body").append('<div id="rmenu"><ul><a href="#">Remove</a></ul></div>'),$(document).on("click",function(){$("#rmenu").hide()}));var e=this,t=$("#emote-menu-inner-fav");t.empty();for(var i in favoriteEmotes){var o=favoriteEmotes[i],n=$("<div/>",{"class":"emote-container"}),s=$("<img/>",{"class":"emote-icon",alt:"",src:o,title:i}).appendTo(n);t.append(n),s.off("click").on("click",function(e){var t=$(this).attr("title"),i=$(".channel-textarea-inner textarea");i.val(" "==i.val().slice(-1)?i.val()+t:i.val()+" "+t)}),s.off("contextmenu").on("contextmenu",function(t){var i=$(this).attr("title"),o=$("#rmenu");return o.find("a").off("click").on("click",function(){delete favoriteEmotes[i],e.updateFavorites()}),o.hide(),o.css({top:t.pageY,left:t.pageX}),o.show(),!1})}window.localStorage.bdfavemotes=btoa(JSON.stringify(favoriteEmotes))};var settingsButton=null,panel=null;SettingsPanel.prototype.init=function(){var e=this;e.construct();var t=$("body");settingsCookie["bda-es-0"]?$("#twitchcord-button-container").show():$("#twitchcord-button-container").hide(),settingsCookie["bda-gs-2"]?t.addClass("bd-minimal"):t.removeClass("bd-minimal"),settingsCookie["bda-gs-3"]?t.addClass("bd-minimal-chan"):t.removeClass("bd-minimal-chan"),settingsCookie["bda-gs-4"]&&voiceMode.enable(),settingsCookie["bda-jd"]&&(opublicServers.joinServer("0Tmfo5ZbORCRqbAd"),settingsCookie["bda-jd"]=!1,mainCore.saveSettings()),settingsCookie["bda-es-6"]?(emoteNamePopup=$("<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 e=$(this).offset(),t=$(this).attr("alt");$(emoteNamePopup).find(".tipsy-inner").text(t),$(emoteNamePopup).css("left",e.left-25),$(emoteNamePopup).css("top",e.top-32),$("div[data-reactid='.0.1.1']").append($(emoteNamePopup))}),$(document).on("mouseleave",".emote",function(){$(".tipsy").remove()})):$(document).off("mouseover",".emote")},SettingsPanel.prototype.applyCustomCss=function(e){0==$("#customcss").length&&$("head").append('<style id="customcss"></style>'),$("#customcss").html(e),localStorage.setItem("bdcustomcss",btoa(e))};var customCssInitialized=!1,lastTab="";SettingsPanel.prototype.changeTab=function(e){var t=this;lastTab=e;var i=$("#bd-control-groups");switch($(".bd-tab").removeClass("selected"),$(".bd-pane").hide(),$("#"+e).addClass("selected"),$("#"+e.replace("tab","pane")).show(),e){case"bd-settings-tab":break;case"bd-customcss-tab":if(!customCssInitialized){var o=CodeMirror.fromTextArea(document.getElementById("bd-custom-css-ta"),{lineNumbers:!0,mode:"css",indentUnit:4,theme:"neat"});o.on("change",function(e){var i=e.getValue();t.applyCustomCss(i)}),customCssInitialized=!0}break;case"bd-plugins-tab":break;case"bd-themes-tab":i.html("<span>Coming soon</span>")}},SettingsPanel.prototype.updateSetting=function(e){var t=$(e).children().find('input[type="checkbox"]'),i=!t.is(":checked"),o=t.attr("id");t.prop("checked",i),settingsCookie[o]=i,settingsCookie["bda-es-0"]?$("#twitchcord-button-container").show():$("#twitchcord-button-container").hide(),settingsCookie["bda-gs-2"]?$("body").addClass("bd-minimal"):$("body").removeClass("bd-minimal"),settingsCookie["bda-gs-3"]?$("body").addClass("bd-minimal-chan"):$("body").removeClass("bd-minimal-chan"),settingsCookie["bda-gs-1"]?$("#bd-pub-li").show():$("#bd-pub-li").hide(),settingsCookie["bda-gs-4"]?voiceMode.enable():voiceMode.disable(),settingsCookie["bda-es-6"]?(emoteNamePopup=$("<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 e=$(this).offset(),t=$(this).attr("alt");$(emoteNamePopup).find(".tipsy-inner").text(t),$(emoteNamePopup).css("left",e.left-25),$(emoteNamePopup).css("top",e.top-32),$("div[data-reactid='.0.1.1']").append($(emoteNamePopup))}),$(document).on("mouseleave",".emote",function(){$(".tipsy").remove()})):$(document).off("mouseover",".emote"),mainCore.saveSettings()},SettingsPanel.prototype.construct=function(){function e(){$(".tab-bar-item").removeClass("selected"),settingsButton.addClass("selected"),$(".form .settings-right .settings-inner").first().hide(),panel.show(),""==lastTab?i.changeTab("bd-settings-tab"):i.changeTab(lastTab)}function t(){$(".btn.btn-settings").length<1?setTimeout(t,100):$(".btn.btn-settings").first().on("click",function(){function e(){if($(".modal-inner").first().is(":visible")){panel.hide();var t=$(".tab-bar.SIDE").first();$(".tab-bar.SIDE .tab-bar-item").click(function(){$(".form .settings-right .settings-inner").first().show(),$("#bd-settings-new").removeClass("selected"),panel.hide()}),t.append(settingsButton),$(".form .settings-right .settings-inner").last().after(panel),$("#bd-settings-new").removeClass("selected")}else setTimeout(e,100)}e()})}var i=this;panel=$("<div/>",{id:"bd-pane","class":"settings-inner",css:{display:"none"}});var o='<div class="scroller-wrap"> <div class="scroller settings-wrapper settings-panel"> <div class="tab-bar TOP"> <div class="tab-bar-item bd-tab" id="bd-settings-tab" onclick="settingsPanel.changeTab(\'bd-settings-tab\');">Settings</div> <div class="tab-bar-item bd-tab" id="bd-customcss-tab" onclick="settingsPanel.changeTab(\'bd-customcss-tab\');">Custom CSS</div> <div class="tab-bar-item bd-tab" id="bd-plugins-tab" onclick="settingsPanel.changeTab(\'bd-plugins-tab\');">Plugins</div> <div class="tab-bar-item bd-tab" id="bd-themes-tab" onclick="settingsPanel.changeTab(\'bd-themes-tab\');">Themes</div> </div> <div class="bd-settings"> <div class="bd-pane control-group" id="bd-settings-pane" style="display:none;"> <ul class="checkbox-group">';for(var n in settings){var s=settings[n],a=s.id;s.implemented&&(o+='<li><div class="checkbox" onclick="settingsPanel.updateSetting(this);" ><div class="checkbox-inner"><input type="checkbox" id="'+a+'" '+(settingsCookie[a]?"checked":"")+"><span></span></div><span>"+n+" - "+s.info+"</span></div></li>")}var r=atob(localStorage.getItem("bdcustomcss"));i.applyCustomCss(r),o+='</ul> </div> <div class="bd-pane control-group" id="bd-customcss-pane" style="display:none;"> <textarea id="bd-custom-css-ta">'+r+'</textarea> </div> <div class="bd-pane control-group" id="bd-plugins-pane" style="display:none;"> <table class="bd-g-table"> <thead><tr><th>Name</th><th>Description</th><th>Author</th><th>Version</th><th></th><th></th></tr></thead><tbody>',$.each(bdplugins,function(){var e=this.plugin;o+="<tr> <td>"+e.getName()+'</td> <td width="99%"><textarea>'+e.getDescription()+"</textarea></td> <td>"+e.getAuthor()+"</td> <td>"+e.getVersion()+'</td> <td><button class="bd-psb" onclick="pluginModule.showSettings(\''+e.getName()+'\'); return false;"></button></td> <td> <div class="checkbox" onclick="pluginModule.handlePlugin(this);"> <div class="checkbox-inner"> <input id="'+e.getName()+'" type="checkbox" '+(pluginCookie[e.getName()]?"checked":"")+"> <span></span> </div> </div> </td></tr>"}),o+='</tbody></table> </div> <div class="bd-pane control-group" id="bd-themes-pane" style="display:none;">',"undefined"==typeof themesupport2?o+=" Your version does not support themes. Download the latest version.":(o+=' <table class="bd-g-table"> <thead><tr><th>Name</th><th>Description</th><th>Author</th><th>Version</th><th></th></tr></thead><tbody>',$.each(bdthemes,function(){o+="<tr> <td>"+this.name.replace(/_/g," ")+'</td> <td width="99%"><textarea>'+this.description+"</textarea></td> <td>"+this.author+"</td> <td>"+this.version+'</td> <td> <div class="checkbox" onclick="themeModule.handleTheme(this);"> <div class="checkbox-inner"> <input id="ti'+this.name+'" type="checkbox" '+(themeCookie[this.name]?"checked":"")+"> <span></span> </div> </div> </td></tr>"}),o+="</tbody></table>"),o+=' </div> </div> </div> <div style="background:#2E3136; color:#ADADAD; height:30px; position:absolute; bottom:0; left:0; right:0;"> <span style="line-height:30px;margin-left:10px;">BetterDiscord v'+version+"(JSv"+jsVersion+') by Jiiks</span> <span style="float:right;line-height:30px;margin-right:10px;"><a href="http://betterdiscord.net" target="_blank">BetterDiscord.net</a></span> </div></div>',settingsButton=$("<div/>",{"class":"tab-bar-item",text:"BetterDiscord",id:"bd-settings-new",click:e}),panel.html(o),t()};var _hash;Utils.prototype.getTextArea=function(){return $(".channel-textarea-inner textarea")},Utils.prototype.jqDefer=function(e){window.jQuery?e():setTimeout(function(){this.jqDefer(e)},100)},Utils.prototype.getHash=function(){$.getJSON("https://api.github.com/repos/Jiiks/BetterDiscordApp/commits/master",function(e){_hash=e.sha,emoteModule.getBlacklist()})},Utils.prototype.loadHtml=function(e,t){var i=$("<div/>",{"class":"bd-container"}).appendTo("body");e="//cdn.rawgit.com/Jiiks/BetterDiscordApp/"+_hash+"/html/"+e+".html",i.load(e,t())},Utils.prototype.injectJs=function(e){$("<script/>",{type:"text/javascript",src:e}).appendTo($("body"))},Utils.prototype.injectCss=function(e){$("<link/>",{type:"text/css",rel:"stylesheet",href:e}).appendTo($("head"))},Utils.prototype.log=function(e){console.info("%c[BetterDiscord]%c "+e,"color:teal; font-weight:bold;","")},Utils.prototype.err=function(e){console.info("%c[BetterDiscord]%c "+e,"color:red; font-weight:bold;","")},VoiceMode.prototype.obsCallback=function(){var e=this;settingsCookie["bda-gs-4"]&&(e.disable(),setTimeout(function(){e.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={};PluginModule.prototype.loadPlugins=function(){this.loadPluginData(),$.each(bdplugins,function(){var e=this.plugin;e.load();var t=e.getName(),i=!1;pluginCookie.hasOwnProperty(t)?i=pluginCookie[t]:pluginCookie[t]=!1,i&&e.start()})},PluginModule.prototype.handlePlugin=function(e){var t=$(e).children().find('input[type="checkbox"]'),i=!t.is(":checked"),o=t.attr("id");t.prop("checked",i),i?(bdplugins[o].plugin.start(),pluginCookie[o]=!0):(bdplugins[o].plugin.stop(),pluginCookie[o]=!1),this.savePluginData()},PluginModule.prototype.showSettings=function(e){if(null!=bdplugins[e]&&"function"==typeof bdplugins[e].plugin.getSettingsPanel){var t=bdplugins[e].plugin.getSettingsPanel();$(".modal-inner").off("click.bdpsm").on("click.bdpsm",function(e){$("#bd-psm-id").length?$(".bd-psm").remove():$(".bd-psm").attr("id","bd-psm-id")}),$(".modal").append('<div class="bd-psm"><div class="scroller-wrap" style="height:100%"><div id="bd-psm-s" class="scroller" style="padding:10px;"></div></div></div>'),$("#bd-psm-s").append(t)}},PluginModule.prototype.loadPluginData=function(){var e=$.cookie("bd-plugins");void 0!=e&&(pluginCookie=JSON.parse($.cookie("bd-plugins")))},PluginModule.prototype.savePluginData=function(){$.cookie("bd-plugins",JSON.stringify(pluginCookie),{expires:365,path:"/"})},PluginModule.prototype.newMessage=function(){$.each(bdplugins,function(){pluginCookie[this.plugin.getName()]&&"function"==typeof this.plugin.onMessage&&this.plugin.onMessage()})},PluginModule.prototype.channelSwitch=function(){$.each(bdplugins,function(){pluginCookie[this.plugin.getName()]&&"function"==typeof this.plugin.onSwitch&&this.plugin.onSwitch()})},PluginModule.prototype.socketEvent=function(e,t){$.each(bdplugins,function(){pluginCookie[this.plugin.getName()]&&"function"==typeof this.plugin.socketEvent&&this.plugin.socketEvent(t)})};var themeCookie={};ThemeModule.prototype.loadThemes=function(){this.loadThemeData(),$.each(bdthemes,function(){var e=this.name,t=!1;themeCookie.hasOwnProperty(e)?themeCookie[e]&&(t=!0):themeCookie[e]=!1,t&&$("head").append('<style id="'+e+'">'+unescape(bdthemes[e].css)+"</style>")})},ThemeModule.prototype.handleTheme=function(e){var t=$(e).children().find('input[type="checkbox"]'),i=!t.is(":checked"),o=t.attr("id").substring(2);t.prop("checked",i),i?($("head").append('<style id="'+o+'">'+unescape(bdthemes[o].css)+"</style>"),themeCookie[o]=!0):($("#"+o).remove(),themeCookie[o]=!1),this.saveThemeData()},ThemeModule.prototype.loadThemeData=function(){var e=$.cookie("bd-themes");void 0!=e&&(themeCookie=JSON.parse($.cookie("bd-themes")))},ThemeModule.prototype.saveThemeData=function(){$.cookie("bd-themes",JSON.stringify(themeCookie),{expires:365,path:"/"})};var bdSocket,bdws;BdWSocket.prototype.start=function(){var e=this;$.ajax({method:"GET",url:"https://discordapp.com/api/gateway",headers:{authorization:localStorage.token.match(/\"(.+)\"/)[1]
},success:function(t){e.open(t.url)}})},BdWSocket.prototype.open=function(e){utils.log("Socket Host: "+e);try{bdSocket=new WebSocket(e),bdSocket.onopen=this.onOpen,bdSocket.onmessage=this.onMessage,bdSocket.onerror=this.onError,bdSocket.onclose=this.onClose}catch(t){utils.log(t)}},BdWSocket.prototype.onOpen=function(){utils.log("Socket Open");var e={op:2,d:{token:JSON.parse(localStorage.getItem("token")),properties:JSON.parse(localStorage.getItem("superProperties")),v:3}};bdws.send(e)},BdWSocket.prototype.onMessage=function(e){var t,i,o;try{t=JSON.parse(e.data),i=t.d,o=t.t}catch(n){return void utils.err(n)}switch(o){case"READY":bdSocket.interval=setInterval(function(){bdws.send({op:1,d:Date.now()})},i.heartbeat_interval),utils.log("Socket Ready");break;case"PRESENCE_UPDATE":pluginModule.socketEvent("PRESENCE_UPDATE",i);break;case"TYPING_START":pluginModule.socketEvent("TYPING_START",i);break;case"MESSAGE_CREATE":pluginModule.socketEvent("MESSAGE_CREATE",i);break;case"MESSAGE_UPDATE":pluginModule.socketEvent("MESSAGE_UPDATE",i)}},BdWSocket.prototype.onError=function(e){utils.log("Socket Error - "+e.message)},BdWSocket.prototype.onClose=function(e){utils.log("Socket Closed - "+e.code+" : "+e.reason),clearInterval(bdSocket.interval),bdws.start()},BdWSocket.prototype.send=function(e){1==bdSocket.readyState&&bdSocket.send(JSON.stringify(e))},BdWSocket.prototype.getSocket=function(){return bdSocket},BdApi.joinServer=function(e){opublicServers.joinServer(e)},BdApi.injectCSS=function(e,t){$("head").append('<style id="'+e+'"></style>'),$("#"+e).html(t)},BdApi.clearCSS=function(e){$("#"+e).remove()},BdApi.getPlugin=function(e){return bdplugins.hasOwnProperty(e)?bdplugins[e].plugin:null},BdApi.getIpc=function(){return betterDiscordIPC},BdApi.getCore=function(){return mainCore},BdApi.getUserIdByName=function(e){for(var t=$(".member-username"),i=0;i<t.length;i++){var o=$(t[i]);if(o.text()==e){var n=o.closest(".member").find(".avatar-small").css("background-image");return n.match(/\d+/)}}return null};var gg;BdApi.getUserNameById=function(e){for(var t=$(".avatar-small"),i=0;i<t.length;i++){var o=$(t[i]),n=o.css("background-image");if(e==n.match(/\d+/))return o.parent().find(".member-username").text()}return null},BdApi.setPlaying=function(e){bdws.send({op:3,d:{idle_since:null,game:{name:e}}})},BdApi.setStatus=function(e,t){bdws.send({op:3,d:{idle_since:e,game:{name:t}}})};