This commit is contained in:
Mirco Wittrien 2020-10-25 17:25:53 +01:00
parent 233fd32a4e
commit 8bb79cacad
2 changed files with 11 additions and 48 deletions

View File

@ -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);
});
});
}
});

18
Plugins/BDFDB.min.js vendored
View File

@ -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);
}