From 3821077eaf07c67a45aefad3513f247ae0dca37e Mon Sep 17 00:00:00 2001 From: Jiiks Date: Sun, 10 Apr 2016 15:43:27 +0300 Subject: [PATCH] Updated separated files --- js/bdapi.js | 69 ++++--- js/core.js | 302 +++++++++++++++++-------------- js/csseditor.js | 99 ++++++++++ js/emotemodule.js | 226 ++++++++++++++--------- js/pluginmodule.js | 96 ++++++++-- js/publicservers.js | 311 +++++++++++++++++++------------- js/quickemotemenu.js | 298 +++++++++++++++--------------- js/settingspanel.js | 419 ++++++++++++++++++++++++------------------- js/socket.js | 106 +++++++++++ js/thememodule.js | 43 ++--- js/utils.js | 45 +++-- js/voicemode.js | 16 +- 12 files changed, 1260 insertions(+), 770 deletions(-) create mode 100644 js/csseditor.js create mode 100644 js/socket.js diff --git a/js/bdapi.js b/js/bdapi.js index dd85970..e769da3 100644 --- a/js/bdapi.js +++ b/js/bdapi.js @@ -12,52 +12,52 @@ function BdApi() {} //Joins a server //code = server invite code -BdApi.joinServer = function(code) { - opublicServers.joinServer(code); +BdApi.joinServer = function (code) { + opublicServers.joinServer(code); }; //Inject CSS to document head //id = id of element //css = custom css -BdApi.injectCSS = function(id, css) { - $("head").append('') +BdApi.injectCSS = function (id, css) { + $("head").append(''); $("#" + id).html(css); }; //Clear css/remove any element //id = id of element -BdApi.clearCSS = function(id) { - $("#"+id).remove(); +BdApi.clearCSS = function (id) { + $("#" + id).remove(); }; //Get another plugin //name = name of plugin -BdApi.getPlugin = function(name) { - if(bdplugins.hasOwnProperty(name)) { +BdApi.getPlugin = function (name) { + if (bdplugins.hasOwnProperty(name)) { return bdplugins[name]["plugin"]; } return null; }; //Get ipc for reason -BdApi.getIpc = function() { - return betterDiscordIPC; +BdApi.getIpc = function () { + return betterDiscordIPC; }; //Get BetterDiscord Core -BdApi.getCore = function() { - return mainCore; +BdApi.getCore = function () { + return mainCore; }; //Attempts to get user id by username //Name = username //Since Discord hides users if there's too many, this will often fail -BdApi.getUserIdByName = function(name) { +BdApi.getUserIdByName = function (name) { var users = $(".member-username"); - - for(var i = 0 ; i < users.length ; i++) { + + for (var i = 0; i < users.length; i++) { var user = $(users[i]); - if(user.text() == name) { + if (user.text() == name) { var avatarUrl = user.closest(".member").find(".avatar-small").css("background-image"); return avatarUrl.match(/\d+/); } @@ -69,15 +69,44 @@ BdApi.getUserIdByName = function(name) { //ID = user id //Since Discord hides users if there's too many, this will often fail var gg; -BdApi.getUserNameById = function(id) { +BdApi.getUserNameById = function (id) { var users = $(".avatar-small"); - - for(var i = 0 ; i < users.length ; i++) { + + for (var i = 0; i < users.length; i++) { var user = $(users[i]); var url = user.css("background-image"); - if(id == url.match(/\d+/)) { + if (id == url.match(/\d+/)) { return user.parent().find(".member-username").text(); } } return null; +}; + +//Set current game +//game = game +BdApi.setPlaying = function (game) { + bdws.send({ + "op": 3, + "d": { + "idle_since": null, + "game": { + "name": game + } + } + }); +}; + +//Set current status +//idle_since = date +//status = status +BdApi.setStatus = function (idle_since, status) { + bdws.send({ + "op": 3, + "d": { + "idle_since": idle_since, + "game": { + "name": status + } + } + }); }; \ No newline at end of file diff --git a/js/core.js b/js/core.js index d2fdc4f..23653b0 100644 --- a/js/core.js +++ b/js/core.js @@ -1,15 +1,13 @@ /* BetterDiscordApp Core JavaScript - * Version: 1.52 + * Version: 1.53 * Author: Jiiks | http://jiiks.net * Date: 27/08/2015 - 16:36 - * Last Update: 24/010/2015 - 17:27 + * Last Update: 02/04/2016 * https://github.com/Jiiks/BetterDiscordApp */ - - -var settingsPanel, emoteModule, utils, quickEmoteMenu, opublicServers, voiceMode, pluginModule, themeModule; -var jsVersion = 1.54; -var supportedVersion = "0.2.3"; +var settingsPanel, emoteModule, utils, quickEmoteMenu, opublicServers, voiceMode, pluginModule, themeModule, customCssEditor; +var jsVersion = 1.63; +var supportedVersion = "0.2.5"; var mainObserver; @@ -23,20 +21,27 @@ var bttvEmoteUrlEnd = "/1x"; var mainCore; var settings = { - "Save logs locally": { "id": "bda-gs-0", "info": "Saves chat logs locally", "implemented": false }, - "Public Servers": { "id": "bda-gs-1", "info": "Display public servers button", "implemented": true }, - "Minimal Mode": { "id": "bda-gs-2", "info": "Hide elements and reduce the size of elements.", "implemented": true }, - "Voice Mode": { "id": "bda-gs-4", "info": "Only show voice chat", "implemented": true }, - "Hide Channels": { "id": "bda-gs-3", "info": "Hide channels in minimal mode", "implemented": true }, - "Quick Emote Menu": { "id": "bda-es-0", "info": "Show quick emote menu for adding emotes", "implemented": true }, - "Show Emotes": { "id": "bda-es-7", "info": "Show any emotes", "implemented": true }, - "FrankerFaceZ Emotes": { "id": "bda-es-1", "info": "Show FrankerFaceZ Emotes", "implemented": true }, - "BetterTTV Emotes": { "id": "bda-es-2", "info": "Show BetterTTV Emotes", "implemented": true }, - "Emote Autocomplete": { "id": "bda-es-3", "info": "Autocomplete emote commands", "implemented": false }, - "Emote Auto Capitalization": { "id": "bda-es-4", "info": "Autocapitalize emote commands", "implemented": true }, - "Override Default Emotes": { "id": "bda-es-5", "info": "Override default emotes", "implemented": false }, - "Show Names": { "id": "bda-es-6", "info": "Show emote names on hover", "implemented": true } -} + "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"}, + + "Show Emotes": { "id": "bda-es-7", "info": "Show any 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 menu", "implemented": true, "hidden": false, "cat": "emote"}, + "Emote Autocomplete": { "id": "bda-es-3", "info": "Autocomplete emote commands", "implemented": false, "hidden": false, "cat": "emote"}, + "Emote Auto Capitalization": { "id": "bda-es-4", "info": "Autocapitalize emote commands", "implemented": true, "hidden": false, "cat": "emote"}, + "Show Names": { "id": "bda-es-6", "info": "Show emote names on hover", "implemented": true, "hidden": false, "cat": "emote"}, + "Show emote modifiers": { "id": "bda-es-8", "info": "Enable emote mods", "implemented": true, "hidden": false, "cat": "emote"}, +}; var links = { "Jiiks.net": { "text": "Jiiks.net", "href": "http://jiiks.net", "target": "_blank" }, @@ -45,92 +50,87 @@ var links = { }; var defaultCookie = { - "version": jsVersion, + "version": jsVersion, "bda-gs-0": false, "bda-gs-1": true, "bda-gs-2": false, "bda-gs-3": false, "bda-gs-4": false, + "bda-gs-5": true, "bda-es-0": true, - "bda-es-1": false, - "bda-es-2": false, + "bda-es-1": true, + "bda-es-2": true, "bda-es-3": false, "bda-es-4": false, "bda-es-5": true, "bda-es-6": true, "bda-es-7": true, - "bda-jd": true + "bda-es-8": true, + "bda-jd": true, + "bda-es-8": true, + "bda-dc-0": false, + "bda-css-0": false, + "bda-css-1": false, + "bda-es-9": true }; var bdchangelog = { "changes": { - "favemotes": { - "title": "Favorite Emotes!", - "text": "You can now favorite emotes and have them listed in the quick emote menu!", + "darkmode": { + "title": "v1.63 : Dark Mode", + "text": "Dark mode makes certain elements dark by default(currently only applies to emote menu)", "img": "" }, - "plugins": { - "title": "Plugins!", - "text": "Combined with Core 0.2.3, you can now write JavaScript plugins for Discord!", + "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!", "img": "" }, - "settingsmenu": { - "title": "Settings Menu!", - "text": "New and improved settings menu!", + "cccss": { + "title": "v1.61 : New custom CSS editor", + "text": "The custom CSS editor now has options and can be detached!", "img": "" }, - "csseditor": { - "title": "New CSS Editor!", - "text": "New CSS Editor powered by CodeMirror!", - "img": "" + "vdc": { + "title": "v1.61 : Voice Disconnect", + "text": "Disconnect from voice server when closing Discord!", + "img": "" }, - "minimalmode": { - "title": "Minimal mode makeover!", - "text": "New and improved minimal mode!", + "pslist": { + "title": "v1.60 : New public server list!", + "text": 'New and shiny public server list powered by DiscordServers.com!', + "img": "" + }, + "api": { + "title": "v1.59 : New plugin api callback", + "text": "Use the `observer(e)` callback instead of creating your own MutationObserver", + "img": "" + }, + "emotemods": { + "title": "v1.59 : New emote mods!", + "text": "The following emote mods have been added: :shake2, :shake3, :flap", + "img": "" + }, + "minmode": { + "title": "v1.59: Minimal mode", + "text": "Minimal mode embed fixed size has been removed", "img": "" } }, "fixes": { - "reload": { - "title": "Reload Fix!", - "text": "Fixed an issue that caused Discord to crash on reload!", - "img": "" + "modal": { + "title": "v1.62 : Fixed modals", + "text": "Fixed broken modal introduced by 0.0.287", + "imt": "" }, - "eemotes": { - "title": "Edit Emotes!", - "text": "Edited messages now display emotes properly!", - "img": "" - }, - "pservers": { - "title": "Public Servers", - "text": "Public servers have been fixed!", + "emotes": { + "title": "v1.59 : Native sub emote mods", + "text": "Emote mods now work with native sub emotes!", "img": "" }, - "other": { - "title": "Bugfixes!", - "text": "Several smaller bugs fixed!", - "img": "" - } - }, - "upcoming": { - "ignore": { - "title": "Ignore User!", - "text": "Ignore users you don't like!", - "img": "" - }, - "themes": { - "title": "Custom themes!", - "text": "Write your own or download custom themes!", - "img": "" - }, - "favemotes": { - "title": "Favorite emotes!", - "text": "Add your favorite emote(s) to the quick emote menu!", - "img": "" - }, - "more": { - "title": "More Things!", - "text": "More things but probably not in the next version!", + "emotes2": { + "title": "v1.59 : Emote mods and custom emotes", + "text": "Emote mods will no longer interfere with custom emotes using :", "img": "" } } @@ -140,16 +140,17 @@ var settingsCookie = {}; function Core() {} -Core.prototype.init = function() { - +Core.prototype.init = function () { var self = this; - if(version < supportedVersion) { - alert("BetterDiscord v" + version + "(your version)" + " is not supported by the latest js("+jsVersion+"). Please download the latest version from betterdiscord.net"); + 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"); return; } utils = new Utils(); + var sock = new BdWSocket(); + sock.start(); utils.getHash(); emoteModule = new EmoteModule(); quickEmoteMenu = new QuickEmoteMenu(); @@ -163,12 +164,10 @@ Core.prototype.init = function() { //Incase were too fast function gwDefer() { console.log(new Date().getTime() + " Defer"); - if($(".guilds-wrapper .guilds").children().length > 0) { + if ($(".guilds-wrapper .guilds").children().length > 0) { console.log(new Date().getTime() + " Defer Loaded"); var guilds = $(".guilds>li:first-child"); - guilds.after($("
  • ", { id: "bd-pub-li", css: { "height": "20px", "display": settingsCookie["bda-gs-1"] == true ? "" : "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 showChannelsButton = $("' + + '
    ' + + '
    ' + + ' What\'s new in BetterDiscord JS' + jsVersion + '' + + ' ' + '
    ' + '
    ' + '
    '; - if(bdchangelog.changes != null) { + if (bdchangelog.changes != null) { changeLog += '' + '

    ' + ' New Stuff' + '

    ' + '
      '; - for(var change in bdchangelog.changes) { + for (var change in bdchangelog.changes) { change = bdchangelog.changes[change]; changeLog += '' + '
    • ' + - ' '+change.title+'' + - '
      '+change.text+'
      ' + + ' ' + change.title + '' + + '
      ' + change.text + '
      ' + '
    • '; } changeLog += '
    '; } - if(bdchangelog.fixes != null) { + if (bdchangelog.fixes != null) { changeLog += '' + '

    ' + ' Fixed' + '

    ' + '
      '; - for(var fix in bdchangelog.fixes) { + for (var fix in bdchangelog.fixes) { fix = bdchangelog.fixes[fix]; changeLog += '' + '
    • ' + - ' '+fix.title+'' + - '
      '+fix.text+'
      ' + + ' ' + fix.title + '' + + '
      ' + fix.text + '
      ' + '
    • '; } changeLog += '
    '; } - if(bdchangelog.upcoming != null) { + if (bdchangelog.upcoming != null) { changeLog += '' + '

    ' + ' Coming Soon' + '

    ' + '