From 4d14cbaccdb0f9312dd469efb131349fef8be55e Mon Sep 17 00:00:00 2001 From: Jiiks Date: Sun, 27 Dec 2015 17:39:10 +0200 Subject: [PATCH] v1.57 --- js/main.js | 138 ++++++++++++++++--------------------------------- js/main.min.js | 4 +- 2 files changed, 45 insertions(+), 97 deletions(-) diff --git a/js/main.js b/js/main.js index a6233688..5c95ecd8 100644 --- a/js/main.js +++ b/js/main.js @@ -8,7 +8,7 @@ var settingsPanel, emoteModule, utils, quickEmoteMenu, opublicServers, voiceMode, pluginModule, themeModule; -var jsVersion = 1.56; +var jsVersion = 1.57; var supportedVersion = "0.2.3"; var mainObserver; @@ -64,66 +64,21 @@ var defaultCookie = { var bdchangelog = { "changes": { - "core": { - "title": "Core 0.2.5", - "text": "Core v0.2.5 has been made more universal. Download the latest from https://betterdiscord.net ).", + "api": { + "title": "Api Functions!", + "text": "New api events!", "img": "" }, - "plugins": { - "title": "Plugin Settings!", - "text": "Plugins can now add their own settings panel!", - "img": "" - }, - "plugins2": { - "title": "Plugins!", - "text": "Combined with Core 0.2.3, you can now write JavaScript plugins for Discord!", - "img": "" - }, - "settingsmenu": { - "title": "Settings Menu!", - "text": "New and improved settings menu!", - "img": "" - }, - "qemotemenu": { - "title": "Quick emote menu!", - "text": "Quick emote menu now closes when you click anywhere else and you can favorite twitch global emotes!", - "img": "" - }, - "csseditor": { - "title": "New CSS Editor!", - "text": "New CSS Editor powered by CodeMirror!", - "img": "" - }, - "minimalmode": { - "title": "Minimal mode makeover!", - "text": "New and improved minimal mode!", + "dec": { + "title": "Decorations&Snow!", + "text": "Decorations and snow have been removed.", "img": "" } }, "fixes": { - "reload": { - "title": "Reload Fix!", - "text": "Fixed an issue that caused Discord to crash on reload!", - "img": "" - }, - "eemotes": { - "title": "Edit Emotes!", - "text": "Edited messages now display emotes properly!", - "img": "" - }, - "femotes": { - "title": "Favorite Emotes!", - "text": "Favorite emotes right click now always works!", - "img": "" - }, - "pservers": { - "title": "Public Servers", - "text": "Public servers have been fixed!", - "img": "" - }, - "other": { - "title": "Bugfixes!", - "text": "Several smaller bugs fixed!", + "emotes": { + "title": "Sub emotes!", + "text": "Discord sub emotes are now replaced by BetterDiscord sub emotes and can be favorited!", "img": "" } }, @@ -141,7 +96,6 @@ var settingsCookie = {}; function Core() {} Core.prototype.init = function() { - var self = this; if(version < supportedVersion) { @@ -216,10 +170,7 @@ Core.prototype.init = function() { settingsCookie["version"] = jsVersion; self.saveSettings(); } - $("head").append(''); - //By http://www.somethinghitme.com - - + $("head").append(""); @@ -266,6 +217,10 @@ Core.prototype.initObserver = function() { if(mutation.target.getAttribute('class').indexOf("titlebar") != -1) { quickEmoteMenu.obsCallback(); voiceMode.obsCallback(); + if(typeof pluginModule !== "undefined") pluginModule.channelSwitch(); + } + if(mutation.target.getAttribute('class').indexOf('scroller messages') != -1) { + if(typeof pluginModule !== "undefined") pluginModule.newMessage(); } } emoteModule.obsCallback(mutation); @@ -410,6 +365,13 @@ EmoteModule.prototype.obsCallback = function(mutation) { var self = this; if(!settingsCookie["bda-es-7"]) return; + + $(".emoji").each(function() { + var t = $(this); + if(t.attr("src").indexOf(".png") != -1) { + t.replaceWith("" + t.attr("alt") + ""); + } + }); for(var i = 0 ; i < mutation.addedNodes.length ; ++i) { var next = mutation.addedNodes.item(i); @@ -448,7 +410,7 @@ EmoteModule.prototype.injectEmote = function(node) { if(!node.parentElement) return; var parent = node.parentElement; - + if(parent.tagName != "SPAN") return; var edited = false; @@ -464,12 +426,12 @@ EmoteModule.prototype.injectEmote = function(node) { if(!$(parent.parentElement).hasClass("markup") && !$(parent.parentElement).hasClass("message-content")) { return; } var parentInnerHTML = parent.innerHTML; + var words = parentInnerHTML.split(/\s+/g); if(!words) return; words.some(function(word) { - if(word.slice(0, 4) == "[!s]" ) { parentInnerHTML = parentInnerHTML.replace("[!s]", ""); @@ -836,37 +798,7 @@ QuickEmoteMenu.prototype.init = function(reload) { }; QuickEmoteMenu.prototype.obsCallback = function() { - - $("#snowcover").remove(); - $("#decor").remove(); - $("#santasled").remove(); - - var customCss = $("#customcss").html(); - - if(window.location.pathname == "/channels/86004744966914048/86004744966914048" || customCss.indexOf("snow") > -1) { - if($("#customcss").html().indexOf("nosnow") == -1) { - $(".scroller.messages").snowfall('clear'); - $(".scroller.messages").snowfall({flakeCount : 100, maxSpeed : 10}); - } - if(customCss.indexOf("nodecor") > -1) { - $("#decor").remove(); - } else { - $("head").append(''); - } - - if(customCss.indexOf("nobottomsnow") > -1) { - $("#snowcover").remove(); - } else { - $("head").append(''); - } - - if(customCss.indexOf("nosantasled") > -1) { - $("#santasled").remove(); - } else { - $("head").append(''); - } - } if(!emoteBtn) return; if(!$(".content.flex-spacer.flex-horizontal .flex-spacer.flex-vertical form")) return; @@ -912,8 +844,6 @@ QuickEmoteMenu.prototype.initEmoteList = function() { emoteMenuBody.append($("
" , { class: "emote-container" }).append($("", { class: "emote-icon", id: emote, alt: "", src: "https://static-cdn.jtvnw.net/emoticons/v1/"+id+"/1.0", title: emote }))); } } - - }; QuickEmoteMenu.prototype.favorite = function(name, url) { @@ -980,6 +910,7 @@ var panel = null; 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"); } SettingsPanel.prototype.init = function() { @@ -1479,6 +1410,25 @@ PluginModule.prototype.savePluginData = function() { $.cookie("bd-plugins", JSON.stringify(pluginCookie), { expires: 365, path: '/' }); }; +PluginModule.prototype.newMessage = function() { + $.each(bdplugins, function() { + if(!pluginCookie[this.plugin.getName()]) return; + if(typeof this.plugin.onMessage === "function") { + this.plugin.onMessage(); + } + }); +}; + +PluginModule.prototype.channelSwitch = function() { + $.each(bdplugins, function() { + if(!pluginCookie[this.plugin.getName()]) return; + if(typeof this.plugin.onSwitch === "function") { + this.plugin.onSwitch(); + } + }); +}; + + /* BetterDiscordApp ThemeModule JavaScript * Version: 1.0 * Author: Jiiks | http://jiiks.net diff --git a/js/main.min.js b/js/main.min.js index 7808fcbd..b0d527b6 100644 --- a/js/main.min.js +++ b/js/main.min.js @@ -1,3 +1 @@ -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")}function Utils(){}function VoiceMode(){}function PluginModule(){}function ThemeModule(){}function BdApi(){}var settingsPanel,emoteModule,utils,quickEmoteMenu,opublicServers,voiceMode,pluginModule,themeModule,jsVersion=1.56,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:{core:{title:"Core 0.2.5",text:"Core v0.2.5 has been made more universal. Download the latest from https://betterdiscord.net ).",img:""},plugins:{title:"Plugin Settings!",text:"Plugins can now add their own settings panel!",img:""},plugins2:{title:"Plugins!",text:"Combined with Core 0.2.3, you can now write JavaScript plugins for Discord!",img:""},settingsmenu:{title:"Settings Menu!",text:"New and improved settings menu!",img:""},qemotemenu:{title:"Quick emote menu!",text:"Quick emote menu now closes when you click anywhere else and you can favorite twitch global emotes!",img:""},csseditor:{title:"New CSS Editor!",text:"New CSS Editor powered by CodeMirror!",img:""},minimalmode:{title:"Minimal mode makeover!",text:"New and improved minimal mode!",img:""}},fixes:{reload:{title:"Reload Fix!",text:"Fixed an issue that caused Discord to crash on reload!",img:""},eemotes:{title:"Edit Emotes!",text:"Edited messages now display emotes properly!",img:""},femotes:{title:"Favorite Emotes!",text:"Favorite emotes right click now always works!",img:""},pservers:{title:"Public Servers",text:"Public servers have been fixed!",img:""},other:{title:"Bugfixes!",text:"Several smaller bugs fixed!",img:""}},upcoming:{ignore:{title:"Ignore User!",text:"Ignore users you don't like!",img:""}}},settingsCookie={};Core.prototype.init=function(){function A(){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($("
  • ",{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 i=$("
    ';if(null!=bdchangelog.changes){A+='

    New Stuff

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

    Fixed

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

    Coming Soon

      ';for(var i in bdchangelog.upcoming)i=bdchangelog.upcoming[i],A+="
    • "+i.title+"
      "+i.text+"
    • ";A+="
    "}return A+='
    '},Core.prototype.alert=function(A,e){$("body").append('
    '+A+'
    ×
    '+e+"
    ")};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(A){bemotes=A.blacklist})},EmoteModule.prototype.obsCallback=function(A){var e=this;if(settingsCookie["bda-es-7"])for(var t=0;t-1)return;return i.addClass("spoiler"),void i.on("click",function(){$(this).removeClass("spoiler"),spoilered.push($(this).attr("data-reactid"))})}if(!(e.length<4)){if("ClauZ"==e)return void(A=A.replace("ClauZ",''));if(-1==$.inArray(e,bemotes)){if(emotesTwitch.emotes.hasOwnProperty(e)){var s=Math.round(e.length/4),n=e.substr(0,s)+"﷙"+e.substr(s,s)+"﷙"+e.substr(2*s,s)+"﷙"+e.substr(3*s),g=twitchEmoteUrlStart+emotesTwitch.emotes[e].image_id+twitchEmoteUrlEnd;return void(A=A.replace(e,'
    '+n+'
    '))}if("undefined"!=typeof emotesFfz&&settingsCookie["bda-es-1"]&&emotesFfz.hasOwnProperty(e)){var s=Math.round(e.length/4),n=e.substr(0,s)+"﷙"+e.substr(s,s)+"﷙"+e.substr(2*s,s)+"﷙"+e.substr(3*s),g=ffzEmoteUrlStart+emotesFfz[e]+ffzEmoteUrlEnd;return void(A=A.replace(e,'
    '+n+'
    '))}if("undefined"!=typeof emotesBTTV&&settingsCookie["bda-es-2"]&&emotesBTTV.hasOwnProperty(e)){var s=Math.round(e.length/4),n=e.substr(0,s)+"﷙"+e.substr(s,s)+"﷙"+e.substr(2*s,s)+"﷙"+e.substr(3*s),g=emotesBTTV[e];return void(A=A.replace(e,'
    '+n+'
    '))}if("undefined"!=typeof emotesBTTV2&&settingsCookie["bda-es-2"]&&emotesBTTV2.hasOwnProperty(e)){var s=Math.round(e.length/4),n=e.substr(0,s)+"﷙"+e.substr(s,s)+"﷙"+e.substr(2*s,s)+"﷙"+e.substr(3*s),g=bttvEmoteUrlStart+emotesBTTV2[e]+bttvEmoteUrlEnd;return void(A=A.replace(e,'
    '+n+'
    '))}if(subEmotesTwitch.hasOwnProperty(e)){var s=Math.round(e.length/4),n=e.substr(0,s)+"﷙"+e.substr(s,s)+"﷙"+e.substr(2*s,s)+"﷙"+e.substr(3*s),g=twitchEmoteUrlStart+subEmotesTwitch[e]+twitchEmoteUrlEnd;return void(A=A.replace(e,'
    '+n+'
    '))}}}}),null!=t.parentElement)){var i=t.parentElement.offsetHeight;t.innerHTML=A.replace(new RegExp("﷙","g"),"");var o=t.parentElement.offsetHeight,s=$(".scroller.messages").first();s.scrollTop(s.scrollTop()+(o-i))}}}if("undefined"!=typeof emotesTwitch&&A.parentElement){var t=A.parentElement;if("SPAN"==t.tagName){var i=!1;$(t.parentElement).hasClass("edited")&&(t=t.parentElement.parentElement.firstChild,i=!0),i?setTimeout(e,250):e()}}},EmoteModule.prototype.autoCapitalize=function(){var A=this;$("body").delegate($(".channel-textarea-inner textarea"),"keyup change paste",function(){if(settingsCookie["bda-es-4"]){var e=$(".channel-textarea-inner textarea").val();if(void 0!=e){var t=e.split(" ").pop();if(t.length>3){if("danSgame"==t)return;var i=A.capitalize(t.toLowerCase());null!==i&&void 0!==i&&$(".channel-textarea-inner textarea").val(e.replace(t,i))}}}})},EmoteModule.prototype.capitalize=function(A){var e=emotesTwitch.emotes;for(var t in e)if(e.hasOwnProperty(t)&&A==(t+"").toLowerCase())return t};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 A=this;this.container=$("
    ",{id:"bd-ps-container",style:"display:none"});var e=$("
    ",{id:"bd-ps-header"});$("

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