diff --git a/dev/js/01core.js b/dev/js/01core.js index 23653b09..dfb217de 100644 --- a/dev/js/01core.js +++ b/dev/js/01core.js @@ -2,11 +2,11 @@ * Version: 1.53 * Author: Jiiks | http://jiiks.net * Date: 27/08/2015 - 16:36 - * Last Update: 02/04/2016 + * Last Update: 01/05/2016 * https://github.com/Jiiks/BetterDiscordApp */ var settingsPanel, emoteModule, utils, quickEmoteMenu, opublicServers, voiceMode, pluginModule, themeModule, customCssEditor; -var jsVersion = 1.63; +var jsVersion = 1.72; var supportedVersion = "0.2.5"; var mainObserver; @@ -29,10 +29,12 @@ var settings = { "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"}, + "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"}, - "Show Emotes": { "id": "bda-es-7", "info": "Show any emotes", "implemented": true, "hidden": false, "cat": "emote"}, + "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"}, @@ -44,7 +46,7 @@ var settings = { }; var links = { - "Jiiks.net": { "text": "Jiiks.net", "href": "http://jiiks.net", "target": "_blank" }, + "Jiiks.net": { "text": "Jiiks.net", "href": "thtp://jiiks.net", "target": "_blank" }, "twitter": { "text": "Twitter", "href": "http://twitter.com/jiiksi", "target": "_blank" }, "github": { "text": "Github", "href": "http://github.com/jiiks", "target": "_blank" } }; @@ -57,6 +59,8 @@ var defaultCookie = { "bda-gs-3": false, "bda-gs-4": false, "bda-gs-5": true, + "bda-gs-6": false, + "bda-gs-7": false, "bda-es-0": true, "bda-es-1": true, "bda-es-2": true, @@ -76,61 +80,86 @@ var defaultCookie = { var bdchangelog = { "changes": { - "darkmode": { - "title": "v1.63 : Dark Mode", - "text": "Dark mode makes certain elements dark by default(currently only applies to emote menu)", + "a": { + "title": "v1.72 : Public Servers", + "text": "Public servers now have categories, description, tags, dark mode and more!", "img": "" }, - "emotemenu": { - "title": "v1.62 : Brand new emote menu that fits in Discord emoji menu!", - "text": "The emote menu has been replaced by a new one that injects itself in the Discord emoji menu!", + "b": { + "title": "v1.72 : Import/Export", + "text": "Import/Export buttons now disappear in themes/plugins tabs to avoid confusion", "img": "" }, - "cccss": { - "title": "v1.61 : New custom CSS editor", - "text": "The custom CSS editor now has options and can be detached!", + "c": { + "title": "v1.72 : Changelog", + "text": "You can now reopen this changelog from the settings", "img": "" }, - "vdc": { - "title": "v1.61 : Voice Disconnect", - "text": "Disconnect from voice server when closing Discord!", + "d": { + "title": "v1.71 : Hide Twitch emotes", + "text": "Hide all emotes option now toggles Twitch emotes instead!", "img": "" }, - "pslist": { - "title": "v1.60 : New public server list!", - "text": 'New and shiny public server list powered by DiscordServers.com!', + "e": { + "title": "v1.71 : Override FFZ emote", + "text": "Use the :bttv emote modifier to override a FFZ emote with a BTTV one!", "img": "" }, - "api": { - "title": "v1.59 : New plugin api callback", - "text": "Use the `observer(e)` callback instead of creating your own MutationObserver", + "f": { + "title": "v1.70 : 0.2.8 Support", + "text": "Added support for Core version 0.2.8.", "img": "" }, - "emotemods": { - "title": "v1.59 : New emote mods!", - "text": "The following emote mods have been added: :shake2, :shake3, :flap", + "g": { + "title": "v1.70 : Setting Import/Export", + "text": "You can now import and export your settings!", "img": "" }, - "minmode": { - "title": "v1.59: Minimal mode", - "text": "Minimal mode embed fixed size has been removed", + "h": { + "title": "v1.70 : Public Server List Infinite Scroll", + "text": "Public server list now has the ability to load more than 20 servers.", + "img": "" + }, + "i": { + "title": "v1.70 : 24 hour timestamps", + "text": "Replace 12 hour timestamp with 24 hour timestamps!", + "img": "" + }, + "j": { + "title": "v1.70 : Coloured text", + "text": "Make text colour the same as role colour!", "img": "" } }, "fixes": { - "modal": { - "title": "v1.62 : Fixed modals", - "text": "Fixed broken modal introduced by 0.0.287", - "imt": "" - }, - "emotes": { - "title": "v1.59 : Native sub emote mods", - "text": "Emote mods now work with native sub emotes!", + "a": { + "title": "v1.72 : Settings panel", + "text": "Settings panel will now show no matter how you open it!", "img": "" }, - "emotes2": { - "title": "v1.59 : Emote mods and custom emotes", - "text": "Emote mods will no longer interfere with custom emotes using :", + "b": { + "title": "v1.72 : Fixed emote edit bug", + "text": "Edits now appear properly even with emotes!", + "img": "" + }, + "c": { + "title": "v1.72 : Public servers", + "text": "Public servers button is visible again!", + "img": "" + }, + "d": { + "title": "v1.72 : Public servers", + "text": "Updated public servers api endpoint url for fetching correct serverlist.", + "img": "" + }, + "e": { + "title": "v1.71 : Fixed emotes and edit", + "text": "Emotes work again! So does editing emotes!", + "img": "" + }, + "f": { + "title": "Spoilers are currently broken :(", + "text": "Ps. I know this in the fixes section :o", "img": "" } } @@ -143,8 +172,10 @@ function Core() {} Core.prototype.init = function () { var self = this; - if (version < supportedVersion) { - this.alert("Not Supported", "BetterDiscord v" + version + "(your version)" + " is not supported by the latest js(" + jsVersion + ").

Please download the latest version from BetterDiscord.net"); + var lVersion = (typeof(version) === "undefined") ? bdVersion : version; + + if (lVersion < supportedVersion) { + this.alert("Not Supported", "BetterDiscord v" + lVersion + "(your version)" + " is not supported by the latest js(" + jsVersion + ").

Please download the latest version from BetterDiscord.net"); return; } @@ -207,6 +238,11 @@ Core.prototype.init = function () { $('.btn.btn-disconnect').click(); } }); + + $(document).on("mousedown", function(e) { + //bd modal hiders + + }); opublicServers.init(); @@ -264,7 +300,11 @@ Core.prototype.loadSettings = function () { var botlist = ["119598467310944259"]; //Temp Core.prototype.initObserver = function () { mainObserver = new MutationObserver(function (mutations) { + mutations.forEach(function (mutation) { + if(settingsPanel !== undefined) + settingsPanel.inject(mutation); + if($(mutation.target).find(".emoji-picker").length) { var fc = mutation.target.firstChild; if(fc.classList.contains("popout")) { @@ -282,6 +322,38 @@ Core.prototype.initObserver = function () { if (mutation.target.getAttribute('class').indexOf('scroller messages') != -1) { if (typeof pluginModule !== "undefined") pluginModule.newMessage(); } + + if(settingsCookie["bda-gs-6"]) { + $(".timestamp").not("[data-24]").each(function() { + var t = $(this); + t.attr("data-24", true); + var text = t.text(); + var matches = /(.*)?at\s+(\d{1,2}):(\d{1,2})\s+(.*)/.exec(text); + if(matches == null) return true; + if(matches.length < 5) return true; + + var h = parseInt(matches[2]); + if(matches[4] == "AM") { + if(h == 12) h -= 12; + }else if(matches[4] == "PM") { + if(h < 12) h += 12; + } + + matches[2] = ('0' + h).slice(-2); + t.text(matches[1] + " at " + matches[2] + ":" + matches[3]); + }); + } + if(settingsCookie["bda-gs-7"]) { + $(".user-name").not("[data-colour]").each(function() { + var t = $(this); + var color = t.css("color"); + if(color == "rgb(255, 255, 255)") return true; + t.closest(".message-group").find(".markup").not("[data-colour]").each(function() { + $(this).attr("data-colour", true); + $(this).css("color", color); + }); + }); + } } emoteModule.obsCallback(mutation); }); @@ -379,16 +451,30 @@ Core.prototype.constructChangelog = function () { }; Core.prototype.alert = function (title, text) { - $("body").append('' + - '
' + - '
' + - ' ' + title + '' + - '
×
' + - '
' + - '
' + - '
' + - '
' + text + '
' + - '
' + - '
' + - '
'); + var id = ''; + for( var i=0; i < 5; i++ ) + id += "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(Math.random() * "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".length)); + var bdAlert = '\ + \ + '; + $("body").append(bdAlert); + utils.addBackdrop(id); }; \ No newline at end of file diff --git a/dev/js/02emoteModule.js b/dev/js/02emoteModule.js index f5724e33..6c345631 100644 --- a/dev/js/02emoteModule.js +++ b/dev/js/02emoteModule.js @@ -37,26 +37,12 @@ EmoteModule.prototype.getBlacklist = function () { EmoteModule.prototype.obsCallback = function (mutation) { var self = this; - if (!settingsCookie["bda-es-7"]) return; + //if (!settingsCookie["bda-es-7"]) return; - $(".emoji").each(function () { + $(".emoji").each(function() { var t = $(this); - if (t.attr("src").indexOf(".png") != -1) { - - var next = t.next(); - var newText = t.attr("alt"); - if(next.size() > 0) { - if(next.prop("tagName") == "SPAN") { - newText += next.text(); - next.remove(); - } - } - - if(t.parent().prop("tagName") != "SPAN") { - t.replaceWith("" + newText + ""); - } else { - t.replaceWith(newText); - } + if(t.attr("src").indexOf(".png") != -1) { + t.replaceWith(t.attr("alt")); } }); @@ -66,7 +52,12 @@ EmoteModule.prototype.obsCallback = function (mutation) { var nodes = self.getNodes(next); for (var node in nodes) { if (nodes.hasOwnProperty(node)) { - self.injectEmote(nodes[node]); + var elem = nodes[node].parentElement; + if (elem && elem.classList.contains('edited')) { + self.injectEmote(elem); + } else { + self.injectEmote(nodes[node]); + } } } } @@ -82,162 +73,167 @@ EmoteModule.prototype.getNodes = function (node) { while (next = treeWalker.nextNode()) { nodes.push(next); } - return nodes; }; var bemotes = []; var spoilered = []; -EmoteModule.prototype.injectEmote = function (node) { - if (typeof emotesTwitch === 'undefined') return; +EmoteModule.prototype.injectEmote = function(node) { + var self = this; if (!node.parentElement) return; + var parent = $(node).parent(); + + if(!parent.hasClass("markup") && !parent.hasClass("message-content")) return; - var parent = node.parentElement; - - if (parent.tagName != "SPAN") return; - if (!$(parent.parentElement).hasClass("markup") && !$(parent.parentElement).hasClass("message-content")) { - return; - } - - var edited = false; - - if ($(parent.parentElement).hasClass("edited")) { - parent = parent.parentElement.parentElement.firstChild; - edited = true; - } function inject() { - var parentInnerHTML = parent.innerHTML; - var words = parentInnerHTML.split(/\s+/g); + var contents = parent.contents(); + + contents.each(function(i) { + if(contents[i] == undefined) return; + var nodeValue = contents[i].nodeValue; + if(nodeValue == null) return; + //if(nodeValue.indexOf("react-") > -1) return; + if(contents[i].nodeType == 8) return; + contents.splice(i, 1); - if (!words) return; + var words = nodeValue.split(/([^\s]+)([\s]|$)/g).filter(function(e){ return e}); + + var splice = 0; - words.some(function (word) { - if (word.slice(0, 4) == "[!s]") { + var doInject = false; + var text = null; - parentInnerHTML = parentInnerHTML.replace("[!s]", ""); - var markup = $(parent).parent(); - var reactId = markup.attr("data-reactid"); - - if (spoilered.indexOf(reactId) > -1) { - return; + words.forEach(function(w, index, a) { + + if(w.indexOf("[!s]") > -1) { + w = w.replace("[!s]", ""); + parent.data("spoilered", false); + parent.addClass("spoiler"); } - - markup.addClass("spoiler"); - markup.on("click", function () { - $(this).removeClass("spoiler"); - spoilered.push($(this).attr("data-reactid")); - }); - - return; - } - - if (word.length < 4) { - return; - } - - if (word == "ClauZ") { - parentInnerHTML = parentInnerHTML.replace("ClauZ", ''); - return; - } - - var useEmoteCss = false; - var sWord = word; - var emoteClass = ""; - var allowedClasses = ["emoteflip", "emotespin", "emotepulse", "emotespin2", "emotespin3", "emote1spin", "emote2spin", "emote3spin", "emotetr", "emotebl", "emotebr", "emoteshake", "emoteshake2", "emoteshake3", "emoteflap"]; - if(word.indexOf(":") > -1) { - var split = word.split(/:(?!.*:)/); - if (split[0] != "" && split[1] != "") { - userEmoteCss = true; - sWord = split[0]; - if(settingsCookie["bda-es-8"]) { - emoteClass = "emote" + split[1]; - if(allowedClasses.indexOf(emoteClass) < 0) { - emoteClass = ""; + + var allowedClasses = ["flip", "spin", "pulse", "spin2", "spin3", "1spin", "2spin", "3spin", "tr", "bl", "br", "shake", "shake2", "shake3", "flap"]; + var useEmoteClass = false; + var emoteClass = ""; + var skipffz = false; + + var sw = w; + + if(w.indexOf(":") > -1) { + var split = w.split(":"); + if(split[0] != "" && split[1] != "") { + if(allowedClasses.indexOf(split[1]) > -1) { + sw = split[0]; + emoteClass = settingsCookie["bda-es-8"] ? "emote" + split[1] : ""; + } + if(split[1] == "bttv") { + sw = split[0]; + skipffz = true; } } } - } - if ($.inArray(sWord, bemotes) != -1) return; - - if (emotesTwitch.emotes.hasOwnProperty(sWord)) { - var len = Math.round(sWord.length / 4); - var name = sWord.substr(0, len) + "\uFDD9" + sWord.substr(len, len) + "\uFDD9" + sWord.substr(len * 2, len) + "\uFDD9" + sWord.substr(len * 3); - var url = twitchEmoteUrlStart + emotesTwitch.emotes[sWord].image_id + twitchEmoteUrlEnd; - parentInnerHTML = parentInnerHTML.replace(word, '
' + name + '
'); - return; - } - - if (subEmotesTwitch.hasOwnProperty(sWord)) { - var len = Math.round(sWord.length / 4); - var name = sWord.substr(0, len) + "\uFDD9" + sWord.substr(len, len) + "\uFDD9" + sWord.substr(len * 2, len) + "\uFDD9" + sWord.substr(len * 3); - var url = twitchEmoteUrlStart + subEmotesTwitch[sWord] + twitchEmoteUrlEnd; - parentInnerHTML = parentInnerHTML.replace(word, '
' + name + '
'); - return; - } - - if (typeof emotesFfz !== 'undefined' && settingsCookie["bda-es-1"]) { - if (emotesFfz.hasOwnProperty(sWord)) { - var len = Math.round(sWord.length / 4); - var name = sWord.substr(0, len) + "\uFDD9" + sWord.substr(len, len) + "\uFDD9" + sWord.substr(len * 2, len) + "\uFDD9" + sWord.substr(len * 3); - var url = ffzEmoteUrlStart + emotesFfz[sWord] + ffzEmoteUrlEnd; - parentInnerHTML = parentInnerHTML.replace(word, '
' + name + '
'); - return; + + if ($.inArray(sw, bemotes) != -1) return; + + if(typeof emotesTwitch !== 'undefind' && settingsCookie["bda-es-7"]) { + if(emotesTwitch.emotes.hasOwnProperty(sw) && sw.length >= 4) { + if(text != null) { contents.splice(i + splice++, 0, document.createTextNode(text)); text = null;} + var url = twitchEmoteUrlStart + emotesTwitch.emotes[sw].image_id + twitchEmoteUrlEnd; + contents.splice(i + splice++, 0, self.createEmoteElement(sw, url, emoteClass)); + doInject = true; + return; + } } - } - - if (typeof emotesBTTV !== 'undefined' && settingsCookie["bda-es-2"]) { - if (emotesBTTV.hasOwnProperty(sWord)) { - var len = Math.round(sWord.length / 4); - var name = sWord.substr(0, len) + "\uFDD9" + sWord.substr(len, len) + "\uFDD9" + sWord.substr(len * 2, len) + "\uFDD9" + sWord.substr(len * 3); - var url = emotesBTTV[sWord]; - parentInnerHTML = parentInnerHTML.replace(word, '
' + name + '
'); - return; + + if(typeof subEmotesTwitch !== 'undefined' && settingsCookie["bda-es-7"]) { + if(subEmotesTwitch.hasOwnProperty(sw) && sw.length >= 4) { + if(text != null) { contents.splice(i + splice++, 0, document.createTextNode(text)); text = null;} + var url = twitchEmoteUrlStart + subEmotesTwitch[sw] + twitchEmoteUrlEnd; + contents.splice(i + splice++, 0, self.createEmoteElement(sw, url, emoteClass)); + doInject = true; + return; + } } - } - - if (typeof emotesBTTV2 !== 'undefined' && settingsCookie["bda-es-2"]) { - if (emotesBTTV2.hasOwnProperty(sWord)) { - var len = Math.round(sWord.length / 4); - var name = sWord.substr(0, len) + "\uFDD9" + sWord.substr(len, len) + "\uFDD9" + sWord.substr(len * 2, len) + "\uFDD9" + sWord.substr(len * 3); - var url = bttvEmoteUrlStart + emotesBTTV2[sWord] + bttvEmoteUrlEnd; - parentInnerHTML = parentInnerHTML.replace(word, '
' + name + '
'); - return; + + if (typeof emotesBTTV !== 'undefined' && settingsCookie["bda-es-2"]) { + if(emotesBTTV.hasOwnProperty(sw) && sw.length >= 4) { + if(text != null) { contents.splice(i + splice++, 0, document.createTextNode(text)); text = null;} + var url = emotesBTTV[sw]; + contents.splice(i + splice++, 0, self.createEmoteElement(sw, url, emoteClass)); + doInject = true; + return; + } } + + if ((typeof emotesFfz !== 'undefined' && settingsCookie["bda-es-1"]) && (!skipffz || !emotesBTTV2.hasOwnProperty(sw))) { + if(emotesFfz.hasOwnProperty(sw) && sw.length >= 4) { + if(text != null) { contents.splice(i + splice++, 0, document.createTextNode(text)); text = null;} + var url = ffzEmoteUrlStart + emotesFfz[sw] + ffzEmoteUrlEnd; + contents.splice(i + splice++, 0, self.createEmoteElement(sw, url, emoteClass)); + doInject = true; + return; + } + } + + if (typeof emotesBTTV2 !== 'undefined' && settingsCookie["bda-es-2"]) { + if(emotesBTTV2.hasOwnProperty(sw) && sw.length >= 4) { + if(text != null) { contents.splice(i + splice++, 0, document.createTextNode(text)); text = null;} + var url = bttvEmoteUrlStart + emotesBTTV2[sw] + bttvEmoteUrlEnd; + if(skipffz && emotesFfz.hasOwnProperty(sw)) sw = sw + ":bttv"; + contents.splice(i + splice++, 0, self.createEmoteElement(sw, url, emoteClass)); + doInject = true; + return; + } + } + + if(text == null) { + text = w; + } else { + text += "" + w; + } + + if(index === a.length - 1) { + contents.splice(i + splice, 0, document.createTextNode(text)); + } + }); + + if(doInject) { + var oldHeight = parent.outerHeight(); + parent.html(contents); + var scrollPane = $(".scroller.messages").first(); + scrollPane.scrollTop(scrollPane.scrollTop() + (parent.outerHeight() - oldHeight)); } }); - - if (parent.parentElement == null) return; - - var oldHeight = parent.parentElement.offsetHeight; - parent.innerHTML = parentInnerHTML.replace(new RegExp("\uFDD9", "g"), ""); - var newHeight = parent.parentElement.offsetHeight; - - var scrollPane = $(".scroller.messages").first(); - scrollPane.scrollTop(scrollPane.scrollTop() + (newHeight - oldHeight)); - } - - if (edited) { + + inject(); + if(parent.children().hasClass("edited")) { setTimeout(inject, 250); - } else { - inject(); } + + + +}; + +EmoteModule.prototype.createEmoteElement = function(word, url, mod) { + var len = Math.round(word.length / 4); + var name = word.substr(0, len) + "\uFDD9" + word.substr(len, len) + "\uFDD9" + word.substr(len * 2, len) + "\uFDD9" + word.substr(len * 3); + var html = '' + name + ''; + return $.parseHTML(html.replace(new RegExp("\uFDD9", "g"), ""))[0]; }; EmoteModule.prototype.autoCapitalize = function () { var self = this; - $('body').delegate($(".channel-textarea-inner textarea"), 'keyup change paste', function () { + $('body').delegate($(".channel-textarea-inner textarea:first"), 'keyup change paste', function () { if (!settingsCookie["bda-es-4"]) return; - var text = $(".channel-textarea-inner textarea").val(); - + var text = $(".channel-textarea-inner textarea:first").val(); if (text == undefined) return; var lastWord = text.split(" ").pop(); @@ -245,7 +241,7 @@ EmoteModule.prototype.autoCapitalize = function () { if (lastWord == "danSgame") return; var ret = self.capitalize(lastWord.toLowerCase()); if (ret !== null && ret !== undefined) { - $(".channel-textarea-inner textarea").val(text.replace(lastWord, ret)); + $(".channel-textarea-inner textarea:first").val(text.replace(lastWord, ret)); } } }); diff --git a/dev/js/03publicServers.js b/dev/js/03publicServers.js index 1eef4824..8698539a 100644 --- a/dev/js/03publicServers.js +++ b/dev/js/03publicServers.js @@ -14,11 +14,15 @@ PublicServers.prototype.getPanel = function () { }; PublicServers.prototype.init = function () { + this.filtered = ["134680912691462144", "86004744966914048"]; + this.bdServer = null; + this.loadingServers = false; var self = this; - var guilds = $(".guilds>li:first-child"); + var guilds = $(".guilds>:first-child"); - guilds.after($("
  • ", { + guilds.after($("
    ", { + class: "guild", id: "bd-pub-li", css: { "height": "20px", @@ -43,27 +47,76 @@ PublicServers.prototype.init = function () { self.show(); }); - var panelBase=""; - panelBase += "
    "; - panelBase += "
    "; - panelBase += " <\/span><\/span><\/span><\/span>"; - panelBase += " <\/div>"; - panelBase += "
    "; - panelBase += "

    Public Servers<\/h2>"; - panelBase += " \ + \ +
    \ + \ +
    \ +
      \ +
    • All
    • \ +
    • FPS Games
    • \ +
    • MMO Games
    • \ +
    • MOBA Games
    • \ +
    • Strategy Games
    • \ +
    • Sports Games
    • \ +
    • Puzzle Games
    • \ +
    • Retro Games
    • \ +
    • Party Games
    • \ +
    • Tabletop Games
    • \ +
    • Sandbox Games
    • \ +
    • Community
    • \ +
    • Language
    • \ +
    • Programming
    • \ +
    • Other
    • \ +
    • Simulation Games
    • \ +
    \ +
    \ +
    \ +

    \ + \ +
    \ +
    \ +
    \ +
    \ + \ +
    \ +
    \ +
    \ + '; + this.container = panelBase; if($("#bd-pub-li").length < 1) { @@ -73,42 +126,111 @@ PublicServers.prototype.init = function () { } }; - -PublicServers.prototype.show = function () { +PublicServers.prototype.getPinnedServer = function() { var self = this; - $("body").append(this.getPanel()); - var dataset = { - "sort": [{ - "online": "desc" - }], - "from": 0, - "size": 20, + "sort": [{"online": "desc"}], + "size": 1, "query": { - "filtered": { - "query": { - "match_all": {} - } + "query_string": { + "default_operator": "AND", + "query": "BetterDiscord" } } }; - - $("#sbtn").on("click", function() { - self.search(); - }); - $("#sterm").on("keyup", function(e) { - if (e.keyCode == 13) { - self.search(); + + $.ajax({ + type: "POST", + dataType: "json", + url: "https://search-discordservers-izrtub5nprzrl76ugyy6hdooe4.us-west-1.es.amazonaws.com/discord_servers/_search", + crossDomain: true, + data: JSON.stringify(dataset), + success: function(data) { + try { + var s = data.hits.hits[0]._source; + if(s.identifier == "86004744966914048") { + self.bdServer = s; + self.showPinnedServer(); + } + }catch(err) { + self.bdServer = null; + } } }); +}; + +PublicServers.prototype.hidePinnedServer = function() { + $("#pubs-container .scroller-wrap").css({"margin-top": "0", "height": "500px"}); + $(".server-pinned").hide(); +}; + +PublicServers.prototype.showPinnedServer = function() { + $(".server-pinned .server-icon").css("background-image", "url("+this.bdServer.icon+")"); + $(".server-pinned .server-members span").text(this.bdServer.online + "/"+this.bdServer.members+" Members"); + $(".server-pinned .server-region span").text(this.bdServer.region); + $(".server-pinned .server-info button").data("server-invite-code", this.bdServer.invite_code); + $("#pubs-container .scroller-wrap").css({"margin-top": "75px", "height": "425px"}); + $(".server-pinned").show(); +}; + +PublicServers.prototype.show = function () { + var self = this; + this.hidePinnedServer(); + $("#pubs-cat-select").text("All"); + this.selectedCategory = "all"; + $("#pubs-container .scroller-wrap").css({"margin-top": "0", "height": "500px"}); + $(".server-pinned").hide(); + + $(".app").append(this.getPanel()); + + if(this.bdServer == null) { + this.getPinnedServer(); + } else { + this.showPinnedServer(); + } + + self.search(0, true); + + $("#pubs-searchbtn").off("click").on("click", function() { + self.search(); + }); + $("#pubs-sterm").off("keyup").on("keyup", function(e) { + if (e.keyCode == 13) { + self.search(0, true); + } + }); + $("#pubs-cat-select").off("click").on("click", function() { + $("#pubs-select-dropdown").addClass("open"); + }); + $(".pubs-cat-select-li").off("click").on("click", function() { + $("#pubs-select-dropdown").removeClass("open"); + $("#pubs-cat-select").text($(this).text()); + if(self.selectedCategory != $(this).data("val")) { + self.selectedCategory = $(this).data("val"); + self.search(0, true); + } + }); + $("#pubs-container").off("mouseup").on("mouseup", function() { + $("#pubs-select-dropdown").removeClass("open"); + }); - this.loadServers(dataset, false); var self = this; $(document).on("mouseup.bdps",function(e) { if(!$("#bd-pub-button").is(e.target) && !$("#pubs-container").is(e.target) && $("#pubs-container").has(e.target).length === 0) { self.hide(); } }); + + $("#pubs-scroller").off("scroll.pubs").on("scroll.pubs", function() { + if(self.loadingServers) return; + var list = $("#pubs-list"); + if($(this).scrollTop() + 550 < list.height()) return; + if(list.children().length % 20 != 0) return; + + self.loadingServers = true; + $("#pubs-spinner-bottom").show(); + self.search(list.children().length, false); + }); }; PublicServers.prototype.hide = function() { @@ -116,32 +238,51 @@ PublicServers.prototype.hide = function() { $(document).off("mouseup.bdps"); }; -PublicServers.prototype.loadServers = function(dataset, search) { + +PublicServers.prototype.loadServers = function(dataset, search, clear) { + this.loadingServers = true; var self = this; - $("#sbtn").prop("disabled", true); - $("#sterm").prop("disabled", true); - $("#slist").empty(); + $("#pubs-searchbtn").prop("disabled", true); + $("#pubs-sterm").prop("disabled", true); + if(clear) $("#pubs-list").empty(); $("#pubs-spinner").show(); $.ajax({ type: "POST", dataType: "json", - url: "https://search-discordservers-izrtub5nprzrl76ugyy6hdooe4.us-west-1.es.amazonaws.com/app/_search", + url: "https://search-discordservers-izrtub5nprzrl76ugyy6hdooe4.us-west-1.es.amazonaws.com/discord_servers/_search", crossDomain: true, data: JSON.stringify(dataset), success: function(data) { var hits = data.hits.hits; + if(search) { $("#pubs-header-title").text("Public Servers - Search Results: " + hits.length); } else { $("#pubs-header-title").text("Public Servers"); } + hits.forEach(function(hit) { var source = hit._source; - var icode = source.invite_code; + var icode = source.invite_code.replace(/ /g,''); var html = '
    '; html += '
    '; html += '
    '; - html += '' + source.name + ' by ' + source.owner.name + ''; + html += '
    '; + + if(source.is_official) { + html += 'Official!'; + } + + html += '' + source.name + ''; + + var tags = []; + source.categories.forEach(function(tag) { + tags.push(tag.name); + }); + + html += ''+tags.join(", ")+''; + html += ''+(source.description == undefined ? "No Description" : source.description)+''; + html += '
    '; html += '
    '; html += '
    '; html += '' + source.online + '/' + source.members + ' Members'; @@ -153,67 +294,79 @@ PublicServers.prototype.loadServers = function(dataset, search) { html += ''; html += '
    '; html += '
    '; - $("#slist").append(html); + $("#pubs-list").append(html); $("button[data-server-invite-code="+icode+"]").on("click", function(){ self.joinServer(icode); }); }); + + if(search) { + $("#pubs-header-title").text("Public Servers - Search Results: " + $("#pubs-list").children().length); + } }, done: function() { $("#pubs-spinner").hide(); - $("#sbtn").prop("disabled", false); - $("#sterm").prop("disabled", false); + $("#pubs-spinner-bottom").hide(); + $("#pubs-searchbtn").prop("disabled", false); + $("#pubs-sterm").prop("disabled", false); + self.loadingServers = false; }, always: function() { $("#pubs-spinner").hide(); - $("#sbtn").prop("disabled", false); - $("#sterm").prop("disabled", false); + $("#pubs-spinner-bottom").hide(); + $("#pubs-searchbtn").prop("disabled", false); + $("#pubs-sterm").prop("disabled", false); + self.loadingServers = false; }, error: function() { $("#pubs-spinner").hide(); - $("#sbtn").prop("disabled", false); - $("#sterm").prop("disabled", false); + $("#pubs-spinner-bottom").hide(); + $("#pubs-searchbtn").prop("disabled", false); + $("#pubs-sterm").prop("disabled", false); + self.loadingServers = false; }, complete: function() { $("#pubs-spinner").hide(); - $("#sbtn").prop("disabled", false); - $("#sterm").prop("disabled", false); + $("#pubs-spinner-bottom").hide(); + $("#pubs-searchbtn").prop("disabled", false); + $("#pubs-sterm").prop("disabled", false); + self.loadingServers = false; } }); }; -PublicServers.prototype.search = function() { +PublicServers.prototype.search = function(start, clear) { + var sterm = $("#pubs-sterm").val(); + var dataset = { - "sort": [{ - "online": "desc" - }], - "from": 0, + "sort": [{ "online": "desc" }], + "from": start, "size": 20, "query": { "filtered": { "query": { - "match_all": {} + "query_string": { + "default_operator": "AND", + "query": sterm ? sterm : "*" + } + }, + "filter": { + "bool": { + "must_not": [{ + "terms": { + "identifier": this.filtered + } + }] + } } } } }; - - var filter = { - "filter": { - "and": [{ - "query": { - "match_phrase_prefix": { - "name": $("#sterm").val() - } - } - }] - } - }; - - if ($("#sterm").val()) { - $.extend(dataset, filter); + if(this.selectedCategory != "all") { + dataset.query.filtered.filter.bool.must = [{ "term": { "categories.id": this.selectedCategory } }] } - this.loadServers(dataset, true); + + this.loadServers(dataset, true, clear); }; //Workaround for joining a server diff --git a/dev/js/04quickEmoteMenu.js b/dev/js/04quickEmoteMenu.js index 88e4b1ab..402f5bcc 100644 --- a/dev/js/04quickEmoteMenu.js +++ b/dev/js/04quickEmoteMenu.js @@ -80,7 +80,7 @@ QuickEmoteMenu.prototype.favContext = function(e, em) { e.preventDefault(); e.stopPropagation(); $(this).remove(); - console.log($(this).data("emoteid")); + delete quickEmoteMenu.favoriteEmotes[$(this).data("emoteid")]; quickEmoteMenu.updateFavorites(); return false; diff --git a/dev/js/06settingsPanel.js b/dev/js/06settingsPanel.js index 49d62b8e..2216886f 100644 --- a/dev/js/06settingsPanel.js +++ b/dev/js/06settingsPanel.js @@ -53,8 +53,8 @@ SettingsPanel.prototype.init = function () { var title = $(this).attr("alt"); $(emoteNamePopup).find(".tipsy-inner").text(title); $(emoteNamePopup).css('left', x.left - 25); - $(emoteNamePopup).css('top', x.top - 32); - $("div[data-reactid='.0.1.1']").append($(emoteNamePopup)); + $(emoteNamePopup).css('top', x.top - 37); + $(".app").append($(emoteNamePopup)); }); $(document).on("mouseleave", ".emote", function () { $(".tipsy").remove(); @@ -81,13 +81,27 @@ SettingsPanel.prototype.changeTab = function (tab) { switch (tab) { case "bd-settings-tab": + $(".bda-slist-top").show(); + break; + case "bd-emotes-tab": + $(".bda-slist-top").show(); break; case "bd-customcss-tab": + $(".bda-slist-top").show(); if (!customCssInitialized) { customCssEditor.init(); customCssInitialized = true; } break; + case "bd-themes-tab": + $(".bda-slist-top:first").hide(); + break; + case "bd-plugins-tab": + $(".bda-slist-top:first").hide(); + break; + default: + $(".bda-slist-top").show(); + break; } }; @@ -107,6 +121,10 @@ SettingsPanel.prototype.updateSetting = function (checkbox) { settingsCookie[id] = enabled; + this.updateSettings(); +}; + +SettingsPanel.prototype.updateSettings = function() { if (settingsCookie["bda-es-0"]) { $("#twitchcord-button-container").show(); } else { @@ -169,154 +187,214 @@ SettingsPanel.prototype.construct = function () { } }); - var settingsInner = '' + - '
    ' + - '
    ' + - '
    ' + - '
    Core
    ' + - '
    Emotes
    ' + - '
    Custom CSS
    ' + - '
    Plugins
    ' + - '
    Themes
    ' + - '
    ' + - '
    ' + - ' \ + '; + //End core settings + //Emote settings - settingsInner += '\ + '; + //End emote settings + //Custom CSS Editor var ccss = atob(localStorage.getItem("bdcustomcss")); customCssEditor.applyCustomCss(ccss, true, false); - settingsInner += '' + - ' ' + - '' + - ' ' + - ' \ + '; + //End plugin pane - if (typeof (themesupport2) === "undefined") { - settingsInner += '' + - ' Your version does not support themes. Download the latest version.'; + //Theme pane + + settingsInner += '\ + \ + '; + + //End theme panel + + //Footer + + settingsInner += '\ +
    \ + BetterDiscord v' + ((typeof(version) == "undefined") ? bdVersion : version) + '(JSv' + jsVersion + ') by Jiiks\ + BetterDiscord.net\ + changelog\ +
    \ +
    \ + '; - settingsInner += '' + - '
    ' + - '' + - '
    ' + - '
    ' + - '
    ' + - ' BetterDiscord v' + version + '(JSv' + jsVersion + ') by Jiiks' + - ' BetterDiscord.net' + - '
    ' + - ''; function showSettings() { $(".tab-bar-item").removeClass("selected"); @@ -338,35 +416,25 @@ SettingsPanel.prototype.construct = function () { }); panel.html(settingsInner); + this.panel = panel; +}; - function defer() { - if ($(".btn.btn-settings").length < 1) { - setTimeout(defer, 100); - } else { - $(".btn.btn-settings").first().on("click", function () { +SettingsPanel.prototype.inject = function(mutation) { + if(mutation.type != "childList") return; + if(mutation.addedNodes.length <= 0) return; + if($(mutation.addedNodes[0]).find(".user-settings-modal").length <= 0) return; - function innerDefer() { - if ($(".modal-inner").first().is(":visible")) { + var self = this; + this.panel.hide(); + var tabBar = $(".tab-bar.SIDE").first(); - panel.hide(); - var tabBar = $(".tab-bar.SIDE").first(); + $(".tab-bar.SIDE .tab-bar-item").click(function () { + $(".form .settings-right .settings-inner").first().show(); + $("#bd-settings-new").removeClass("selected"); + self.panel.hide(); + }); - $(".tab-bar.SIDE .tab-bar-item").click(function () { - $(".form .settings-right .settings-inner").first().show(); - $("#bd-settings-new").removeClass("selected"); - panel.hide(); - }); - - tabBar.append(settingsButton); - $(".form .settings-right .settings-inner").last().after(panel); - $("#bd-settings-new").removeClass("selected"); - } else { - setTimeout(innerDefer, 100); - } - } - innerDefer(); - }); - } - } - defer(); + tabBar.append(settingsButton); + $(".form .settings-right .settings-inner").last().after(self.panel); + $("#bd-settings-new").removeClass("selected"); }; \ No newline at end of file diff --git a/dev/js/07utils.js b/dev/js/07utils.js index 2a40688f..c8d8374e 100644 --- a/dev/js/07utils.js +++ b/dev/js/07utils.js @@ -59,9 +59,117 @@ Utils.prototype.injectCss = function (uri) { }; Utils.prototype.log = function (message) { - console.info("%c[BetterDiscord]%c " + message, "color:teal; font-weight:bold;", ""); + console.log('%c[%cBetterDiscord%c] %c'+message+'', 'color: red;', 'color: #303030; font-weight:700;', 'color:red;', ''); }; Utils.prototype.err = function (message) { - console.info("%c[BetterDiscord]%c " + message, "color:red; font-weight:bold;", ""); + console.log('%c[%cBetterDiscord%c] %c'+message+'', 'color: red;', 'color: red; font-weight:700;', 'color:red;', ''); +}; + +Utils.prototype.importSettings = function() { + mainCore.alert("Import Settings", '
    '); + $("#bda-import-settings").off("click").on("click", function() { + var obj; + try { + obj = JSON.parse($("#bda-import-textarea").val()); + }catch(err) { + mainCore.alert("Invalid Data", err); + return false; + } + try { + for(key in obj.settings) { + var val = obj.settings[key]; + if(settingsCookie.hasOwnProperty(key)) { + settingsCookie[key] = val; + var cb = $("#" + key); + cb.prop("checked", val); + settingsPanel.updateSettings(); + } + } + localStorage["bdcustomcss"] = obj.customCss; + var ccss = atob(localStorage.getItem("bdcustomcss")); + if (!customCssInitialized) { + customCssEditor.init(); + customCssInitialized = true; + } + customCssEditor.applyCustomCss(ccss, settingsCookie["bda-css-0"], false); + customCssEditor.editor.setValue(ccss); + }catch(err) { + mainCore.alert("Invalid Data", err); + return false; + } + + try { + $.each(obj.plugins, function(plugin) { + var enabled = obj.plugins[plugin]; + if(bdplugins.hasOwnProperty(plugin)) { + pluginCookie[plugin] = enabled; + var cb = $("#"+plugin.replace(" ", "__")); + if(cb.is(":checked") && !enabled) { + bdplugins[plugin]["plugin"].stop(); + cb.prop("checked", false); + } + if(!cb.is(":checked") && enabled) { + bdplugins[plugin]["plugin"].start(); + cb.prop("checked", true); + } + } + }); + pluginModule.savePluginData(); + }catch(err) { + mainCore.alert("Failed to load plugin data", err); + return false; + } + + try { + themeCookie = obj.themes; + $.each(themeCookie, function(theme) { + var enabled = themeCookie[theme]; + var id = "#ti" + theme; + if(bdthemes.hasOwnProperty(theme)) { + if($(id).is(":checked") && !enabled) { + $(id).prop("checked", false); + $("#"+theme).remove(); + } + if(!$(id).is(":checked") && enabled) { + $(id).prop("checked", true); + $("head").append(''); + } + } + }); + themeModule.saveThemeData(); + }catch(err) { + mainCore.alert("Failed to load theme data", err); + return false; + } + + return false; + }); +}; + +Utils.prototype.exportSettings = function() { + var obj = { + settings: settingsCookie, + customCss: localStorage["bdcustomcss"], + plugins: pluginCookie, + themes: themeCookie, + favEmotes: window.localStorage["bdfavemotes"] + }; + mainCore.alert("Export Settings", '
    '); +}; + +Utils.prototype.addBackdrop = function(target) { + var backDrop = $("
    ", { + class: "bda-backdrop", + "data-bdbackdrop": target, + mouseup: function() { + $('[data-bdalert="'+target+'"]').remove(); + $(this).remove(); + } + }); + $("#app-mount").append(backDrop) +}; + +Utils.prototype.removeBackdrop = function(target) { + $('[data-bdbackdrop="'+target+'"]').remove(); }; \ No newline at end of file diff --git a/dev/js/09pluginModule.js b/dev/js/09pluginModule.js index 11119abe..47402607 100644 --- a/dev/js/09pluginModule.js +++ b/dev/js/09pluginModule.js @@ -38,7 +38,7 @@ PluginModule.prototype.handlePlugin = function (checkbox) { var cb = $(checkbox).children().find('input[type="checkbox"]'); var enabled = !cb.is(":checked"); - var id = cb.attr("id"); + var id = cb.attr("id").replace("__", " "); cb.prop("checked", enabled); if (enabled) { diff --git a/dev/js/10themeModule.js b/dev/js/10themeModule.js index 12f33a5f..a7c16293 100644 --- a/dev/js/10themeModule.js +++ b/dev/js/10themeModule.js @@ -61,4 +61,4 @@ ThemeModule.prototype.saveThemeData = function () { expires: 365, path: '/' }); -}; +}; \ No newline at end of file