From 8bb79cacadbd7b2fb52035c9b94d5ff8267abc0a Mon Sep 17 00:00:00 2001 From: Mirco Wittrien Date: Sun, 25 Oct 2020 17:25:53 +0100 Subject: [PATCH] stuff --- Plugins/BDFDB.js | 41 ----------------------------------------- Plugins/BDFDB.min.js | 18 +++++++++++------- 2 files changed, 11 insertions(+), 48 deletions(-) delete mode 100644 Plugins/BDFDB.js diff --git a/Plugins/BDFDB.js b/Plugins/BDFDB.js deleted file mode 100644 index a07a17de89..0000000000 --- a/Plugins/BDFDB.js +++ /dev/null @@ -1,41 +0,0 @@ -if (window.BDFDB && window.BDFDB.myPlugins && Object.keys(window.BDFDB.myPlugins).length) BdApi.showConfirmationModal("BDFDB - Switching from remote to local library", `Due to recent security concerns, plugins are no longer allowed to load remote libraries. That's why I moved my plugin library to a plugin file and converted all my plugins so they use the local library. To download the library plugin and convert all plugins to the newest version press "Convert now". This might take a moment depending on how many of my plugins you are using. This will not delete any of your plugin configurations! Found plugins: ${Object.keys(window.BDFDB.myPlugins).join(", ")}`, { - confirmText: "Convert Now", - cancelText: "Cancel", - onConfirm: _ => { - let request = require("request"); - let fs = require("fs"); - let path = require("path"); - let finish = _ => { - BdApi.alert("Finished converting", "The new library has been downloaded and all old plugins that were enabled have been converted. Old disabled plugins need to be converted once you enable them."); - }; - let downloadPlugins = _ => { - let plugins = Object.assign({}, window.BDFDB.myPlugins), i = 0; - for (let name in plugins) if (plugins[name]) { - i++; - let last = i >= Object.keys(plugins).length; - clearTimeout(plugins[name].startTimeout); - setTimeout(_ => { - let url = typeof plugins[name].getRawUrl == "function" && typeof plugins[name].getRawUrl() == "string" ? plugins[name].getRawUrl() : `https://mwittrien.github.io/BetterDiscordAddons/Plugins/${name}/${name}.plugin.js`; - request(url, (error, response, body) => { - if (!error && body && body.indexOf(`//META{"name":"`) > -1) fs.writeFile(path.join(BdApi.Plugins.folder, name + ".plugin.js"), body, _ => { - if (last) finish(); - }); - else if (last) finish(); - }); - }, i * 1000); - } - }; - if (BdApi.Plugins.get("BDFDB")) downloadPlugins(); - else request.get("https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js", (error, response, body) => { - fs.writeFile(path.join(BdApi.Plugins.folder, "0BDFDB.plugin.js"), body, _ => { - let count = 0, interval = setInterval(_ => { - if (window.BDFDB_Global) { - clearInterval(interval); - downloadPlugins(); - } - else if (count > 100) clearInterval(interval); - }, 1000); - }); - }); - } -}); diff --git a/Plugins/BDFDB.min.js b/Plugins/BDFDB.min.js index a07a17de89..ba04aad144 100644 --- a/Plugins/BDFDB.min.js +++ b/Plugins/BDFDB.min.js @@ -1,10 +1,8 @@ -if (window.BDFDB && window.BDFDB.myPlugins && Object.keys(window.BDFDB.myPlugins).length) BdApi.showConfirmationModal("BDFDB - Switching from remote to local library", `Due to recent security concerns, plugins are no longer allowed to load remote libraries. That's why I moved my plugin library to a plugin file and converted all my plugins so they use the local library. To download the library plugin and convert all plugins to the newest version press "Convert now". This might take a moment depending on how many of my plugins you are using. This will not delete any of your plugin configurations! Found plugins: ${Object.keys(window.BDFDB.myPlugins).join(", ")}`, { +if (window.BDFDB && window.BDFDB.myPlugins && Object.keys(window.BDFDB.myPlugins).length) BdApi.showConfirmationModal("BDFDB - Switching from remote to local library", `Due to recent security concerns, plugins are no longer allowed to load remote libraries. That's why I moved my plugin library to a plugin file and converted all my plugins so they use the local library. To download the library plugin and convert all plugins to the newest version press "Convert now". This might take a moment depending on how many of my plugins you are using. This will not delete any of your plugin configurations!\nFound plugins: ${Object.keys(window.BDFDB.myPlugins).join(", ")}`, { confirmText: "Convert Now", cancelText: "Cancel", onConfirm: _ => { - let request = require("request"); - let fs = require("fs"); - let path = require("path"); + let request = require("request"), fs = require("fs"), path = require("path"); let finish = _ => { BdApi.alert("Finished converting", "The new library has been downloaded and all old plugins that were enabled have been converted. Old disabled plugins need to be converted once you enable them."); }; @@ -17,10 +15,16 @@ if (window.BDFDB && window.BDFDB.myPlugins && Object.keys(window.BDFDB.myPlugins setTimeout(_ => { let url = typeof plugins[name].getRawUrl == "function" && typeof plugins[name].getRawUrl() == "string" ? plugins[name].getRawUrl() : `https://mwittrien.github.io/BetterDiscordAddons/Plugins/${name}/${name}.plugin.js`; request(url, (error, response, body) => { - if (!error && body && body.indexOf(`//META{"name":"`) > -1) fs.writeFile(path.join(BdApi.Plugins.folder, name + ".plugin.js"), body, _ => { + let filePath = path.join(BdApi.Plugins.folder, name + ".plugin.js"); + if (!error && body && body.indexOf("/**") == 0 && body.indexOf(` * @name `) > -1) { + fs.writeFile(filePath, body, _ => {if (last) finish();}); + } + else { + fs.exists(filePath, exists => {if (exists) fs.unlink(filePath, _ => {});}); + let configPath = path.join(BdApi.Plugins.folder, name + ".config.json"); + fs.exists(configPath, exists => {if (exists) fs.unlink(configPath, _ => {});}); if (last) finish(); - }); - else if (last) finish(); + } }); }, i * 1000); }