BetterDiscordApp-v2/js/main.min.js

3 lines
62 KiB
JavaScript
Raw Normal View History

(function(){let __fs=window.require("fs");let __process=window.require("process");let __platform=__process.platform;let __dataPath=(__platform==="win32"?__process.env.APPDATA:__platform==="darwin"?__process.env.HOME+"/Library/Preferences":process.env.HOME+"/.config")+"/BetterDiscord/";let __data={};if(__fs.existsSync(`${__dataPath}localStorage.json`)){try{__data=JSON.parse(__fs.readFileSync(`${__dataPath}localStorage.json`))}catch(err){console.log(err)}}else if(__fs.existsSync("localStorage.json")){try{__data=JSON.parse(__fs.readFileSync("localStorage.json"))}catch(err){console.log(err)}}var __ls=__data;__ls.setItem=function(i,v){__ls[i]=v;this.save()};__ls.getItem=function(i){return __ls[i]||null};__ls.save=function(){__fs.writeFileSync(`${__dataPath}/localStorage.json`,JSON.stringify(this),null,4)};var __proxy=new Proxy(__ls,{set:function(target,name,val,receiver){__ls[name]=val;__ls.save()},get:function(target,name,receiver){return __ls[name]||null}});window.localStorage=__proxy})();window.bdStorage={};window.bdStorage.get=function(i){return betterDiscordIPC.sendSync("synchronous-message",{arg:"storage",cmd:"get",var:i})};window.bdStorage.set=function(i,v){betterDiscordIPC.sendSync("synchronous-message",{arg:"storage",cmd:"set",var:i,data:v})};window.bdPluginStorage={};window.bdPluginStorage.get=function(pn,i){return betterDiscordIPC.sendSync("synchronous-message",{arg:"pluginstorage",cmd:"get",pn:pn,var:i})};window.bdPluginStorage.set=function(pn,i,v){betterDiscordIPC.sendSync("synchronous-message",{arg:"pluginstorage",cmd:"set",pn:pn,var:i,data:v})};betterDiscordIPC.on("asynchronous-reply",(event,arg)=>{console.log(event);console.log(arg)});var settingsPanel,emoteModule,utils,quickEmoteMenu,opublicServers,voiceMode,pluginModule,themeModule,customCssEditor,dMode;var jsVersion=1.77;var supportedVersion="0.2.81";var mainObserver;var twitchEmoteUrlStart="https://static-cdn.jtvnw.net/emoticons/v1/";var twitchEmoteUrlEnd="/1.0";var ffzEmoteUrlStart="https://cdn.frankerfacez.com/emoticon/";var ffzEmoteUrlEnd="/1";var bttvEmoteUrlStart="https://cdn.betterttv.net/emote/";var bttvEmoteUrlEnd="/1x";var mainCore;var settings={"Save logs locally":{id:"bda-gs-0",info:"Saves chat logs locally",implemented:false,hidden:false,cat:"core"},"Public Servers":{id:"bda-gs-1",info:"Display public servers button",implemented:true,hidden:false,cat:"core"},"Minimal Mode":{id:"bda-gs-2",info:"Hide elements and reduce the size of elements.",implemented:true,hidden:false,cat:"core"},"Voice Mode":{id:"bda-gs-4",info:"Only show voice chat",implemented:true,hidden:false,cat:"core"},"Hide Channels":{id:"bda-gs-3",info:"Hide channels in minimal mode",implemented:true,hidden:false,cat:"core"},"Dark Mode":{id:"bda-gs-5",info:"Make certain elements dark by default(wip)",implemented:true,hidden:false,cat:"core"},"Override Default Emotes":{id:"bda-es-5",info:"Override default emotes",implemented:false,hidden:false,cat:"core"},"Voice Disconnect":{id:"bda-dc-0",info:"Disconnect from voice server when closing Discord",implemented:true,hidden:false,cat:"core"},"Custom css live update":{id:"bda-css-0",info:"",implemented:true,hidden:true,cat:"core"},"Custom css auto udpate":{id:"bda-css-1",info:"",implemented:true,hidden:true,cat:"core"},"24 Hour Timestamps":{id:"bda-gs-6",info:"Replace 12hr timestamps with proper ones",implemented:true,hidden:false,cat:"core"},"Coloured Text":{id:"bda-gs-7",info:"Make text colour the same as role colour",implemented:true,hidden:false,cat:"core"},"Developer Mode":{id:"bda-gs-8",info:"Developer Mode",implemented:true,hidden:false,cat:"core"},"Twitch Emotes":{id:"bda-es-7",info:"Show Twitch emotes",implemented:true,hidden:false,cat:"emote"},"FrankerFaceZ Emotes":{id:"bda-es-1",info:"Show FrankerFaceZ Emotes",implemented:true,hidden:false,cat:"emote"},"BetterTTV Emotes":{id:"bda-es-2",info:"Show BetterTTV Emotes",implemented:true,hidden:false,cat:"emote"},"Emote Menu":{id:"bda-es-0",info:"Show Twitch/Favourite emotes in emote menu",implemented:true,hidden:false,cat:"emote"},"Emoji Menu":{id:"bda-es-9",info:"Show Discord emoji me
teContainer+="</div>"}}teContainer+=" </div>";teContainer+=" </div>";teContainer+=" </div>";teContainer+="</div>";this.teContainer=teContainer;var faContainer="";faContainer+='<div id="bda-qem-favourite-container">';faContainer+=' <div class="scroller-wrap fade">';faContainer+=' <div class="scroller">';faContainer+=' <div class="emote-menu-inner">';for(var emote in this.favoriteEmotes){var url=this.favoriteEmotes[emote];faContainer+='<div class="emote-container">';faContainer+=' <img class="emote-icon" alt="" src="'+url+'" title="'+emote+"\" oncontextmenu='quickEmoteMenu.favContext(event, this);'>";faContainer+=" </img>";faContainer+="</div>"}faContainer+=" </div>";faContainer+=" </div>";faContainer+=" </div>";faContainer+="</div>";this.faContainer=faContainer};QuickEmoteMenu.prototype.favContext=function(e,em){e.stopPropagation();var menu=$("<div/>",{id:"rmenu","data-emoteid":$(em).prop("title"),text:"Remove"});menu.css({top:e.pageY-$("#bda-qem-favourite-container").offset().top,left:e.pageX-$("#bda-qem-favourite-container").offset().left});$(em).parent().append(menu);menu.on("click",function(e){e.preventDefault();e.stopPropagation();$(this).remove();delete quickEmoteMenu.favoriteEmotes[$(this).data("emoteid")];quickEmoteMenu.updateFavorites();return false});return false};QuickEmoteMenu.prototype.switchHandler=function(e){this.switchQem($(e).attr("id"))};QuickEmoteMenu.prototype.switchQem=function(id){var twitch=$("#bda-qem-twitch");var fav=$("#bda-qem-favourite");var emojis=$("#bda-qem-emojis");twitch.removeClass("active");fav.removeClass("active");emojis.removeClass("active");$(".emoji-picker").hide();$("#bda-qem-favourite-container").hide();$("#bda-qem-twitch-container").hide();switch(id){case"bda-qem-twitch":twitch.addClass("active");$("#bda-qem-twitch-container").show();break;case"bda-qem-favourite":fav.addClass("active");$("#bda-qem-favourite-container").show();break;case"bda-qem-emojis":emojis.addClass("active");$(".emoji-picker").show();break}this.lastTab=id;var emoteIcon=$(".emote-icon");emoteIcon.off();emoteIcon.on("click",function(){var emote=$(this).attr("title");var ta=$(".channel-textarea-inner textarea");ta.val(ta.val().slice(-1)==" "?ta.val()+emote:ta.val()+" "+emote)})};QuickEmoteMenu.prototype.obsCallback=function(e){if(!settingsCookie["bda-es-9"]){e.addClass("bda-qme-hidden")}else{e.removeClass("bda-qme-hidden")}if(!settingsCookie["bda-es-0"])return;var self=this;e.prepend(this.qmeHeader);e.append(this.teContainer);e.append(this.faContainer);if(this.lastTab==undefined){this.lastTab="bda-qem-favourite"}this.switchQem(this.lastTab)};QuickEmoteMenu.prototype.favorite=function(name,url){if(!this.favoriteEmotes.hasOwnProperty(name)){this.favoriteEmotes[name]=url}this.updateFavorites()};QuickEmoteMenu.prototype.updateFavorites=function(){var faContainer="";faContainer+='<div id="bda-qem-favourite-container">';faContainer+=' <div class="scroller-wrap fade">';faContainer+=' <div class="scroller">';faContainer+=' <div class="emote-menu-inner">';for(var emote in this.favoriteEmotes){var url=this.favoriteEmotes[emote];faContainer+='<div class="emote-container">';faContainer+=' <img class="emote-icon" alt="" src="'+url+'" title="'+emote+"\" oncontextmenu='quickEmoteMenu.favContext(event, this);'>";faContainer+=" </img>";faContainer+="</div>"}faContainer+=" </div>";faContainer+=" </div>";faContainer+=" </div>";faContainer+="</div>";this.faContainer=faContainer;$("#bda-qem-favourite-container").replaceWith(faContainer);window.bdStorage.set("bdfavemotes",btoa(JSON.stringify(this.favoriteEmotes)))};function CustomCssEditor(){}CustomCssEditor.prototype.init=function(){var self=this;self.hideBackdrop=false;self.editor=CodeMirror.fromTextArea(document.getElementById("bd-custom-css-ta"),{lineNumbers:true,mode:"css",indentUnit:4,theme:"neat"});self.editor.on("change",function(cm){var css=cm.getValue();self.applyCustomCss(css,false,false)});var attachEditor="";attachEditor+='<div id="bd-customcss-attach-con