Update 0BDFDB.plugin.js

This commit is contained in:
Mirco Wittrien 2021-07-15 21:13:07 +02:00
parent 40d4d94b99
commit 271b40b964
1 changed files with 7283 additions and 7278 deletions

View File

@ -980,19 +980,19 @@ module.exports = (_ => {
return backup;
};
const loadLibrary = tryAgain => {
let InternalData, libraryCSS;
const requestLibraryData = tryAgain => {
request.get(`https://mwittrien.github.io/BetterDiscordAddons/Library/_res/BDFDB.raw.css`, (e, r, b) => {
if ((e || !b || r.statusCode != 200) && tryAgain) return BDFDB.TimeUtils.timeout(_ => loadLibrary(), 10000);
const css = !e && b && r.statusCode == 200 ? b : fs.existsSync(cssPath) && (fs.readFileSync(cssPath) || "").toString();
if ((e || !b || r.statusCode != 200) && tryAgain) return BDFDB.TimeUtils.timeout(_ => requestLibraryData(), 10000);
libraryCSS = !e && b && r.statusCode == 200 ? b : fs.existsSync(cssPath) && (fs.readFileSync(cssPath) || "").toString();
request.get(`https://mwittrien.github.io/BetterDiscordAddons/Library/_res/BDFDB.data.json`, BDFDB.TimeUtils.suppress((e2, r2, b2) => {
if (e2 || !b2 || r2.statusCode != 200) {
if (tryAgain) return BDFDB.TimeUtils.timeout(_ => loadLibrary(), 10000);
if (tryAgain) return BDFDB.TimeUtils.timeout(_ => requestLibraryData(), 10000);
else {
BDFDB.LogUtils.error(["Failed to fetch JSON from GitHub. Could not load data.json!", e2 || ""]);
b2 = loadBackup();
}
}
let InternalData;
try {InternalData = JSON.parse(b2);}
catch (err) {
BDFDB.LogUtils.error(["Failed to parse fetched JSON. Could not load data.json!", err]);
@ -1002,6 +1002,24 @@ module.exports = (_ => {
if (!e && b && r.statusCode == 200) fs.writeFile(cssPath, b, _ => {});
if (!e2 && b2 && r2.statusCode == 200) fs.writeFile(dataPath, b2, _ => {});
InternalBDFDB.getWebModuleReq = function () {
if (!InternalBDFDB.getWebModuleReq.req) {
const id = "BDFDB-WebModules";
const req = window.webpackJsonp.push([[], {[id]: (module, exports, req) => module.exports = req}, [[id]]]);
delete req.m[id];
delete req.c[id];
InternalBDFDB.getWebModuleReq.req = req;
}
return InternalBDFDB.getWebModuleReq.req;
};
// ADD async proxy check
loadLibrary();
}, "Could not initiate Library!"));
});
};
const loadLibrary = _ => {
InternalData.UserBackgrounds = {};
if (InternalData.userBackgroundsUrl && InternalData.userBackgroundsProperties) request(InternalData.userBackgroundsUrl, (e3, r3, b3) => {
if (!e3 && b3 && r3.statusCode == 200) {
@ -1037,6 +1055,91 @@ module.exports = (_ => {
else return "";
};
InternalBDFDB.findModule = function (type, cacheString, filter, getExport) {
if (!BDFDB.ObjectUtils.is(Cache.modules[type])) Cache.modules[type] = {module: {}, export: {}};
if (getExport && Cache.modules[type].export[cacheString]) return Cache.modules[type].export[cacheString];
else if (!getExport && Cache.modules[type].module[cacheString]) return Cache.modules[type].module[cacheString];
else {
let m = BDFDB.ModuleUtils.find(filter, getExport);
if (m) {
if (getExport) Cache.modules[type].export[cacheString] = m;
else Cache.modules[type].module[cacheString] = m;
return m;
}
else BDFDB.LogUtils.warn(`${cacheString} [${type}] not found in WebModules`);
}
};
const proxyStates = {};
InternalBDFDB.isSearchableModule = function (m, path) {
if (m && (typeof m == "object" || typeof m == "function")) {
path = [path].flat(10).join(" ");
if (proxyStates[path] !== undefined) return !proxyStates[path];
else {
proxyStates[path] = BDFDB.ObjectUtils.isProxy(m);
return !proxyStates[path];
}
}
return false;
};
BDFDB.ModuleUtils = {};
BDFDB.ModuleUtils.find = function (filter, getExport) {
getExport = typeof getExport != "boolean" ? true : getExport;
let req = InternalBDFDB.getWebModuleReq();
for (let i in req.c) if (req.c.hasOwnProperty(i)) {
let m = req.c[i].exports;
if (m && (typeof m == "object" || typeof m == "function") && filter(m)) return getExport ? m : req.c[i];
if (m && m.__esModule) {
for (let j in m) if (InternalBDFDB.isSearchableModule(m[j], [i, j]) && filter(m[j])) return getExport ? m[j] : req.c[i];
if (m.default && (typeof m.default == "object" || typeof m.default == "function")) {
for (let j in m.default) if (InternalBDFDB.isSearchableModule(m.default[j], [i, "default", j]) && filter(m.default[j])) return getExport ? m.default[j] : req.c[i];
}
}
}
for (let i in req.m) if (req.m.hasOwnProperty(i)) {
let m = req.m[i];
if (m && typeof m == "function" && filter(m)) {
if (req.c[i]) return getExport ? req.c[i].exports : req.c[i];
else {
let resolved = {}, resolved2 = {};
m(resolved, resolved2, req);
let trueResolved = resolved2 && BDFDB.ObjectUtils.isEmpty(resolved2) ? resolved : resolved2;
return getExport ? trueResolved.exports : trueResolved;
}
}
}
};
BDFDB.ModuleUtils.findByProperties = function (...properties) {
properties = properties.flat(10);
let getExport = properties.pop();
if (typeof getExport != "boolean") {
properties.push(getExport);
getExport = true;
}
return InternalBDFDB.findModule("prop", JSON.stringify(properties), m => properties.every(prop => m[prop] !== undefined), getExport);
};
BDFDB.ModuleUtils.findByName = function (name, getExport) {
return InternalBDFDB.findModule("name", JSON.stringify(name), m => m.displayName === name || m.render && m.render.displayName === name, typeof getExport != "boolean" ? true : getExport);
};
BDFDB.ModuleUtils.findByString = function (...strings) {
strings = strings.flat(10);
let getExport = strings.pop();
if (typeof getExport != "boolean") {
strings.push(getExport);
getExport = true;
}
return InternalBDFDB.findModule("string", JSON.stringify(strings), m => strings.every(string => typeof m == "function" && (m.toString().indexOf(string) > -1 || typeof m.__originalMethod == "function" && m.__originalMethod.toString().indexOf(string) > -1 || typeof m.__originalFunction == "function" && m.__originalFunction.toString().indexOf(string) > -1) || BDFDB.ObjectUtils.is(m) && typeof m.type == "function" && m.type.toString().indexOf(string) > -1), getExport);
};
BDFDB.ModuleUtils.findByPrototypes = function (...protoProps) {
protoProps = protoProps.flat(10);
let getExport = protoProps.pop();
if (typeof getExport != "boolean") {
protoProps.push(getExport);
getExport = true;
}
return InternalBDFDB.findModule("proto", JSON.stringify(protoProps), m => m.prototype && protoProps.every(prop => m.prototype[prop] !== undefined), getExport);
};
BDFDB.ObserverUtils = {};
BDFDB.ObserverUtils.connect = function (plugin, eleOrSelec, observer, config = {childList: true}) {
plugin = plugin == BDFDB && InternalBDFDB || plugin;
@ -1837,101 +1940,6 @@ module.exports = (_ => {
return itemLayer;
};
InternalBDFDB.findModule = function (type, cacheString, filter, getExport) {
if (!BDFDB.ObjectUtils.is(Cache.modules[type])) Cache.modules[type] = {module: {}, export: {}};
if (getExport && Cache.modules[type].export[cacheString]) return Cache.modules[type].export[cacheString];
else if (!getExport && Cache.modules[type].module[cacheString]) return Cache.modules[type].module[cacheString];
else {
let m = BDFDB.ModuleUtils.find(filter, getExport);
if (m) {
if (getExport) Cache.modules[type].export[cacheString] = m;
else Cache.modules[type].module[cacheString] = m;
return m;
}
else BDFDB.LogUtils.warn(`${cacheString} [${type}] not found in WebModules`);
}
};
InternalBDFDB.getWebModuleReq = function () {
if (!InternalBDFDB.getWebModuleReq.req) {
const id = "BDFDB-WebModules";
const req = window.webpackJsonp.push([[], {[id]: (module, exports, req) => module.exports = req}, [[id]]]);
delete req.m[id];
delete req.c[id];
InternalBDFDB.getWebModuleReq.req = req;
}
return InternalBDFDB.getWebModuleReq.req;
};
const proxyStates = {};
InternalBDFDB.isSearchableModule = function (m, path) {
if (m && (typeof m == "object" || typeof m == "function")) {
path = [path].flat(10).join(" ");
if (proxyStates[path] !== undefined) return !proxyStates[path];
else {
proxyStates[path] = BDFDB.ObjectUtils.isProxy(m);
return !proxyStates[path];
}
}
return false;
};
BDFDB.ModuleUtils = {};
BDFDB.ModuleUtils.find = function (filter, getExport) {
getExport = typeof getExport != "boolean" ? true : getExport;
let req = InternalBDFDB.getWebModuleReq();
for (let i in req.c) if (req.c.hasOwnProperty(i)) {
let m = req.c[i].exports;
if (m && (typeof m == "object" || typeof m == "function") && filter(m)) return getExport ? m : req.c[i];
if (m && m.__esModule) {
for (let j in m) if (InternalBDFDB.isSearchableModule(m[j], [i, j]) && filter(m[j])) return getExport ? m[j] : req.c[i];
if (m.default && (typeof m.default == "object" || typeof m.default == "function")) {
for (let j in m.default) if (InternalBDFDB.isSearchableModule(m.default[j], [i, "default", j]) && filter(m.default[j])) return getExport ? m.default[j] : req.c[i];
}
}
}
for (let i in req.m) if (req.m.hasOwnProperty(i)) {
let m = req.m[i];
if (m && typeof m == "function" && filter(m)) {
if (req.c[i]) return getExport ? req.c[i].exports : req.c[i];
else {
let resolved = {}, resolved2 = {};
m(resolved, resolved2, req);
let trueResolved = resolved2 && BDFDB.ObjectUtils.isEmpty(resolved2) ? resolved : resolved2;
return getExport ? trueResolved.exports : trueResolved;
}
}
}
};
BDFDB.ModuleUtils.findByProperties = function (...properties) {
properties = properties.flat(10);
let getExport = properties.pop();
if (typeof getExport != "boolean") {
properties.push(getExport);
getExport = true;
}
return InternalBDFDB.findModule("prop", JSON.stringify(properties), m => properties.every(prop => m[prop] !== undefined), getExport);
};
BDFDB.ModuleUtils.findByName = function (name, getExport) {
return InternalBDFDB.findModule("name", JSON.stringify(name), m => m.displayName === name || m.render && m.render.displayName === name, typeof getExport != "boolean" ? true : getExport);
};
BDFDB.ModuleUtils.findByString = function (...strings) {
strings = strings.flat(10);
let getExport = strings.pop();
if (typeof getExport != "boolean") {
strings.push(getExport);
getExport = true;
}
return InternalBDFDB.findModule("string", JSON.stringify(strings), m => strings.every(string => typeof m == "function" && (m.toString().indexOf(string) > -1 || typeof m.__originalMethod == "function" && m.__originalMethod.toString().indexOf(string) > -1 || typeof m.__originalFunction == "function" && m.__originalFunction.toString().indexOf(string) > -1) || BDFDB.ObjectUtils.is(m) && typeof m.type == "function" && m.type.toString().indexOf(string) > -1), getExport);
};
BDFDB.ModuleUtils.findByPrototypes = function (...protoProps) {
protoProps = protoProps.flat(10);
let getExport = protoProps.pop();
if (typeof getExport != "boolean") {
protoProps.push(getExport);
getExport = true;
}
return InternalBDFDB.findModule("proto", JSON.stringify(protoProps), m => m.prototype && protoProps.every(prop => m.prototype[prop] !== undefined), getExport);
};
InternalBDFDB.forceInitiateProcess = function (pluginDataObjs, instance, type) {
pluginDataObjs = [pluginDataObjs].flat(10).filter(n => n);
if (pluginDataObjs.length && instance && type) {
@ -8385,8 +8393,7 @@ module.exports = (_ => {
BDFDB.LibraryComponents[component] = "div";
}
if (!document.querySelector("head #bd-stylesheet")) BDFDB.DOMUtils.appendWebStyle("https://rauenzi.github.io/BetterDiscordApp/src/styles/index.css");
if (css) BDFDB.DOMUtils.appendLocalStyle("BDFDB", css.replace(/[\n\t\r]/g, "").replace(/\[REPLACE_CLASS_([A-z0-9_]+?)\]/g, function(a, b) {return BDFDB.dotCN[b];}));
if (libraryCSS) BDFDB.DOMUtils.appendLocalStyle("BDFDB", libraryCSS.replace(/[\n\t\r]/g, "").replace(/\[REPLACE_CLASS_([A-z0-9_]+?)\]/g, (a, b) => BDFDB.dotCN[b]));
BDFDB.LogUtils.log("Finished loading Library");
@ -8405,10 +8412,8 @@ module.exports = (_ => {
let pluginName = pluginQueue.shift();
if (pluginName) BDFDB.TimeUtils.timeout(_ => BDFDB.BDUtils.reloadPlugin(pluginName));
}
}, "Could not initiate Library!"));
});
};
loadLibrary(true);
requestLibraryData(true);
return class BDFDB_Frame {
getName () {return config.info.name;}