From c65b760ca1a7fbf831193b6041c4881ea8cf062a Mon Sep 17 00:00:00 2001 From: Zerthox Date: Mon, 19 Dec 2016 19:18:31 +0100 Subject: [PATCH 01/40] Add Spooky, Spaghetti, Rucksack, Rein --- data/emotefilter.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/data/emotefilter.json b/data/emotefilter.json index 4579819..f026108 100644 --- a/data/emotefilter.json +++ b/data/emotefilter.json @@ -184,6 +184,10 @@ "Affe", "Baby", "YOUTUBE", - "Bella" + "Bella", + "Spooky", + "Spaghetti", + "Rucksack", + "Rein" ] } From b4bc6ff1093d9ae1d64ff490459e719a7ac439a1 Mon Sep 17 00:00:00 2001 From: Zerthox Date: Sat, 31 Dec 2016 20:24:44 +0100 Subject: [PATCH 02/40] Add Dirk --- data/emotefilter.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/data/emotefilter.json b/data/emotefilter.json index f026108..60d94c6 100644 --- a/data/emotefilter.json +++ b/data/emotefilter.json @@ -188,6 +188,7 @@ "Spooky", "Spaghetti", "Rucksack", - "Rein" + "Rein", + "Dirk" ] } From 6e1816d97337aaa5dfd15e305f9d053f6f12ce70 Mon Sep 17 00:00:00 2001 From: Jiiks Date: Mon, 9 Jan 2017 07:41:36 +0200 Subject: [PATCH 03/40] Alternate storage fix --- js/main.js | 90 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 35 deletions(-) diff --git a/js/main.js b/js/main.js index d585c0f..ba66d9a 100644 --- a/js/main.js +++ b/js/main.js @@ -6,8 +6,29 @@ * Last Update: 01/05/2016 * https://github.com/Jiiks/BetterDiscordApp */ + +window.bdStorage = {}; +window.bdStorage.get = function(i) { + return betterDiscordIPC.sendSync('synchronous-message', { 'arg': 'storage', 'cmd': 'get', 'var': i }); +}; +window.bdStorage.set = function(i, v) { + betterDiscordIPC.sendSync('synchronous-message', { 'arg': 'storage', 'cmd': 'set', 'var': i, 'data': v }); +}; +window.bdPluginStorage = {}; +window.bdPluginStorage.get = function(pn, i) { + return betterDiscordIPC.sendSync('synchronous-message', { 'arg': 'pluginstorage', 'cmd': 'get', 'pn': pn, 'var': i }); +}; +window.bdPluginStorage.set = function(pn, i, v) { + betterDiscordIPC.sendSync('synchronous-message', { 'arg': 'pluginstorage', 'cmd': 'set', 'pn': pn, 'var': i, 'data': v }); +}; + +betterDiscordIPC.on('asynchronous-reply', (event, arg) => { + console.log(event); + console.log(arg); +}); + var settingsPanel, emoteModule, utils, quickEmoteMenu, opublicServers, voiceMode, pluginModule, themeModule, customCssEditor, dMode; -var jsVersion = 1.74; +var jsVersion = 1.75; var supportedVersion = "0.2.5"; var mainObserver; @@ -997,7 +1018,7 @@ PublicServers.prototype.loadServers = function(dataset, search, clear) { // if(source.invite_code === undefined) return; // var icode = source.invite_code.replace(/ /g,''); // icode = self.escape(icode).replace(/[^A-z0-9]/g,''); - var icode = source.identifier; + var icode = source.identifier; var html = '
'; html += '
'; html += '
'; @@ -1100,27 +1121,27 @@ PublicServers.prototype.search = function(start, clear) { };*/ var dataset = { - "sort": [{ "online": "desc" }], - "from": start, - "size": 20, - "query": { - "bool": { - "must": [ - {"query_string": { - "default_operator": "AND", - "query": sterm ? sterm : "*" - }} - ], - "must_not": [ - {"terms": { "identifier": this.filtered }} - ] - } - } + "sort": [{ "online": "desc" }], + "from": start, + "size": 20, + "query": { + "bool": { + "must": [ + {"query_string": { + "default_operator": "AND", + "query": sterm ? sterm : "*" + }} + ], + "must_not": [ + {"terms": { "identifier": this.filtered }} + ] + } + } }; if(this.selectedCategory != "all") { - dataset.query.bool.must.push({ "match_phrase": { "categories": this.selectedCategory } }); + dataset.query.bool.must.push({ "match_phrase": { "categories": this.selectedCategory } }); } this.loadServers(dataset, true, clear); @@ -1128,8 +1149,8 @@ PublicServers.prototype.search = function(start, clear) { //Workaround for joining a server PublicServers.prototype.joinServer = function (code) { - require('electron').shell.openExternal("https://www.discordservers.com/join/" + code); - this.hide(); + require('electron').shell.openExternal("https://www.discordservers.com/join/" + code); + this.hide(); }; PublicServers.prototype.joinServerDirect = function(code) { @@ -1141,7 +1162,7 @@ PublicServers.prototype.joinServerDirect = function(code) { }; PublicServers.prototype.escape = function(unsafe) { - if(unsafe === undefined) return ""; + if(unsafe === undefined) return ""; return unsafe .replace(/&/g, "&") @@ -1168,7 +1189,7 @@ QuickEmoteMenu.prototype.init = function() { if(e.target.id != "rmenu") $("#rmenu").remove(); }); this.favoriteEmotes = {}; - var fe = localStorage["bdfavemotes"]; + var fe = bdStorage.get("bdfavemotes"); if (fe != undefined) { this.favoriteEmotes = JSON.parse(atob(fe)); } @@ -1332,8 +1353,7 @@ QuickEmoteMenu.prototype.updateFavorites = function () { this.faContainer = faContainer; $("#bda-qem-favourite-container").replaceWith(faContainer); - - window.localStorage["bdfavemotes"] = btoa(JSON.stringify(this.favoriteEmotes)); + window.bdStorage.set("bdfavemotes", btoa(JSON.stringify(this.favoriteEmotes))); }; function CustomCssEditor() { } @@ -1364,7 +1384,7 @@ attachEditor += " <\/li>"; attachEditor += "
  • "; attachEditor += "
    "; attachEditor += "
    <\/span><\/div>"; -attachEditor += " Autosave<\/span>"; +attachEditor += " TEMPDISABLED<\/span>"; attachEditor += " <\/div>"; attachEditor += " <\/li>"; attachEditor += "
  • "; @@ -1430,8 +1450,8 @@ CustomCssEditor.prototype.applyCustomCss = function (css, forceupdate, forcesave $("#customcss").html(css); } - if(forcesave || settingsCookie["bda-css-1"]) { - localStorage.setItem("bdcustomcss", btoa(css)); + if(forcesave) { + window.bdStorage.set("bdcustomcss", btoa(css)); } }; /* BetterDiscordApp Settings Panel JavaScript @@ -1725,7 +1745,7 @@ SettingsPanel.prototype.construct = function () { //End emote settings //Custom CSS Editor - var ccss = atob(localStorage.getItem("bdcustomcss")); + var ccss = atob(window.bdStorage.get("bdcustomcss")); customCssEditor.applyCustomCss(ccss, true, false); settingsInner += '\ @@ -1977,8 +1997,8 @@ Utils.prototype.importSettings = function() { settingsPanel.updateSettings(); } } - localStorage["bdcustomcss"] = obj.customCss; - var ccss = atob(localStorage.getItem("bdcustomcss")); + window.bdStorage.set("bdcustomcss", obj.customCss); + var ccss = window.bdStorage.get("bdcustomcss"); if (!customCssInitialized) { customCssEditor.init(); customCssInitialized = true; @@ -2041,10 +2061,10 @@ Utils.prototype.importSettings = function() { Utils.prototype.exportSettings = function() { var obj = { settings: settingsCookie, - customCss: localStorage["bdcustomcss"], + customCss: window.bdStorage.get("bdcustomcss"), plugins: pluginCookie, themes: themeCookie, - favEmotes: window.localStorage["bdfavemotes"] + favEmotes: window.bdStorage.get("bdfavemotes") }; mainCore.alert("Export Settings", '
    '); }; @@ -2329,8 +2349,8 @@ BdWSocket.prototype.onOpen = function () { var data = { op: 2, d: { - token: JSON.parse(localStorage.getItem('token')), - properties: JSON.parse(localStorage.getItem('superProperties')), + token: JSON.parse(window.bdStorage.get('token')), + properties: JSON.parse(window.bdStorage.get('superProperties')), v: 3 } }; From 186d6c9bc58eb9f6cd23983b552994abfd6e2164 Mon Sep 17 00:00:00 2001 From: Jiiks Date: Mon, 9 Jan 2017 07:42:14 +0200 Subject: [PATCH 04/40] Alternate storage lib fix --- lib/BetterDiscord.js | 108 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 99 insertions(+), 9 deletions(-) diff --git a/lib/BetterDiscord.js b/lib/BetterDiscord.js index 0ff0c81..6a1b957 100644 --- a/lib/BetterDiscord.js +++ b/lib/BetterDiscord.js @@ -22,6 +22,53 @@ var _mainWindow; var _cfg = {}; var _extData = {}; +var bdStorage = {}; +var bdPluginStorage = {}; + +bdStorage.defaults = { + data: {} +}; + +bdPluginStorage.defaults = { + data: {} +}; + +function initStorage() { + if(!_fs.existsSync(_cfg.dataPath + "/bdstorage.json")) { + bdStorage.data = bdStorage.defaults.data; + _fs.writeFileSync(_cfg.dataPath + "/bdstorage.json", JSON.stringify(bdStorage, null, 4)); + } else { + bdStorage.data = JSON.parse(_fs.readFileSync(_cfg.dataPath + "/bdStorage.json")); + } + if(!_fs.existsSync(_cfg.dataPath + "/bdPluginStorage.json")) { + bdPluginStorage.data = bdPluginStorage.defaults.data; + _fs.writeFileSync(_cfg.dataPath + "/bdPluginStorage.json", JSON.stringify(bdPluginStorage, null, 4)); + } else { + bdPluginStorage.data = JSON.parse(_fs.readFileSync(_cfg.dataPath + "/bdPluginStorage.json")); + } +}; + + +bdStorage.get = function(i, m, pn) { + if(m) return bdStorage.data[i] || ""; + if(bdPluginStorage.data[pn] === undefined) bdPluginStorage.data[pn] = {}; + return bdPluginStorage.data[pn][i] || ""; +}; + +bdStorage.set = function(i, v, m, pn) { + if(m) { + bdStorage.data[i] = v; + _fs.writeFileSync(_cfg.dataPath + "/bdstorage.json", JSON.stringify(bdStorage.data, null, 4)); + } else { + if(bdPluginStorage.data[pn] === undefined) bdPluginStorage.data[pn] = {}; + bdPluginStorage.data[pn][i] = v; + _fs.writeFileSync(_cfg.dataPath + "/bdPluginStorage.json", JSON.stringify(bdPluginStorage.data, null, 4)); + } + return true; +}; + + + function BetterDiscord(mainWindow) { _mainWindow = mainWindow; _cfg = _config.cfg; @@ -86,6 +133,7 @@ function init() { getUtils().attempt(getHash, 3, 0, "Failed to load hash", initUpdater, function() { exit("Failed to load hash after 3 attempts"); }); + initStorage(); } function getHash(callback) { @@ -94,11 +142,11 @@ function getHash(callback) { _cfg.hash = JSON.parse(data).sha; getUtils().injectVar("_bdhash", _cfg.hash); }catch(err) { - callback(false); + callback(false, err); return; } if(_cfg.hash == undefined) { - callback(false); + callback(false, "_cfg.hash == undefined"); return; } @@ -111,7 +159,7 @@ function getHash(callback) { function initUpdater() { getUtils().log("Getting updater"); getUtils().attempt(getUpdater, 3, 0, "Failed to load updater", waitForDom, function() { - exit("Failed to load updater after 3 attempts"); + exit("Failed to load updater after 3 attempts."); }); } @@ -120,17 +168,22 @@ function getUpdater(callback) { try { _cfg.updater = JSON.parse(data); } catch(err) { - callback(false); + callback(false, err); return; } if(_cfg.updater == undefined) { - callback(false); + callback(false, "_cfg.updater == undefined"); return; } - if(_cfg.updater.LatestVersion == undefined || _cfg.updater.CDN == undefined) { - callback(false); + if(_cfg.updater.LatestVersion == undefined) { + callback(false, "_cfg.updater.LatestVersion == undefined"); + return; + } + + if(_cfg.updater.CDN == undefined) { + callback(false, "_cfg.updater.CDN == undefined"); return; } @@ -170,7 +223,7 @@ function updateExtData() { 'resource': 'Main JS', 'domain': _cfg.updater.CDN, 'url': '//' + _cfg.updater.CDN + '/' + _cfg.repo + '/BetterDiscordApp/' + _cfg.hash + '/js/main.min.js', - 'localurl': _cfg.localServer + '/BetterDiscordApp/js/main.js', + 'localurl': _cfg.localServer + '/BetterDiscordApp/js/main.js?v=1.1', 'message': 'load-emoteData-twitchGlobal', 'cacheable': false, 'variable': null @@ -357,6 +410,7 @@ function load(reload) { } getUtils().log("Hooking ipc async"); _bdIpc.on('asynchronous-message', function(event, arg) { ipcAsyncMessage(event, arg); }); + _bdIpc.on('synchronous-message', function(event, arg) { ipcSyncMessage(event, arg); }); getUtils().log("Hooked ipc async"); } initLoaders(); @@ -511,8 +565,32 @@ function loadApp() { getUtils().injectJavaScriptSync("//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js", "load-jQueryCookie"); } -function ipcAsyncMessage(event, arg) { +function ipcSyncMessage(event, arg) { + if(typeof(arg) === "object") { + switch(arg.arg) { + case "storage": + if(arg.cmd == "get") { + event.returnValue = bdStorage.get(arg.var, true); + } + if(arg.cmd == "set") { + bdStorage.set(arg.var, arg.data, true); + event.returnValue = "saved"; + } + break; + case "pluginstorage": + if(arg.cmd == "get") { + event.returnValue = bdStorage.get(arg.var, false, arg.pn); + } + if(arg.cmd == "set") { + bdStorage.set(arg.var, arg.data, false, arg.pn); + event.returnValue = "saved"; + } + break; + } + } +} +function ipcAsyncMessage(event, arg) { if(typeof(arg) === "object") { switch(arg.arg) { case "opendir": @@ -530,6 +608,18 @@ function ipcAsyncMessage(event, arg) { } getUtils().openDir(arg.path); break; + case "storage": + if(arg.cmd == "set") { + bdStorage.set(arg.var, arg.data); + break; + } + if(arg.cmd == "get") { + var get = bdStorage.get(arg.var); + console.log(get); + event.sender.send('asynchronous-reply', get); + break; + } + break; } return; } From 5784e45e8776521d373a11c297da5f0d77e5258e Mon Sep 17 00:00:00 2001 From: Jiiks Date: Mon, 9 Jan 2017 07:46:58 +0200 Subject: [PATCH 05/40] Updated emote blacklist to use the new storage --- Plugins/emoteBlacklist.plugin.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Plugins/emoteBlacklist.plugin.js b/Plugins/emoteBlacklist.plugin.js index c5f3c44..a695332 100644 --- a/Plugins/emoteBlacklist.plugin.js +++ b/Plugins/emoteBlacklist.plugin.js @@ -9,7 +9,7 @@ emoteBlacklist.prototype.onSwitch = function () { emoteBlacklist.prototype.start = function () { window.ebEnabled = true; var self = this; - var em = localStorage["emoteBlacklist"]; + var em = bdPluginStorage.get("emoteBlacklist", "blacklist"); if(em == undefined) return; JSON.parse(em).forEach(function(emote) { self.remove(emote); @@ -35,7 +35,7 @@ emoteBlacklist.prototype.stop = function () { }; emoteBlacklist.prototype.clear = function() { var self = this; - var em = localStorage["emoteBlacklist"]; + var em = bdPluginStorage.get("emoteBlacklist", "blacklist"); if(em == undefined) return; var em = JSON.parse(em); em.forEach(function(emote) { @@ -43,7 +43,7 @@ emoteBlacklist.prototype.clear = function() { }); }; emoteBlacklist.prototype.getSettingsPanel = function () { - var em = localStorage["emoteBlacklist"]; + var em = bdPluginStorage.get("emoteBlacklist", "blacklist"); var html = ''; html += '

    Emote Blacklist'; @@ -64,7 +64,7 @@ emoteBlacklist.prototype.save = function() { $("#emoteBlistTa").val().split("\n").forEach(function(item) { blist.push(item); }); - localStorage["emoteBlacklist"] = JSON.stringify(blist); + bdPluginStorage.set("emoteBlacklist", "blacklist", blist); if(window.ebEnabled) { this.start(); } From b7851955b2ea683540865bac86def7cda003201e Mon Sep 17 00:00:00 2001 From: Jiiks Date: Mon, 9 Jan 2017 08:15:00 +0200 Subject: [PATCH 06/40] Updated to use individual storage files for plugins --- lib/BetterDiscord.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/BetterDiscord.js b/lib/BetterDiscord.js index 6a1b957..8f17bac 100644 --- a/lib/BetterDiscord.js +++ b/lib/BetterDiscord.js @@ -40,19 +40,21 @@ function initStorage() { } else { bdStorage.data = JSON.parse(_fs.readFileSync(_cfg.dataPath + "/bdStorage.json")); } - if(!_fs.existsSync(_cfg.dataPath + "/bdPluginStorage.json")) { - bdPluginStorage.data = bdPluginStorage.defaults.data; - _fs.writeFileSync(_cfg.dataPath + "/bdPluginStorage.json", JSON.stringify(bdPluginStorage, null, 4)); - } else { - bdPluginStorage.data = JSON.parse(_fs.readFileSync(_cfg.dataPath + "/bdPluginStorage.json")); - } }; bdStorage.get = function(i, m, pn) { if(m) return bdStorage.data[i] || ""; - if(bdPluginStorage.data[pn] === undefined) bdPluginStorage.data[pn] = {}; - return bdPluginStorage.data[pn][i] || ""; + + if(bdPluginStorage[pn] !== undefined) { + return bdPluginStorage[pn][i] || undefined; + } + + if(_fs.existsSync(_cfg.dataPath + "/plugins/" + pn + ".config.json")) { + bdPluginStorage[pn] = JSON.parse(_fs.readFileSync(_cfg.dataPath + "/plugins/" + pn + ".config.json")); + return bdPluginStorage[pn][i] || undefined; + } + }; bdStorage.set = function(i, v, m, pn) { @@ -60,9 +62,9 @@ bdStorage.set = function(i, v, m, pn) { bdStorage.data[i] = v; _fs.writeFileSync(_cfg.dataPath + "/bdstorage.json", JSON.stringify(bdStorage.data, null, 4)); } else { - if(bdPluginStorage.data[pn] === undefined) bdPluginStorage.data[pn] = {}; - bdPluginStorage.data[pn][i] = v; - _fs.writeFileSync(_cfg.dataPath + "/bdPluginStorage.json", JSON.stringify(bdPluginStorage.data, null, 4)); + if(bdPluginStorage[pn] === undefined) bdPluginStorage[pn] = {}; + bdPluginStorage[pn][i] = v; + _fs.writeFileSync(_cfg.dataPath + "/plugins/" + pn + ".config.json", JSON.stringify(bdPluginStorage[pn], null, 4)); } return true; }; From ba56f3bf6e4e75865cca4222d56a88026ff4f087 Mon Sep 17 00:00:00 2001 From: Jiiks Date: Mon, 9 Jan 2017 08:29:18 +0200 Subject: [PATCH 07/40] Updated to comply with the new storage spec --- Plugins/emoteBlacklist.plugin.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Plugins/emoteBlacklist.plugin.js b/Plugins/emoteBlacklist.plugin.js index a695332..9dd5133 100644 --- a/Plugins/emoteBlacklist.plugin.js +++ b/Plugins/emoteBlacklist.plugin.js @@ -10,8 +10,9 @@ emoteBlacklist.prototype.start = function () { window.ebEnabled = true; var self = this; var em = bdPluginStorage.get("emoteBlacklist", "blacklist"); - if(em == undefined) return; - JSON.parse(em).forEach(function(emote) { + + if(em === null) return; + em.forEach(function(emote) { self.remove(emote); self.add(emote); }); @@ -36,8 +37,7 @@ emoteBlacklist.prototype.stop = function () { emoteBlacklist.prototype.clear = function() { var self = this; var em = bdPluginStorage.get("emoteBlacklist", "blacklist"); - if(em == undefined) return; - var em = JSON.parse(em); + if(em === null) return; em.forEach(function(emote) { self.remove(emote); }); @@ -48,8 +48,8 @@ emoteBlacklist.prototype.getSettingsPanel = function () { var html = ''; html += '

    Emote Blacklist'; html += '

  • ';settingsInner+='
      ';$.each(bdplugins,function(){var plugin=this["plugin"];var hasSettings=false;if(typeof(plugin.getSettingsPanel)=="function"){hasSettings=plugin.getSettingsPanel()!=null&&plugin.getSettingsPanel()!="";} +settingsInner+='
    ';var ccss=atob(window.bdStorage.get("bdcustomcss"));customCssEditor.applyCustomCss(ccss,true,false);settingsInner+=' ';settingsInner+='
      ';$.each(bdplugins,function(){var plugin=this["plugin"];var hasSettings=false;if(typeof(plugin.getSettingsPanel)=="function"){hasSettings=plugin.getSettingsPanel()!=null&&plugin.getSettingsPanel()!="";} settingsInner+='
    • '+plugin.getName()+' v'+plugin.getVersion()+' by '+plugin.getAuthor()+'
      '+plugin.getDescription()+'
    • ';});settingsInner+='
    ';settingsInner+=' ';settingsInner+='
    BetterDiscord v'+((typeof(version)=="undefined")?bdVersion:version)+'(JSv'+jsVersion+') by Jiiks BetterDiscord.net changelog
    ';function showSettings(){$(".tab-bar-item").removeClass("selected");settingsButton.addClass("selected");$(".form .settings-right .settings-inner").first().hide();panel.show();if(lastTab==""){self.changeTab("bd-settings-tab");}else{self.changeTab(lastTab);}} settingsButton=$("
    ",{class:"tab-bar-item",text:"BetterDiscord",id:"bd-settings-new",click:showSettings});panel.html(settingsInner);this.panel=panel;};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;var self=this;this.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();});tabBar.append(settingsButton);$(".form .settings-right .settings-inner").last().after(self.panel);$("#bd-settings-new").removeClass("selected");};var _hash;function Utils(){} Utils.prototype.getTextArea=function(){return $(".channel-textarea-inner textarea");};Utils.prototype.jqDefer=function(fnc){if(window.jQuery){fnc();}else{setTimeout(function(){this.jqDefer(fnc);},100);}};Utils.prototype.getHash=function(){$.getJSON("https://api.github.com/repos/Jiiks/BetterDiscordApp/commits/master",function(data){_hash=data.sha;emoteModule.getBlacklist();});};Utils.prototype.loadHtml=function(html,callback){var container=$("
    ",{class:"bd-container"}).appendTo("body");html='//cdn.rawgit.com/Jiiks/BetterDiscordApp/'+_hash+'/html/'+html+'.html';container.load(html,callback());};Utils.prototype.injectJs=function(uri){$("