BetterDiscordApp-v1/js/main.min.js

1 line
17 KiB
JavaScript

function Core(){}function EmoteModule(){}function PublicServers(){}function QuickEmoteMenu(){}function SettingsPanel(){}function Utils(){}function VoiceMode(){}var settingsPanel,emoteModule,utils,quickEmoteMenu,opublicServers,voiceMode,jsVersion=1.3,supportedVersion="0.1.5",mainObserver,twitchEmoteUrlStart="https://static-cdn.jtvnw.net/emoticons/v1/",twitchEmoteUrlEnd="/1.0",ffzEmoteUrlStart="https://cdn.frankerfacez.com/emoticon/",ffzEmoteUrlEnd="/1",bttvEmoteUrlStart="",bttvEmoteUrlEnd="",mainCore,settings={"Save logs locally":{id:"bda-gs-0",info:"Saves chat logs locally",implemented:!1},"Public Servers":{id:"bda-gs-1",info:"BETA : 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},"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}},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":!1,"bda-es-2":!1,"bda-es-3":!1,"bda-es-4":!1,"bda-es-5":!0},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 t=$(".guilds li:first-child");t.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"}))))),t.after($("<li/>",{id:"tc-settings-li"}).append($("<div/>",{"class":"guild-inner"}).append($("<a/>").append($("<div/>",{"class":"avatar-small",id:"tc-settings-button"}))))),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=new PublicServers,opublicServers.init(),emoteModule.autoCapitalize()}else setTimeout(e,100)}return version<supportedVersion?void alert("BetterDiscord v"+version+"(your version) is not supported by the latest js("+jsVersion+"). Please download the latest version from GitHub."):(utils=new Utils,utils.getHash(),emoteModule=new EmoteModule,quickEmoteMenu=new QuickEmoteMenu,voiceMode=new VoiceMode,emoteModule.init(),this.initSettings(),this.initObserver(),void $(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"))},Core.prototype.initObserver=function(){mainObserver=new MutationObserver(function(e){e.forEach(function(e){null!=e.target.getAttribute("class")&&-1!=e.target.getAttribute("class").indexOf("titlebar")&&(quickEmoteMenu.obsCallback(),voiceMode.obsCallback()),emoteModule.obsCallback(e)})}),mainObserver.observe(document,{childList:!0,subtree:!0})};var emotesFfz={},emotesBTTV={},emotesTwitch={emotes:{emote:{image_id:0}}},subEmotesTwitch={},twitchAc={"4head":"4Head",anele:"ANELE",argieb8:"ArgieB8",arsonnosexy:"ArsonNoSexy",asianglow:"AsianGlow",atgl:"AtGL",athenapms:"AthenaPMS",ativy:"AtIvy",atww:"AtWW",babyrage:"BabyRage",batchest:"BatChest",bcwarrior:"BCWarrior",biblethump:"BibleThump",bigbrother:"BigBrother",bionicbunion:"BionicBunion",blargnaut:"BlargNaut",bloodtrail:"BloodTrail",bort:"BORT",brainslug:"BrainSlug",brokeback:"BrokeBack",buddhabar:"BuddhaBar",coolcat:"CoolCat",corgiderp:"CorgiDerp",cougarhunt:"CougarHunt",daesuppy:"DAESuppy",dansgame:"DansGame",dathass:"DatHass",datsheffy:"DatSheffy",dbstyle:"DBstyle",deexcite:"deExcite",deilluminati:"deIlluminati",dendiface:"DendiFace",dogface:"DogFace",doomguy:"DOOMGuy",eagleeye:"EagleEye",elegiggle:"EleGiggle",evilfetus:"EvilFetus",failfish:"FailFish",fpsmarksman:"FPSMarksman",frankerz:"FrankerZ",freakinstinkin:"FreakinStinkin",fungineer:"FUNgineer",funrun:"FunRun",fuzzyotteroo:"FuzzyOtterOO",gasjoker:"GasJoker",gingerpower:"GingerPower",grammarking:"GrammarKing",hassanchop:"HassanChop",heyguys:"HeyGuys",hotpokket:"HotPokket",humblelife:"HumbleLife",itsboshytime:"ItsBoshyTime",jebaited:"Jebaited",jkanstyle:"JKanStyle",joncarnage:"JonCarnage",kapow:"KAPOW",kappa:"Kappa",kappapride:"KappaPride",keepo:"Keepo",kevinturtle:"KevinTurtle",kippa:"Kippa",kreygasm:"Kreygasm",kzskull:"KZskull",mau5:"Mau5",mcat:"mcaT",mechasupes:"MechaSupes",mrdestructoid:"MrDestructoid",mvgame:"MVGame",nightbat:"NightBat",ninjatroll:"NinjaTroll",nonospot:"NoNoSpot",notatk:"NotATK",notlikethis:"NotLikeThis",omgscoots:"OMGScoots",onehand:"OneHand",opieop:"OpieOP",optimizeprime:"OptimizePrime",osbeaver:"OSbeaver",osbury:"OSbury",osdeo:"OSdeo",osfrog:"OSfrog",oskomodo:"OSkomodo",osrob:"OSrob",ossloth:"OSsloth",panicbasket:"panicBasket",panicvis:"PanicVis",pazpazowitz:"PazPazowitz",peopleschamp:"PeoplesChamp",permasmug:"PermaSmug",picomause:"PicoMause",pipehype:"PipeHype",pjharley:"PJHarley",pjsalt:"PJSalt",pmstwin:"PMSTwin",pogchamp:"PogChamp",poooound:"Poooound",praiseit:"PraiseIt",prchase:"PRChase",punchtrees:"PunchTrees",puppeyface:"PuppeyFace",raccattack:"RaccAttack",ralpherz:"RalpherZ",redcoat:"RedCoat",residentsleeper:"ResidentSleeper",ritzmitz:"RitzMitz",rulefive:"RuleFive",shadylulu:"ShadyLulu",shazam:"Shazam",shazamicon:"shazamicon",shazbotstix:"ShazBotstix",shibez:"ShibeZ",smorc:"SMOrc",smskull:"SMSkull",sobayed:"SoBayed",soonerlater:"SoonerLater",srihead:"SriHead",ssssss:"SSSsss",stonelightning:"StoneLightning",strawbeary:"StrawBeary",supervinlin:"SuperVinlin",swiftrage:"SwiftRage",tbbaconbiscuit:"tbBaconBiscuit",tbchickenbiscuit:"tbChickenBiscuit",tbquesarito:"tbQuesarito",tbsausagebiscuit:"tbSausageBiscuit",tbspicy:"tbSpicy",tbsriracha:"tbSriracha",tf2john:"TF2John",theking:"TheKing",theringer:"TheRinger",thetarfu:"TheTarFu",thething:"TheThing",thunbeast:"ThunBeast",tinyface:"TinyFace",toospicy:"TooSpicy",trihard:"TriHard",ttours:"TTours",uleetbackup:"UleetBackup",unclenox:"UncleNox",unsane:"UnSane",vaultboy:"VaultBoy",volcania:"Volcania",wholewheat:"WholeWheat",winwaker:"WinWaker",wtruck:"WTRuck",wutface:"WutFace",youwhy:"YouWHY"};EmoteModule.prototype.init=function(){$.getJSON("https://cdn.rawgit.com/Jiiks/betterDiscordApp/"+_hash+"/emotefilter.json",function(e){bemotes=e.blacklist})},EmoteModule.prototype.obsCallback=function(e){for(var t=this,i=0;i<e.addedNodes.length;++i){var o=e.addedNodes.item(i);if(o){var n=t.getNodes(o);for(var a in n)n.hasOwnProperty(a)&&t.injectEmote(n[a])}}},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=[];EmoteModule.prototype.injectEmote=function(e){if("undefined"!=typeof emotesTwitch&&e.parentElement){var t=e.parentElement;if("SPAN"==t.tagName){var i=t.innerHTML,o=i.split(" ");if(o&&(o.some(function(e){return-1!=$.inArray(e,bemotes)||e.length<4?void 0:emotesTwitch.emotes.hasOwnProperty(e)?void(i=i.replace(e,"<img src="+twitchEmoteUrlStart+emotesTwitch.emotes[e].image_id+twitchEmoteUrlEnd+" ></img>")):"undefined"!=typeof emotesFfz&&settingsCookie["bda-es-1"]&&emotesFfz.hasOwnProperty(e)?void(i=i.replace(e,"<img src="+ffzEmoteUrlStart+emotesFfz[e]+ffzEmoteUrlEnd+" ></img>")):"undefined"!=typeof emotesBTTV&&settingsCookie["bda-es-2"]&&emotesBTTV.hasOwnProperty(e)?void(i=i.replace(e,"<img src="+emotesBTTV[e]+" ></img>")):void(subEmotesTwitch.hasOwnProperty(e)&&(i=i.replace(e,"<img src="+twitchEmoteUrlStart+subEmotesTwitch[e]+twitchEmoteUrlEnd+" ></img>")))}),null!=t.parentElement)){var n=t.parentElement.offsetHeight;t.innerHTML=i;var a=t.parentElement.offsetHeight,s=$(".scroller.messages").first();s.scrollTop(s.scrollTop()+(a-n))}}}},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){var o=e.capitalize(i.toLowerCase());null!=o&&$(".channel-textarea-inner textarea").val(t.replace(i,o))}}}})},EmoteModule.prototype.capitalize=function(e){return twitchAc.hasOwnProperty(e)?twitchAc[e]:null};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 a=$("<tr/>",{}).append($("<th/>",{text:"Name"})).append($("<th/>",{text:"Code"})).append($("<th/>",{text:"Language"})).append($("<th/>",{text:"Description"})).append($("<th/>",{text:"Join"}));a.appendTo(n);var s=$("<tbody/>",{id:"bd-ps-tbody"});s.appendTo(o),o.appendTo(i),$("body").append(this.getPanel()),$("#bd-ps-close").on("click",function(){e.show()});var r=publicServers.servers;for(var l in r)if(r.hasOwnProperty(l)){var c=r[l],d=c.code,p=c.title,u=c.language,m=c.description;this.addServer(l,d,p,u,m)}},PublicServers.prototype.addServer=function(e,t,i,o,n){var a=this,s=$("#bd-ps-tbody"),r=$("<td/>").append($("<div/>",{"class":"bd-ps-description",text:n})),l=$("<tr/>");l.append($("<td/>",{text:i})),l.append($("<td/>",{css:{"-webkit-user-select":"initial","user-select":"initial"},text:t})),l.append($("<td/>",{text:o})),l.append(r),l.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(){a.joinServer(t)}}))),s.append(l)},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;QuickEmoteMenu.prototype.init=function(){emoteBtn=null,emoteMenu||this.initEmoteList();var e;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(){e=!e,e?(emoteMenu.addClass("emotemenu-open"),$(this).addClass("twitchcord-button-open")):(emoteMenu.removeClass(),$(this).removeClass())}),settingsCookie["bda-es-0"]&&emoteBtn.show();var t=$(".emote-icon");t.off(),t.on("click",function(){var e=$(this).attr("id"),t=$(".channel-textarea-inner textarea");t.val(" "==t.val().slice(-1)?t.val()+e:t.val()+" "+e)})},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))}},QuickEmoteMenu.prototype.initEmoteList=function(){emoteMenu=$("<div/>",{id:"emote-menu"});var e=$("<div/>",{id:"emote-menu-header"}).append($("<span/>",{text:"Global Emotes"})),t=$("<div/>",{id:"emote-menu-inner"});emoteMenu.append(e),emoteMenu.append(t);for(var i in emotesTwitch.emotes)if(emotesTwitch.emotes.hasOwnProperty(i)){var o=emotesTwitch.emotes[i].image_id;t.append($("<div/>",{"class":"emote-container"}).append($("<img/>",{"class":"emote-icon",id:i,alt:"",src:"https://static-cdn.jtvnw.net/emoticons/v1/"+o+"/1.0",title:i})))}};var links={"Jiiks.net":"http://jiiks.net",Twitter:"http://twitter.com/jiiksi",Github:"https://github.com/jiiks"};SettingsPanel.prototype.getPanel=function(){return this.tcSettingsPanel},SettingsPanel.prototype.init=function(){var e=this,t=$("body");this.tcSettingsPanel=$("<div/>",{id:"tc-settings-panel",style:"display:none"}),this.getPanel().append($("<div/>",{id:"tc-settings-panel-header"}).append($("<h2/>",{text:"BetterDiscord - Settings"})).append($("<span/>",{id:"tc-settings-close",text:"X",style:"cursor:pointer;"})));var i=$("<ul/>");this.getPanel().append($("<div/>",{id:"tc-settings-panel-body"}).append(i)),$.each(settings,function(e,t){var o="tc-switch-on",n="tc-switch-off";settingsCookie[t.id]?o="tc-switch-on active":n="tc-switch-off active",i.append($("<li/>").append($("<h2/>",{text:e})).append($("<span/>",{html:" - <span>"+t.info+"</span>"+(0==t.implemented?'<span style="color:red"> Coming Soon</span>':"")})).append($("<div/>",{"class":t.implemented?"tc-switch":"tc-switch disabled",id:t.id}).append($("<span/>",{"class":n,text:"OFF"})).append($("<span/>",{"class":o,text:"ON"}))))});var o=$("<div/>",{id:"tc-settings-panel-footer"});o.append($("<span/>",{id:"tc-about",text:"BDA v"+version+"(js "+jsVersion+") by Jiiks | Settings are automatically saved."}));var n=$("<span/>",{id:"tc-links"});$.each(links,function(e,t){n.append($("<a/>",{href:t,text:e,target:"_blank"})),n.append($("<span/>",{text:" | "}))}),o.append(n),this.getPanel().append(o),t.append(this.getPanel()),$("#tc-settings-close").on("click",function(){e.show()}),$(".tc-switch").on("click",function(){e.handler($(this))}),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()},SettingsPanel.prototype.show=function(){this.getPanel().toggle();var e=$("#tc-settings-li");e.removeClass(),this.getPanel().is(":visible")&&e.addClass("active")},SettingsPanel.prototype.handler=function(e){var t=e.attr("id"),i=settingsCookie[t];i=!i,settingsCookie[t]=i;var o=$("#"+t+" .tc-switch-off"),n=$("#"+t+" .tc-switch-on");o.removeClass("active"),n.removeClass("active"),i?n.addClass("active"):o.addClass("active"),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(),mainCore.saveSettings()};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})},VoiceMode.prototype.obsCallback=function(){console.log("voiceMode obs");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","")};