BetterDiscordAddons/Plugins/BDFDB.min.js

46 lines
2.6 KiB
JavaScript
Raw Normal View History

2020-10-25 17:25:53 +01:00
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(", ")}`, {
2020-10-12 23:57:09 +02:00
confirmText: "Convert Now",
2020-09-19 21:51:26 +02:00
cancelText: "Cancel",
onConfirm: _ => {
2020-10-25 17:25:53 +01:00
let request = require("request"), fs = require("fs"), path = require("path");
2020-09-19 21:51:26 +02:00
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;
2020-09-28 16:31:56 +02:00
for (let name in plugins) if (plugins[name]) {
2020-09-19 21:51:26 +02:00
i++;
let last = i >= Object.keys(plugins).length;
2020-09-28 16:31:56 +02:00
clearTimeout(plugins[name].startTimeout);
2020-09-19 21:51:26 +02:00
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`;
2020-09-19 21:51:26 +02:00
request(url, (error, response, body) => {
2020-10-25 17:25:53 +01:00
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, _ => {});});
2020-09-19 21:51:26 +02:00
if (last) finish();
2020-10-25 17:25:53 +01:00
}
2020-09-19 21:51:26 +02:00
});
}, i * 1000);
}
};
if (BdApi.Plugins.get("BDFDB")) downloadPlugins();
else request.get("https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js", (error, response, body) => {
2020-09-21 10:48:29 +02:00
fs.writeFile(path.join(BdApi.Plugins.folder, "0BDFDB.plugin.js"), body, _ => {
2020-09-19 21:51:26 +02:00
let count = 0, interval = setInterval(_ => {
if (window.BDFDB_Global) {
clearInterval(interval);
downloadPlugins();
}
else if (count > 100) clearInterval(interval);
}, 1000);
});
});
}
2020-09-21 10:48:29 +02:00
});