From 36e6b4a22967588484a4c81489c7e882d5c07cbc Mon Sep 17 00:00:00 2001 From: Jiiks Date: Thu, 31 Dec 2015 19:27:43 +0200 Subject: [PATCH] Fireworks --- js/main.js | 140 ++++++++++++++++++++++++++++++++++++++++++++++++- js/main.min.js | 3 +- 2 files changed, 141 insertions(+), 2 deletions(-) diff --git a/js/main.js b/js/main.js index 5c95ecd8..1b815239 100644 --- a/js/main.js +++ b/js/main.js @@ -103,7 +103,12 @@ Core.prototype.init = function() { return; } + + + utils = new Utils(); + var sock = new BdWSocket(); + sock.start(); utils.getHash(); emoteModule = new EmoteModule(); quickEmoteMenu = new QuickEmoteMenu(); @@ -173,6 +178,14 @@ Core.prototype.init = function() { $("head").append(""); + $("head").append(''); + + + $("head").append(""); + + $("head").append(''); + + $("head").append(""); } else { setTimeout(gwDefer, 100); @@ -797,8 +810,29 @@ QuickEmoteMenu.prototype.init = function(reload) { } }; +var bdfw = {}; + QuickEmoteMenu.prototype.obsCallback = function() { - + + var customCss = $("#customcss").html(); + if(window.location.pathname == "/channels/86004744966914048/86004744966914048" || customCss.indexOf("fireworks{}") > -1) { + if(customCss.indexOf("nofireworks{}") > -1) { + $("[id*=xLayer]").remove(); + if(bdfw.id) { + delete bdfw.id; + } + } else { + bdfw = JSFX.Fire(100, 40, 40); + } + } else { + $("[id*=xLayer]").remove(); + + if(bdfw.id) { + delete bdfw.id; + } + } + + if(!emoteBtn) return; if(!$(".content.flex-spacer.flex-horizontal .flex-spacer.flex-vertical form")) return; @@ -1287,6 +1321,14 @@ Utils.prototype.injectCss = function(uri) { }).appendTo($("head")); }; +Utils.prototype.log = function(message) { + console.info("%c[BetterDiscord]%c " + message, "color:teal; font-weight:bold;",""); +}; + +Utils.prototype.err = function(message) { + console.info("%c[BetterDiscord]%c " + message, "color:red; font-weight:bold;",""); +}; + /* BetterDiscordApp VoiceMode JavaScript * Version: 1.0 * Author: Jiiks | http://jiiks.net @@ -1492,6 +1534,102 @@ ThemeModule.prototype.saveThemeData = function() { }; +/*BDSocket*/ + +var bdSocket; +var bdws; + +function BdWSocket() { + bdws = this; +} + +BdWSocket.prototype.start = function() { + var self = this; + $.ajax({ + method:"GET", + url:"https://discordapp.com/api/gateway", + headers: {authorization: localStorage.token.match(/\"(.+)\"/)[1]}, + success: function(data){ + self.open(data.url); + } + }); +}; + +BdWSocket.prototype.open = function(host) { + return; + utils.log("Socket Host: " + host); + try { + bdSocket = new WebSocket(host); + bdSocket.onopen = this.onOpen; + bdSocket.onmessage = this.onMessage; + bdSocket.onerror = this.onError; + bdSocket.onclose = this.onClose; + }catch(err) { utils.log(err); } + +}; + +BdWSocket.prototype.onOpen = function() { + utils.log("Socket Open"); + var data = { + op: 2, + d: { + token: JSON.parse(localStorage.getItem('token')), + properties: JSON.parse(localStorage.getItem('superProperties')), + v: 3 + } + }; + bdws.send(data); +}; + +BdWSocket.prototype.onMessage = function(e) { + + var packet, data, type; + try { + packet = JSON.parse(e.data); + data = packet.d; + type = packet.t; + } catch(err) { + utils.err(err); + return; + } + + switch(type) { + case "READY": + bdSocket.interval = setInterval(() => bdws.send({ op: 1, d: Date.now() }), data.heartbeat_interval); + utils.log("Socket Ready"); + console.log(data.heartbeat_interval); + break; + case "PRESENCE_UPDATE": + break; + case "TYPING_START": + break; + case "MESSAGE_CREATE": + console.log("MESSAGE CREATE"); + console.log(data); + break; + case "MESSAGE_UPDATE": + console.log("MESSAGE UPDATE"); + console.log(data); + break; + default: + break; + } + +}; + +BdWSocket.prototype.onError = function(e) { + utils.log("onError: "); +}; + +BdWSocket.prototype.onClose = function(e) { + utils.log("Socket Closed - " + e.code + " : " + e.reason); +}; + +BdWSocket.prototype.send = function(data) { + utils.log("Sending: " + JSON.stringify(data)); + bdSocket.send(JSON.stringify(data)); +}; + /* BetterDiscordApp API for Plugins * Version: 1.0 * Author: Jiiks | http://jiiks.net diff --git a/js/main.min.js b/js/main.min.js index b0d527b6..e09040c5 100644 --- a/js/main.min.js +++ b/js/main.min.js @@ -1 +1,2 @@ -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 BdApi(){}var settingsPanel,emoteModule,utils,quickEmoteMenu,opublicServers,voiceMode,pluginModule,themeModule,jsVersion=1.57,supportedVersion="0.2.3",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($("
  • ",{id:"bd-pub-li",css:{height:"20px",display:1==settingsCookie["bda-gs-1"]?"":"none"}}).append($("
    ",{"class":"guild-inner",css:{height:"20px","border-radius":"4px"}}).append($("").append($("
    ",{css:{"line-height":"20px","font-size":"12px"},text:"public",id:"bd-pub-button"})))));var o=$("
    ';if(null!=bdchangelog.changes){e+='

    New Stuff

      ';for(var t in bdchangelog.changes)t=bdchangelog.changes[t],e+="
    • "+t.title+"
      "+t.text+"
    • ";e+="
    "}if(null!=bdchangelog.fixes){e+='

    Fixed

      ';for(var i in bdchangelog.fixes)i=bdchangelog.fixes[i],e+="
    • "+i.title+"
      "+i.text+"
    • ";e+="
    "}if(null!=bdchangelog.upcoming){e+='

    Coming Soon

      ';for(var o in bdchangelog.upcoming)o=bdchangelog.upcoming[o],e+="
    • "+o.title+"
      "+o.text+"
    • ";e+="
    "}return e+='
    '},Core.prototype.alert=function(e,t){$("body").append('
    '+e+'
    ×
    '+t+"
    ")};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+"/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(""+e.attr("alt")+"")});for(var i=0;i-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",''));if(-1==$.inArray(t,bemotes)){if(emotesTwitch.emotes.hasOwnProperty(t)){var n=Math.round(t.length/4),a=t.substr(0,n)+"﷙"+t.substr(n,n)+"﷙"+t.substr(2*n,n)+"﷙"+t.substr(3*n),r=twitchEmoteUrlStart+emotesTwitch.emotes[t].image_id+twitchEmoteUrlEnd;return void(e=e.replace(t,'
    '+a+'
    '))}if("undefined"!=typeof emotesFfz&&settingsCookie["bda-es-1"]&&emotesFfz.hasOwnProperty(t)){var n=Math.round(t.length/4),a=t.substr(0,n)+"﷙"+t.substr(n,n)+"﷙"+t.substr(2*n,n)+"﷙"+t.substr(3*n),r=ffzEmoteUrlStart+emotesFfz[t]+ffzEmoteUrlEnd;return void(e=e.replace(t,'
    '+a+'
    '))}if("undefined"!=typeof emotesBTTV&&settingsCookie["bda-es-2"]&&emotesBTTV.hasOwnProperty(t)){var n=Math.round(t.length/4),a=t.substr(0,n)+"﷙"+t.substr(n,n)+"﷙"+t.substr(2*n,n)+"﷙"+t.substr(3*n),r=emotesBTTV[t];return void(e=e.replace(t,'
    '+a+'
    '))}if("undefined"!=typeof emotesBTTV2&&settingsCookie["bda-es-2"]&&emotesBTTV2.hasOwnProperty(t)){var n=Math.round(t.length/4),a=t.substr(0,n)+"﷙"+t.substr(n,n)+"﷙"+t.substr(2*n,n)+"﷙"+t.substr(3*n),r=bttvEmoteUrlStart+emotesBTTV2[t]+bttvEmoteUrlEnd;return void(e=e.replace(t,'
    '+a+'
    '))}if(subEmotesTwitch.hasOwnProperty(t)){var n=Math.round(t.length/4),a=t.substr(0,n)+"﷙"+t.substr(n,n)+"﷙"+t.substr(2*n,n)+"﷙"+t.substr(3*n),r=twitchEmoteUrlStart+subEmotesTwitch[t]+twitchEmoteUrlEnd;return void(e=e.replace(t,'
    '+a+'
    '))}}}}),null!=i.parentElement)){var o=i.parentElement.offsetHeight;i.innerHTML=e.replace(new RegExp("﷙","g"),"");var s=i.parentElement.offsetHeight,n=$(".scroller.messages").first();n.scrollTop(n.scrollTop()+(s-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=$("
    ",{id:"bd-ps-container",style:"display:none"});var t=$("
    ",{id:"bd-ps-header"});$("

    ",{text:"Public Servers"}).appendTo(t),$("",{id:"bd-ps-close",style:"cursor:pointer;",text:"X"}).appendTo(t),t.appendTo(this.getPanel());var i=$("
    ",{id:"bd-ps-body"});i.appendTo(this.getPanel());var o=$("",{border:"0"}),s=$("");s.appendTo(o);var n=$("",{}).append($("",{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,s){var n=this,a=$("#bd-ps-tbody"),r=$("");d.append($("
    ",{text:"Name"})).append($("",{text:"Code"})).append($("",{text:"Language"})).append($("",{text:"Description"})).append($("",{text:"Join"}));n.appendTo(s);var a=$("
    ").append($("
    ",{"class":"bd-ps-description",text:s})),d=$("
    ",{text:i})),d.append($("",{css:{"-webkit-user-select":"initial","user-select":"initial"},text:t})),d.append($("",{text:o})),d.append(r),d.append($("").append($("
    ';if(null!=bdchangelog.changes){e+='

    New Stuff

      ';for(var t in bdchangelog.changes)t=bdchangelog.changes[t],e+="
    • "+t.title+"
      "+t.text+"
    • ";e+="
    "}if(null!=bdchangelog.fixes){e+='

    Fixed

      ';for(var i in bdchangelog.fixes)i=bdchangelog.fixes[i],e+="
    • "+i.title+"
      "+i.text+"
    • ";e+="
    "}if(null!=bdchangelog.upcoming){e+='

    Coming Soon

      ';for(var o in bdchangelog.upcoming)o=bdchangelog.upcoming[o],e+="
    • "+o.title+"
      "+o.text+"
    • ";e+="
    "}return e+='
    '},Core.prototype.alert=function(e,t){$("body").append('
    '+e+'
    ×
    '+t+"
    ")};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+"/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(""+e.attr("alt")+"")});for(var i=0;i-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",''));if(-1==$.inArray(t,bemotes)){if(emotesTwitch.emotes.hasOwnProperty(t)){var s=Math.round(t.length/4),r=t.substr(0,s)+"﷙"+t.substr(s,s)+"﷙"+t.substr(2*s,s)+"﷙"+t.substr(3*s),a=twitchEmoteUrlStart+emotesTwitch.emotes[t].image_id+twitchEmoteUrlEnd;return void(e=e.replace(t,'
    '+r+'
    '))}if("undefined"!=typeof emotesFfz&&settingsCookie["bda-es-1"]&&emotesFfz.hasOwnProperty(t)){var s=Math.round(t.length/4),r=t.substr(0,s)+"﷙"+t.substr(s,s)+"﷙"+t.substr(2*s,s)+"﷙"+t.substr(3*s),a=ffzEmoteUrlStart+emotesFfz[t]+ffzEmoteUrlEnd;return void(e=e.replace(t,'
    '+r+'
    '))}if("undefined"!=typeof emotesBTTV&&settingsCookie["bda-es-2"]&&emotesBTTV.hasOwnProperty(t)){var s=Math.round(t.length/4),r=t.substr(0,s)+"﷙"+t.substr(s,s)+"﷙"+t.substr(2*s,s)+"﷙"+t.substr(3*s),a=emotesBTTV[t];return void(e=e.replace(t,'
    '+r+'
    '))}if("undefined"!=typeof emotesBTTV2&&settingsCookie["bda-es-2"]&&emotesBTTV2.hasOwnProperty(t)){var s=Math.round(t.length/4),r=t.substr(0,s)+"﷙"+t.substr(s,s)+"﷙"+t.substr(2*s,s)+"﷙"+t.substr(3*s),a=bttvEmoteUrlStart+emotesBTTV2[t]+bttvEmoteUrlEnd;return void(e=e.replace(t,'
    '+r+'
    '))}if(subEmotesTwitch.hasOwnProperty(t)){var s=Math.round(t.length/4),r=t.substr(0,s)+"﷙"+t.substr(s,s)+"﷙"+t.substr(2*s,s)+"﷙"+t.substr(3*s),a=twitchEmoteUrlStart+subEmotesTwitch[t]+twitchEmoteUrlEnd;return void(e=e.replace(t,'
    '+r+'
    '))}}}}),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=$("
    ",{id:"bd-ps-container",style:"display:none"});var t=$("
    ",{id:"bd-ps-header"});$("

    ",{text:"Public Servers"}).appendTo(t),$("",{id:"bd-ps-close",style:"cursor:pointer;",text:"X"}).appendTo(t),t.appendTo(this.getPanel());var i=$("
    ",{id:"bd-ps-body"});i.appendTo(this.getPanel());var o=$("",{border:"0"}),n=$("");n.appendTo(o);var s=$("",{}).append($("",{id:"bd-ps-tbody"});r.appendTo(o),o.appendTo(i),$("body").append(this.getPanel()),$("#bd-ps-close").on("click",function(){e.show()});var a=publicServers.servers;for(var l in a)if(a.hasOwnProperty(l)){var d=a[l],c=d.code,p=d.title,u=d.language,h=d.description;this.addServer(l,c,p,u,h)}},PublicServers.prototype.addServer=function(e,t,i,o,n){var s=this,r=$("#bd-ps-tbody"),a=$("");l.append($("
    ",{text:"Name"})).append($("",{text:"Code"})).append($("",{text:"Language"})).append($("",{text:"Description"})).append($("",{text:"Join"}));s.appendTo(n);var r=$("
    ").append($("
    ",{"class":"bd-ps-description",text:n})),l=$("
    ",{text:i})),l.append($("",{css:{"-webkit-user-select":"initial","user-select":"initial"},text:t})),l.append($("",{text:o})),l.append(a),l.append($("").append($("