diff --git a/js/main.js b/js/main.js index 5d600a9..c03d82c 100644 --- a/js/main.js +++ b/js/main.js @@ -6,7 +6,7 @@ * https://github.com/Jiiks/BetterDiscordApp */ var settingsPanel, emoteModule, utils, quickEmoteMenu, opublicServers, voiceMode, pluginModule, themeModule, customCssEditor; -var jsVersion = 1.64; +var jsVersion = 1.70; var supportedVersion = "0.2.5"; var mainObserver; @@ -29,8 +29,10 @@ 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"}, "FrankerFaceZ Emotes": { "id": "bda-es-1", "info": "Show FrankerFaceZ Emotes", "implemented": true, "hidden": false, "cat": "emote"}, @@ -39,7 +41,7 @@ var settings = { "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 Names": { "id": "bda-es-6", "info": "Show emote names trueon hover", "implemented": true, "hidden": false, "cat": "emote"}, "Show emote modifiers": { "id": "bda-es-8", "info": "Enable emote mods", "implemented": true, "hidden": false, "cat": "emote"}, }; @@ -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, @@ -77,14 +81,29 @@ var defaultCookie = { var bdchangelog = { "changes": { "028s": { - "title": "v1.64 : 0.2.8 Support", - "text": "Added support for Core version 0.2.8", + "title": "v1.70 : 0.2.8 Support", + "text": "Added support for Core version 0.2.8.", + "img": "" + }, + "importexport": { + "title": "v1.70 : Setting Import/Export", + "text": "You can now import and export your settings!", "img": "" }, "infscroll": { - "title": "v1.64 : Public Server List Infinite Scroll", + "title": "v1.70 : Public Server List Infinite Scroll", "text": "Public server list now has the ability to load more than 20 servers.", "img": "" + }, + "tstamps": { + "title": "v1.70 : 24 hour timestamps", + "text": "Replace 12 hour timestamp with 24 hour timestamps!", + "img": "" + }, + "ctext": { + "title": "v1.70 : Coloured text", + "text": "Make text colour the same as role colour!", + "img": "" } }, "fixes": { @@ -169,6 +188,11 @@ Core.prototype.init = function () { $('.btn.btn-disconnect').click(); } }); + + $(document).on("mousedown", function(e) { + //bd modal hiders + + }); opublicServers.init(); @@ -244,6 +268,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] + 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); }); @@ -341,31 +397,32 @@ Core.prototype.constructChangelog = function () { }; Core.prototype.alert = function (title, text) { - var id = 'bdalert-'; + var id = ''; for( var i=0; i < 5; i++ ) id += "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(Math.random() * "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".length)); var bdAlert = '\ -
\ -
\ -
\ -
\ - BetterDiscord - '+title+'\ + ' + - '
' + - ' BetterDiscord v' + ((typeof(version) == "undefined") ? bdVersion : version) + '(JSv' + jsVersion + ') by Jiiks' + - ' BetterDiscord.net' + - '
' + - '
'; function showSettings() { $(".tab-bar-item").removeClass("selected"); @@ -1670,6 +1790,65 @@ Utils.prototype.err = function (message) { console.info("%c[BetterDiscord]%c " + message, "color:red; font-weight:bold;", ""); }; +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")); + customCssEditor.applyCustomCss(ccss, settingsCookie["bda-css-0"], false); + customCssEditor.editor.setValue(ccss); + }catch(err) { + mainCore.alert("Invalid Data", err); + return false; + } + return false; + }); +}; + +Utils.prototype.exportSettings = function() { + var obj = { + settings: settingsCookie, + customCss: localStorage["bdcustomcss"], + plugins: bdplugins, + 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(); +}; + /* BetterDiscordApp VoiceMode JavaScript * Version: 1.0 * Author: Jiiks | http://jiiks.net