/* BetterDiscordApp QuickEmoteMenu JavaScript * Version: 1.3 * Author: Jiiks | http://jiiks.net * Date: 26/08/2015 - 11:49 * Last Update: 29/08/2015 - 11:46 * https://github.com/Jiiks/BetterDiscordApp */ var emoteBtn, emoteMenu; function QuickEmoteMenu() { } QuickEmoteMenu.prototype.init = function(reload) { emoteBtn = null; $(".channel-textarea").first().removeClass("emotemenu-enabled"); if(!emoteMenu) { this.initEmoteList(); } var menuOpen; emoteBtn = $("
", { id:"twitchcord-button-container", style:"display:none" }).append($("", { 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() { menuOpen = !menuOpen; if(menuOpen) { emoteMenu.addClass("emotemenu-open"); $(this).addClass("twitchcord-button-open"); } else { emoteMenu.removeClass(); $(this).removeClass(); } }); if(settingsCookie["bda-es-0"]) { $(".channel-textarea").first().addClass("emotemenu-enabled"); emoteBtn.show(); } 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); }); var fe = localStorage["bdfavemotes"]; if(fe != undefined) { favoriteEmotes = JSON.parse(atob(fe)); this.updateFavorites(); } }; QuickEmoteMenu.prototype.obsCallback = function() { $("#snowcover").remove(); $("#decor").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(!emoteBtn) return; if(!$(".content.flex-spacer.flex-horizontal .flex-spacer.flex-vertical form")) return; var tcbtn = $("#twitchcord-button-container"); if(tcbtn.parent().prop("tagName") == undefined) { quickEmoteMenu = new QuickEmoteMenu(); quickEmoteMenu.init(true); } }; var favoriteEmotes = {}; QuickEmoteMenu.prototype.initEmoteList = function() { emoteMenu = $("", { id: "emote-menu" }); var emoteMenuHeader = $("", { id: "emote-menu-header" }); var emoteMenuBody = $("", { id: "emote-menu-inner" }); var emoteMenuBodyFav = $("", { id: "emote-menu-inner-fav", css: { "display": "none" }}) var globalTab = $("", {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(); }}); var favoriteTab = $("", {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(); }}); emoteMenuHeader.append(globalTab); emoteMenuHeader.append(favoriteTab); emoteMenu.append(emoteMenuHeader); var swrapper = $("", { class: "scroller-wrap" }); var scroller = $("", { class: "scroller"}); swrapper.append(scroller); scroller.append(emoteMenuBody); scroller.append(emoteMenuBodyFav); emoteMenu.append(swrapper); for(var emote in emotesTwitch.emotes) { if(emotesTwitch.emotes.hasOwnProperty(emote)) { var id = emotesTwitch.emotes[emote].image_id; 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) { if(!$("#rmenu").length) { $("body").append(' '); $(document).on("click", function() { $("#rmenu").hide(); }); } if(!favoriteEmotes.hasOwnProperty(name)) { favoriteEmotes[name] = url; } this.updateFavorites(); }; QuickEmoteMenu.prototype.updateFavorites = function() { var self = this; var emoteMenuBody = $("#emote-menu-inner-fav"); emoteMenuBody.empty(); for(var emote in favoriteEmotes) { var url = favoriteEmotes[emote]; var econtainer = $("", { class: "emote-container" }); var icon = $("", { class: "emote-icon", alt: "", src: url, title: emote }).appendTo(econtainer); emoteMenuBody.append(econtainer); icon.off("click").on("click", function(e) { var emote = $(this).attr("title"); var ta = $(".channel-textarea-inner textarea"); ta.val(ta.val().slice(-1) == " " ? ta.val() + emote : ta.val() + " " + emote); }); icon.off("contextmenu").on("contextmenu", function(e) { var title = $(this).attr("title"); var menu = $("#rmenu"); menu.find("a").off("click").on("click",function() { delete favoriteEmotes[title]; self.updateFavorites(); }); menu.hide(); menu.css({top: e.pageY, left: e.pageX}); menu.show(); return false; }); } window.localStorage["bdfavemotes"] = btoa(JSON.stringify(favoriteEmotes)); };