(_ => {
if (window.BDFDB && window.BDFDB.ListenerUtils && typeof window.BDFDB.ListenerUtils.remove == "function") window.BDFDB.ListenerUtils.remove(window.BDFDB);
if (window.BDFDB && window.BDFDB.StoreChangeUtils && typeof window.BDFDB.StoreChangeUtils.remove == "function") window.BDFDB.StoreChangeUtils.remove(window.BDFDB);
if (window.BDFDB && window.BDFDB.ObserverUtils && typeof window.BDFDB.ObserverUtils.disconnect == "function") window.BDFDB.ObserverUtils.disconnect(window.BDFDB);
if (window.BDFDB && window.BDFDB.ModuleUtils && typeof window.BDFDB.ModuleUtils.unpatch == "function") window.BDFDB.ModuleUtils.unpatch(window.BDFDB);
if (window.BDFDB && window.BDFDB.WindowUtils && typeof window.BDFDB.WindowUtils.closeAll == "function") window.BDFDB.WindowUtils.closeAll(window.BDFDB);
if (window.BDFDB && window.BDFDB.WindowUtils && typeof window.BDFDB.WindowUtils.removeListener == "function") window.BDFDB.WindowUtils.removeListener(window.BDFDB);
var BDFDB = {
myPlugins: Object.assign({}, window.BDFDB && window.BDFDB.myPlugins),
InternalData: Object.assign({
pressedKeys: [],
mousePosition: {
pageX: 0,
pageY: 0
},
componentPatchQueries: {}
},
window.BDFDB && window.BDFDB.InternalData,
{
creationTime: performance.now()
}),
BDv2Api: window.BDFDB && window.BDFDB.BDv2Api || undefined,
name: "BDFDB"
};
var loadid = Math.round(Math.random() * 10000000000000000), InternalBDFDB = {};
BDFDB.InternalData.loadid = loadid;
if (typeof Array.prototype.flat != "function") Array.prototype.flat = function () {return this;}
InternalBDFDB.defaults = {
settings: {
showToasts: {value:true, description:"Show Plugin start and stop Toasts"},
showSupportBadges: {value:true, description:"Show little Badges for Users who support my Patreon"},
addSupportLinks: {value:true, description:"Add PayPal/Patreon links to my Plugin Entries"}
}
};
BDFDB.LogUtils = {};
BDFDB.LogUtils.log = function (string, name) {
console.log(`%c[${typeof name == "string" && name || "BDFDB"}]`, "color: #3a71c1; font-weight: 700;", (typeof string == "string" && string || "").trim());
};
BDFDB.LogUtils.warn = function (string, name) {
console.warn(`%c[${typeof name == "string" && name || "BDFDB"}]`, "color: #3a71c1; font-weight: 700;", (typeof string == "string" && string || "").trim());
};
BDFDB.LogUtils.error = function (string, name) {
console.error(`%c[${typeof name == "string" && name || "BDFDB"}]`, "color: #3a71c1; font-weight: 700;", "Fatal Error: " + (typeof string == "string" && string || "").trim());
};
BDFDB.LogUtils.log("Loading library.");
BDFDB.PluginUtils = {};
BDFDB.PluginUtils.init = function (plugin) {
plugin.name = plugin.name || (typeof plugin.getName == "function" ? plugin.getName() : null);
plugin.version = plugin.version || (typeof plugin.getVersion == "function" ? plugin.getVersion() : null);
plugin.author = plugin.author || (typeof plugin.getAuthor == "function" ? plugin.getAuthor() : null);
plugin.description = plugin.description || (typeof plugin.getDescription == "function" ? plugin.getDescription() : null);
InternalBDFDB.clearStartTimeout(plugin);
let loadmessage = BDFDB.LanguageUtils.LibraryStringsFormat("toast_plugin_started", "v" + plugin.version);
BDFDB.LogUtils.log(loadmessage, plugin.name);
if (!BDFDB.BDUtils.getSettings("fork-ps-2") && BDFDB.DataUtils.get(BDFDB, "settings", "showToasts")) BDFDB.NotificationUtils.toast(plugin.name + " " + loadmessage, {nopointer: true, selector: "plugin-started-toast"});
let url = typeof plugin.getRawUrl == "function" && typeof plugin.getRawUrl() == "string" ? plugin.getRawUrl() : `https://mwittrien.github.io/BetterDiscordAddons/Plugins/${plugin.name}/${plugin.name}.plugin.js`;
BDFDB.PluginUtils.checkUpdate(plugin.name, url);
if (BDFDB.ObjectUtils.is(plugin.classes)) InternalBDFDB.addPluginClasses(plugin);
if (typeof plugin.initConstructor === "function") BDFDB.TimeUtils.suppress(plugin.initConstructor.bind(plugin), "Could not initiate constructor!", plugin.name)();
if (typeof plugin.css === "string") BDFDB.DOMUtils.appendLocalStyle(plugin.name, plugin.css);
InternalBDFDB.patchPlugin(plugin);
InternalBDFDB.addSpecialListeners(plugin);
BDFDB.PluginUtils.translate(plugin);
BDFDB.PluginUtils.checkChangeLog(plugin);
if (!window.PluginUpdates || typeof window.PluginUpdates !== "object") window.PluginUpdates = {plugins: {} };
window.PluginUpdates.plugins[url] = {name: plugin.name, raw: url, version: plugin.version};
if (typeof window.PluginUpdates.interval === "undefined") window.PluginUpdates.interval = BDFDB.TimeUtils.interval(_ => {BDFDB.PluginUtils.checkAllUpdates();}, 1000*60*60*2);
plugin.started = true;
delete plugin.stopping;
for (let name in BDFDB.myPlugins) if (!BDFDB.myPlugins[name].started && typeof BDFDB.myPlugins[name].initialize == "function") setImmediate(_ => {BDFDB.TimeUtils.suppress(BDFDB.myPlugins[name].initialize.bind(BDFDB.myPlugins[name]), "Could not initiate plugin!", name)();});
};
BDFDB.PluginUtils.clear = function (plugin) {
InternalBDFDB.clearStartTimeout(plugin);
delete BDFDB.myPlugins[plugin.name];
let unloadmessage = BDFDB.LanguageUtils.LibraryStringsFormat("toast_plugin_stopped", "v" + plugin.version);
BDFDB.LogUtils.log(unloadmessage, plugin.name);
if (!BDFDB.BDUtils.getSettings("fork-ps-2") && BDFDB.DataUtils.get(BDFDB, "settings", "showToasts")) BDFDB.NotificationUtils.toast(plugin.name + " " + unloadmessage, {nopointer: true, selector: "plugin-stopped-toast"});
let url = typeof plugin.getRawUrl == "function" && typeof plugin.getRawUrl() == "string" ? plugin.getRawUrl() : `https://mwittrien.github.io/BetterDiscordAddons/Plugins/${plugin.name}/${plugin.name}.plugin.js`;
if (BDFDB.ObjectUtils.is(plugin.classes)) InternalBDFDB.removePluginClasses(plugin);
if (typeof plugin.css === "string") BDFDB.DOMUtils.removeLocalStyle(plugin.name);
BDFDB.ModuleUtils.unpatch(plugin);
BDFDB.ListenerUtils.remove(plugin);
BDFDB.StoreChangeUtils.remove(plugin);
BDFDB.ObserverUtils.disconnect(plugin);
BDFDB.WindowUtils.closeAll(plugin);
BDFDB.WindowUtils.removeListener(plugin);
for (let type in BDFDB.InternalData.componentPatchQueries) BDFDB.ArrayUtils.remove(BDFDB.InternalData.componentPatchQueries[type].query, plugin, true);
for (let modal of document.querySelectorAll(`.${plugin.name}-modal, .${plugin.name.toLowerCase()}-modal, .${plugin.name}-settingsmodal, .${plugin.name.toLowerCase()}-settingsmodal`)) {
let closebutton = modal.querySelector(BDFDB.dotCN.modalclose);
if (closebutton) closebutton.click();
}
delete BDFDB.DataUtils.cached[plugin.name]
delete window.PluginUpdates.plugins[url];
delete plugin.started;
BDFDB.TimeUtils.timeout(_ => {delete plugin.stopping;});
};
BDFDB.PluginUtils.translate = function (plugin) {
plugin.labels = {};
if (typeof plugin.setLabelsByLanguage === "function" || typeof plugin.changeLanguageStrings === "function") {
if (document.querySelector("html").lang) translate();
else {
var translateinterval = BDFDB.TimeUtils.interval(_ => {
if (document.querySelector("html").lang) {
BDFDB.TimeUtils.clear(translateinterval);
translate();
}
}, 100);
}
function translate() {
var language = BDFDB.LanguageUtils.getLanguage();
if (typeof plugin.setLabelsByLanguage === "function") plugin.labels = plugin.setLabelsByLanguage(language.id);
if (typeof plugin.changeLanguageStrings === "function") plugin.changeLanguageStrings();
BDFDB.LogUtils.log(BDFDB.LanguageUtils.LibraryStringsFormat("toast_plugin_translated", language.ownlang), plugin.name);
}
}
};
BDFDB.PluginUtils.checkUpdate = function (pluginName, url) {
if (BDFDB.BDUtils.isBDv2() || !pluginName || !url) return;
LibraryRequires.request(url, (error, response, result) => {
if (error) return;
var newversion = result.match(/['"][0-9]+\.[0-9]+\.[0-9]+['"]/i);
if (!newversion) return;
if (BDFDB.NumberUtils.getVersionDifference(newversion[0], window.PluginUpdates.plugins[url].version) > 0.2) {
BDFDB.NotificationUtils.toast(`${pluginName} will be force updated, because your version is heavily outdated.`, {type:"warn", nopointer:true, selector:"plugin-forceupdate-toast"});
BDFDB.PluginUtils.downloadUpdate(pluginName, url);
}
else if (BDFDB.NumberUtils.compareVersions(newversion[0], window.PluginUpdates.plugins[url].version)) BDFDB.PluginUtils.showUpdateNotice(pluginName, url);
else BDFDB.PluginUtils.removeUpdateNotice(pluginName);
});
};
BDFDB.PluginUtils.checkAllUpdates = function () {
for (let url in window.PluginUpdates.plugins) {
var plugin = window.PluginUpdates.plugins[url];
BDFDB.PluginUtils.checkUpdate(plugin.name, plugin.raw);
}
};
BDFDB.PluginUtils.showUpdateNotice = function (pluginName, url) {
if (!pluginName || !url) return;
var updatenotice = document.querySelector("#pluginNotice");
if (!updatenotice) {
updatenotice = BDFDB.NotificationUtils.notice(`The following plugins need to be updated: `, {html:true, id:"pluginNotice", type:"info", btn:!BDFDB.BDUtils.isAutoLoadEnabled() ? "Reload" : "", customicon:``});
updatenotice.style.setProperty("display", "block", "important");
updatenotice.style.setProperty("visibility", "visible", "important");
updatenotice.style.setProperty("opacity", "1", "important");
updatenotice.querySelector(BDFDB.dotCN.noticedismiss).addEventListener("click", _ => {
BDFDB.DOMUtils.remove(".update-clickme-tooltip");
});
let reloadbutton = updatenotice.querySelector(BDFDB.dotCN.noticebutton);
if (reloadbutton) {
BDFDB.DOMUtils.toggle(reloadbutton, true);
reloadbutton.addEventListener("click", _ => {
LibraryRequires.electron.remote.getCurrentWindow().reload();
});
reloadbutton.addEventListener("mouseenter", _ => {
if (window.PluginUpdates.downloaded) BDFDB.TooltipUtils.create(reloadbutton, window.PluginUpdates.downloaded.join(", "), {type:"bottom", selector:"update-notice-tooltip", style: "max-width: 420px"});
});
}
}
if (updatenotice) {
var updatenoticelist = updatenotice.querySelector("#outdatedPlugins");
if (updatenoticelist && !updatenoticelist.querySelector(`#${pluginName}-notice`)) {
if (updatenoticelist.querySelector("span")) updatenoticelist.appendChild(BDFDB.DOMUtils.create(`, `));
var updateentry = BDFDB.DOMUtils.create(`${pluginName}`);
updateentry.addEventListener("click", _ => {BDFDB.PluginUtils.downloadUpdate(pluginName, url);});
updatenoticelist.appendChild(updateentry);
if (!document.querySelector(".update-clickme-tooltip")) BDFDB.TooltipUtils.create(updatenoticelist, "Click us!", {type:"bottom", selector:"update-clickme-tooltip", delay:500});
}
}
};
BDFDB.PluginUtils.removeUpdateNotice = function (pluginName, updatenotice = document.querySelector("#pluginNotice")) {
if (!pluginName || !updatenotice) return;
var updatenoticelist = updatenotice.querySelector("#outdatedPlugins");
if (updatenoticelist) {
var noticeentry = updatenoticelist.querySelector(`#${pluginName}-notice`);
if (noticeentry) {
var nextsibling = noticeentry.nextSibling;
var prevsibling = noticeentry.prevSibling;
if (nextsibling && BDFDB.DOMUtils.containsClass(nextsibling, "separator")) nextsibling.remove();
else if (prevsibling && BDFDB.DOMUtils.containsClass(prevsibling, "separator")) prevsibling.remove();
noticeentry.remove();
}
if (!updatenoticelist.querySelector("span")) {
var reloadbutton = updatenotice.querySelector(BDFDB.dotCN.noticebutton);
if (reloadbutton) {
updatenotice.querySelector(".notice-message").innerText = "To finish updating you need to reload.";
BDFDB.DOMUtils.toggle(reloadbutton, false);
}
else updatenotice.querySelector(BDFDB.dotCN.noticedismiss).click();
}
}
};
BDFDB.PluginUtils.downloadUpdate = function (pluginName, url) {
if (!pluginName || !url) return;
LibraryRequires.request(url, (error, response, result) => {
if (error) return BDFDB.LogUtils.warn("Unable to get update for " + pluginName);
BDFDB.InternalData.creationTime = 0;
var newversion = result.match(/['"][0-9]+\.[0-9]+\.[0-9]+['"]/i);
newversion = newversion.toString().replace(/['"]/g, "");
LibraryRequires.fs.writeFileSync(LibraryRequires.path.join(BDFDB.BDUtils.getPluginsFolder(), url.split("/").slice(-1)[0]), result);
BDFDB.NotificationUtils.toast(`${pluginName} v${window.PluginUpdates.plugins[url].version} has been replaced by ${pluginName} v${newversion}.`, {nopointer:true, selector:"plugin-updated-toast"});
var updatenotice = document.querySelector("#pluginNotice");
if (updatenotice) {
if (updatenotice.querySelector(BDFDB.dotCN.noticebutton)) {
window.PluginUpdates.plugins[url].version = newversion;
if (!window.PluginUpdates.downloaded) window.PluginUpdates.downloaded = [];
if (!window.PluginUpdates.downloaded.includes(pluginName)) window.PluginUpdates.downloaded.push(pluginName);
}
BDFDB.PluginUtils.removeUpdateNotice(pluginName, updatenotice);
}
});
};
BDFDB.PluginUtils.checkChangeLog = function (plugin) {
if (!BDFDB.ObjectUtils.is(plugin) || !plugin.changelog) return;
var changelog = BDFDB.DataUtils.load(plugin, "changelog");
if (!changelog.currentversion || BDFDB.NumberUtils.compareVersions(plugin.version, changelog.currentversion)) {
changelog.currentversion = plugin.version;
BDFDB.DataUtils.save(changelog, plugin, "changelog");
BDFDB.PluginUtils.openChangeLog(plugin);
}
};
BDFDB.PluginUtils.openChangeLog = function (plugin) {
if (!BDFDB.ObjectUtils.is(plugin) || !plugin.changelog) return;
var changeLogHTML = "", headers = {
added: "New Features",
fixed: "Bug Fixes",
improved: "Improvements",
progress: "Progress"
};
for (let type in plugin.changelog) {
type = type.toLowerCase();
var classname = BDFDB.disCN["changelog" + type];
if (classname) {
changeLogHTML += `
${headers[type]}
`;
for (let log of plugin.changelog[type]) changeLogHTML += `
${log[0]}${log[1] ? (": " + log[1] + ".") : ""}
`;
changeLogHTML += `
`
}
}
if (changeLogHTML) BDFDB.ModalUtils.open(plugin, {header:`${plugin.name} ${BDFDB.LanguageUtils.LanguageStrings.CHANGE_LOG}`, subheader:`Version ${plugin.version}`, children:BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(changeLogHTML)), className:BDFDB.disCN.modalchangelogmodal, contentClassName:BDFDB.disCNS.changelogcontainer + BDFDB.disCN.modalminicontent});
};
BDFDB.PluginUtils.addLoadingIcon = function (icon) {
if (!Node.prototype.isPrototypeOf(icon)) return;
BDFDB.DOMUtils.addClass(icon, BDFDB.disCN.loadingicon);
let loadingiconwrapper = document.querySelector(BDFDB.dotCN.app + ">" + BDFDB.dotCN.loadingiconwrapper);
if (!loadingiconwrapper) {
loadingiconwrapper = BDFDB.DOMUtils.create(``);
document.querySelector(BDFDB.dotCN.app).appendChild(loadingiconwrapper);
let killObserver = new MutationObserver(changes => {if (!loadingiconwrapper.firstElementChild) BDFDB.DOMUtils.remove(loadingiconwrapper);});
killObserver.observe(loadingiconwrapper, {childList:true});
}
loadingiconwrapper.appendChild(icon);
};
BDFDB.PluginUtils.createSettingsPanel = function (plugin, children) {
if (!BDFDB.ObjectUtils.is(plugin) || !children || (!BDFDB.ReactUtils.isValidElement(children) && !BDFDB.ArrayUtils.is(children)) || (BDFDB.ArrayUtils.is(children) && !children.length)) return;
let settingspanel = BDFDB.DOMUtils.create(``);
BDFDB.ReactUtils.render(BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.SettingsPanel, {
key: `${plugin.name}-settingspanel`,
title: plugin.name,
children
}), settingspanel);
return settingspanel;
};
BDFDB.PluginUtils.refreshSettingsPanel = function (plugin, settingspanel, ...args) {
if (!BDFDB.ObjectUtils.is(plugin) || typeof plugin.getSettingsPanel != "function" || !Node.prototype.isPrototypeOf(settingspanel) || !settingspanel.parentElement) return;
settingspanel.parentElement.appendChild(plugin.getSettingsPanel(...args));
settingspanel.remove();
};
InternalBDFDB.clearStartTimeout = function (plugin) {
if (!BDFDB.ObjectUtils.is(plugin)) return;
BDFDB.TimeUtils.clear(plugin.startTimeout, plugin.libLoadTimeout);
delete plugin.startTimeout;
delete plugin.libLoadTimeout;
};
InternalBDFDB.addSpecialListeners = function (plugin) {
if (BDFDB.ObjectUtils.is(plugin)) {
if (typeof plugin.onSettingsClosed === "function") {
let SettingsLayer = BDFDB.ModuleUtils.findByName("StandardSidebarView");
if (SettingsLayer) BDFDB.ModuleUtils.patch(plugin, SettingsLayer.prototype, "componentWillUnmount", {after: e => {
plugin.onSettingsClosed();
}});
}
if (typeof plugin.onSwitch === "function") {
let spacer = document.querySelector(`${BDFDB.dotCN.guildswrapper} ~ * > ${BDFDB.dotCN.chatspacer}`);
if (spacer) {
let noChannelObserver = new MutationObserver(changes => {changes.forEach(change => {
if (change.target && BDFDB.DOMUtils.containsClass(change.target, BDFDB.disCN.nochannel)) plugin.onSwitch();
});});
BDFDB.ObserverUtils.connect(plugin, spacer.querySelector(BDFDB.dotCNC.chat + BDFDB.dotCN.nochannel), {name:"switchFixNoChannelObserver", instance:noChannelObserver}, {attributes: true});
let spacerObserver = new MutationObserver(changes => {changes.forEach(change => {if (change.addedNodes) {change.addedNodes.forEach(node => {
if (BDFDB.DOMUtils.containsClass(node, BDFDB.disCN.chat, BDFDB.disCN.nochannel, false)) {
BDFDB.ObserverUtils.connect(plugin, node, {name:"switchFixNoChannelObserver", instance:noChannelObserver}, {attributes: true});
}
});}});});
BDFDB.ObserverUtils.connect(plugin, spacer, {name:"switchFixSpacerObserver", instance:spacerObserver}, {childList: true});
}
}
InternalBDFDB.addContextListeners(plugin);
}
};
BDFDB.ObserverUtils = {};
BDFDB.ObserverUtils.connect = function (plugin, eleOrSelec, observer, config = {childList: true}) {
if (!BDFDB.ObjectUtils.is(plugin) || !eleOrSelec || !observer) return;
if (BDFDB.ObjectUtils.isEmpty(plugin.observers)) plugin.observers = {};
if (!BDFDB.ArrayUtils.is(plugin.observers[observer.name])) plugin.observers[observer.name] = [];
if (!observer.multi) for (let subinstance of plugin.observers[observer.name]) subinstance.disconnect();
if (observer.instance) plugin.observers[observer.name].push(observer.instance);
var instance = plugin.observers[observer.name][plugin.observers[observer.name].length - 1];
if (instance) {
var node = Node.prototype.isPrototypeOf(eleOrSelec) ? eleOrSelec : typeof eleOrSelec === "string" ? document.querySelector(eleOrSelec) : null;
if (node) instance.observe(node, config);
}
};
BDFDB.ObserverUtils.disconnect = function (plugin, observer) {
if (BDFDB.ObjectUtils.is(plugin) && !BDFDB.ObjectUtils.isEmpty(plugin.observers)) {
let observername = typeof observer == "string" ? observer : (BDFDB.ObjectUtils.is(observer) ? observer.name : null);
if (!observername) {
for (let observer in plugin.observers) for (let instance of plugin.observers[observer]) instance.disconnect();
delete plugin.observers;
}
else if (!BDFDB.ArrayUtils.is(plugin.observers[observername])) {
for (let instance of plugin.observers[observername]) instance.disconnect();
delete plugin.observers[observername];
}
}
};
BDFDB.StoreChangeUtils = {};
BDFDB.StoreChangeUtils.add = function (plugin, store, callback) {
if (!BDFDB.ObjectUtils.is(plugin) || !BDFDB.ObjectUtils.is(store) || typeof store.addChangeListener != "function" || typeof callback != "function") return;
BDFDB.ListenerUtils.remove(plugin, store, callback);
if (!BDFDB.ArrayUtils.is(plugin.changeListeners)) plugin.changeListeners = [];
plugin.changeListeners.push({store, callback});
store.addChangeListener(callback);
};
BDFDB.StoreChangeUtils.remove = function (plugin, store, callback) {
if (!BDFDB.ObjectUtils.is(plugin) || !BDFDB.ArrayUtils.is(plugin.changeListeners)) return;
if (!store) {
while (plugin.changeListeners.length) {
let listener = plugin.changeListeners.pop();
listener.store.removeChangeListener(listener.callback);
}
}
else if (BDFDB.ObjectUtils.is(store) && typeof store.addChangeListener == "function") {
if (!callback) {
for (let listener of plugin.changeListeners) {
let removedListeners = [];
if (listener.store == store) {
listener.store.removeChangeListener(listener.callback);
removedListeners.push(listener);
}
if (removedListeners.length) plugin.changeListeners = plugin.changeListeners.filter(listener => !removedListeners.includes(listener));
}
}
else if (typeof callback == "function") {
store.removeChangeListener(callback);
plugin.changeListeners = plugin.changeListeners.filter(listener => listener.store == store && listener.callback == callback);
}
}
};
BDFDB.ListenerUtils = {};
BDFDB.ListenerUtils.add = function (plugin, ele, actions, selectorOrCallback, callbackOrNothing) {
if (!BDFDB.ObjectUtils.is(plugin) || (!Node.prototype.isPrototypeOf(ele) && ele !== window) || !actions) return;
let callbackIs4th = typeof selectorOrCallback == "function";
let selector = callbackIs4th ? undefined : selectorOrCallback;
let callback = callbackIs4th ? selectorOrCallback : callbackOrNothing;
if (typeof callback != "function") return;
BDFDB.ListenerUtils.remove(plugin, ele, actions, selector);
for (let action of actions.split(" ")) {
action = action.split(".");
let eventname = action.shift().toLowerCase();
if (!eventname) return;
let origeventname = eventname;
eventname = eventname == "mouseenter" || eventname == "mouseleave" ? "mouseover" : eventname;
let namespace = (action.join(".") || "") + plugin.name;
if (!BDFDB.ArrayUtils.is(plugin.eventListeners)) plugin.eventListeners = [];
let eventcallback = null;
if (selector) {
if (origeventname == "mouseenter" || origeventname == "mouseleave") {
eventcallback = e => {
for (let child of e.path) if (typeof child.matches == "function" && child.matches(selector) && !child[namespace + "BDFDB" + origeventname]) {
child[namespace + "BDFDB" + origeventname] = true;
if (origeventname == "mouseenter") callback(BDFDB.ListenerUtils.copyEvent(e, child));
let mouseout = e2 => {
if (e2.target.contains(child) || e2.target == child || !child.contains(e2.target)) {
if (origeventname == "mouseleave") callback(BDFDB.ListenerUtils.copyEvent(e, child));
delete child[namespace + "BDFDB" + origeventname];
document.removeEventListener("mouseout", mouseout);
}
};
document.addEventListener("mouseout", mouseout);
break;
}
};
}
else {
eventcallback = e => {
for (let child of e.path) if (typeof child.matches == "function" && child.matches(selector)) {
callback(BDFDB.ListenerUtils.copyEvent(e, child));
break;
}
};
}
}
else eventcallback = e => {callback(BDFDB.ListenerUtils.copyEvent(e, ele));};
plugin.eventListeners.push({ele, eventname, origeventname, namespace, selector, eventcallback});
ele.addEventListener(eventname, eventcallback, true);
}
};
BDFDB.ListenerUtils.remove = function (plugin, ele, actions = "", selector) {
if (!BDFDB.ObjectUtils.is(plugin) || !BDFDB.ArrayUtils.is(plugin.eventListeners)) return;
if (!ele) {
while (plugin.eventListeners.length) {
let listener = plugin.eventListeners.pop();
listener.ele.removeEventListener(listener.eventname, listener.eventcallback, true);
}
}
else if (Node.prototype.isPrototypeOf(ele) || ele === window) {
for (let action of actions.split(" ")) {
action = action.split(".");
let eventname = action.shift().toLowerCase();
let namespace = (action.join(".") || "") + plugin.name;
for (let listener of plugin.eventListeners) {
let removedListeners = [];
if (listener.ele == ele && (!eventname || listener.origeventname == eventname) && listener.namespace == namespace && (selector === undefined || listener.selector == selector)) {
listener.ele.removeEventListener(listener.eventname, listener.eventcallback, true);
removedListeners.push(listener);
}
if (removedListeners.length) plugin.eventListeners = plugin.eventListeners.filter(listener => !removedListeners.includes(listener));
}
}
}
};
BDFDB.ListenerUtils.multiAdd = function (node, actions, callback) {
if (!Node.prototype.isPrototypeOf(node) || !actions || typeof callback != "function") return;
for (let action of actions.trim().split(" ").filter(n => n)) node.addEventListener(action, callback, true);
};
BDFDB.ListenerUtils.multiRemove = function (node, actions, callback) {
if (!Node.prototype.isPrototypeOf(node) || !actions || typeof callback != "function") return;
for (let action of actions.trim().split(" ").filter(n => n)) node.removeEventListener(action, callback, true);
};
BDFDB.ListenerUtils.addToChildren = function (node, actions, selector, callback) {
if (!Node.prototype.isPrototypeOf(node) || !actions || !selector || !selector.trim() || typeof callback != "function") return;
for (let action of actions.trim().split(" ").filter(n => n)) {
let eventcallback = callback;
if (action == "mouseenter" || action == "mouseleave") eventcallback = e => {if (e.target.matches(selector)) callback(e);};
node.querySelectorAll(selector.trim()).forEach(child => {child.addEventListener(action, eventcallback, true);});
}
};
BDFDB.ListenerUtils.copyEvent = function (e, ele) {
if (!e || !e.constructor || !e.type) return e;
var ecopy = new e.constructor(e.type, e);
Object.defineProperty(ecopy, "originalEvent", {value: e});
Object.defineProperty(ecopy, "which", {value: e.which});
Object.defineProperty(ecopy, "keyCode", {value: e.keyCode});
Object.defineProperty(ecopy, "path", {value: e.path});
Object.defineProperty(ecopy, "relatedTarget", {value: e.relatedTarget});
Object.defineProperty(ecopy, "srcElement", {value: e.srcElement});
Object.defineProperty(ecopy, "target", {value: e.target});
Object.defineProperty(ecopy, "toElement", {value: e.toElement});
if (ele) Object.defineProperty(ecopy, "currentTarget", {value: ele});
return ecopy;
};
BDFDB.ListenerUtils.stopEvent = function (e) {
if (BDFDB.ObjectUtils.is(e)) {
if (typeof e.preventDefault == "function") e.preventDefault();
if (typeof e.stopPropagation == "function") e.stopPropagation();
if (typeof e.stopImmediatePropagation == "function") e.stopImmediatePropagation();
if (BDFDB.ObjectUtils.is(e.originalEvent)) {
if (typeof e.originalEvent.preventDefault == "function") e.originalEvent.preventDefault();
if (typeof e.originalEvent.stopPropagation == "function") e.originalEvent.stopPropagation();
if (typeof e.originalEvent.stopImmediatePropagation == "function") e.originalEvent.stopImmediatePropagation();
}
}
};
var NotificationBars = [], DesktopNotificationQueue = {queue:[], running:false};
BDFDB.NotificationUtils = {};
BDFDB.NotificationUtils.toast = function (text, options = {}) {
let toasts = document.querySelector(".toasts, .bd-toasts");
if (!toasts) {
let channels = document.querySelector(BDFDB.dotCN.channels + " + div");
let channelrects = channels ? BDFDB.DOMUtils.getRects(channels) : null;
let members = channels ? channels.querySelector(BDFDB.dotCN.memberswrap) : null;
let left = channelrects ? channelrects.left : 310;
let width = channelrects ? (members ? channelrects.width - BDFDB.DOMUtils.getRects(members).width : channelrects.width) : window.outerWidth - 0;
let form = channels ? channels.querySelector("form") : null;
let bottom = form ? BDFDB.DOMUtils.getRects(form).height : 80;
toasts = BDFDB.DOMUtils.create(``);
(document.querySelector(BDFDB.dotCN.app) || document.body).appendChild(toasts);
}
const {type = "", icon = true, timeout = 3000, html = false, selector = "", nopointer = false, color = ""} = options;
let toast = BDFDB.DOMUtils.create(`
${html === true ? text : BDFDB.StringUtils.htmlEscape(text)}
`);
if (type) {
BDFDB.DOMUtils.addClass(toast, "toast-" + type);
if (icon) BDFDB.DOMUtils.addClass(toast, "icon");
}
else if (color) {
let rgbcolor = BDFDB.ColorUtils.convert(color, "RGB");
if (rgbcolor) toast.style.setProperty("background-color", rgbcolor);
}
BDFDB.DOMUtils.addClass(toast, selector);
toasts.appendChild(toast);
toast.close = _ => {
if (document.contains(toast)) {
BDFDB.DOMUtils.addClass(toast, "closing");
toast.style.setProperty("pointer-events", "none", "important");
BDFDB.TimeUtils.timeout(_ => {
toast.remove();
if (!toasts.querySelectorAll(".toast, .bd-toast").length) toasts.remove();
}, 3000);
}
};
if (nopointer) toast.style.setProperty("pointer-events", "none", "important");
else toast.addEventListener("click", toast.close);
BDFDB.TimeUtils.timeout(_ => {toast.close();}, timeout > 0 ? timeout : 600000);
return toast;
};
BDFDB.NotificationUtils.desktop = function (parsedcontent, parsedoptions = {}) {
var queue = _ => {
DesktopNotificationQueue.queue.push({parsedcontent, parsedoptions});
runqueue();
};
var runqueue = _ => {
if (!DesktopNotificationQueue.running) {
var notification = DesktopNotificationQueue.queue.shift();
if (notification) notify(notification.parsedcontent, notification.parsedoptions);
}
};
var notify = (content, options) => {
DesktopNotificationQueue.running = true;
var muted = options.silent;
options.silent = options.silent || options.sound ? true : false;
var notification = new Notification(content, options);
var audio = new Audio();
var timeout = BDFDB.TimeUtils.timeout(_ => {close();}, options.timeout ? options.timeout : 3000);
if (typeof options.click == "function") notification.onclick = _ => {
BDFDB.TimeUtils.clear(timeout);
close();
options.click();
};
if (!muted && options.sound) {
audio.src = options.sound;
audio.play();
}
var close = _ => {
audio.pause();
notification.close();
DesktopNotificationQueue.running = false;
BDFDB.TimeUtils.timeout(_ => {runqueue();}, 1000);
};
};
if (!("Notification" in window)) {}
else if (Notification.permission === "granted") queue();
else if (Notification.permission !== "denied") Notification.requestPermission(function (response) {if (response === "granted") queue();});
};
BDFDB.NotificationUtils.notice = function (text, options = {}) {
if (!text) return;
var layers = document.querySelector(BDFDB.dotCN.layers);
if (!layers) return;
var id = BDFDB.NumberUtils.generateId(NotificationBars);
var notice = BDFDB.DOMUtils.create(`
`);
layers.parentElement.insertBefore(notice, layers);
var noticemessage = notice.querySelector(".notice-message");
if (options.platform) for (let platform of options.platform.split(" ")) if (DiscordClasses["noticeicon" + platform]) {
let icon = BDFDB.DOMUtils.create(``);
BDFDB.DOMUtils.addClass(icon, BDFDB.disCN.noticeplatformicon);
BDFDB.DOMUtils.removeClass(icon, BDFDB.disCN.noticeicon);
notice.insertBefore(icon, noticemessage);
}
if (options.customicon) {
let iconinner = BDFDB.DOMUtils.create(options.customicon)
let icon = BDFDB.DOMUtils.create(``);
if (iconinner.tagName == "span" && !iconinner.firstElementChild) icon.style.setProperty("background", `url(${options.customicon}) center/cover no-repeat`);
else icon.appendChild(iconinner);
BDFDB.DOMUtils.addClass(icon, BDFDB.disCN.noticeplatformicon);
BDFDB.DOMUtils.removeClass(icon, BDFDB.disCN.noticeicon);
notice.insertBefore(icon, noticemessage);
}
if (options.btn || options.button) notice.appendChild(BDFDB.DOMUtils.create(``));
if (options.id) notice.id = options.id.split(" ").join("");
if (options.selector) BDFDB.DOMUtils.addClass(notice, options.selector);
if (options.css) BDFDB.DOMUtils.appendLocalStyle("BDFDBcustomnotificationbar" + id, options.css);
if (options.style) notice.style = options.style;
if (options.html === true) noticemessage.innerHTML = text;
else {
var link = document.createElement("a");
var newtext = [];
for (let word of text.split(" ")) {
var encodedword = BDFDB.StringUtils.htmlEscape(word);
link.href = word;
newtext.push(link.host && link.host !== window.location.host ? `` : encodedword);
}
noticemessage.innerHTML = newtext.join(" ");
}
var type = null;
if (options.type && !document.querySelector(BDFDB.dotCNS.chatbase + BDFDB.dotCN.noticestreamer)) {
if (type = BDFDB.disCN["notice" + options.type]) BDFDB.DOMUtils.addClass(notice, type);
if (options.type == "premium") {
var noticebutton = notice.querySelector(BDFDB.dotCN.noticebutton);
if (noticebutton) BDFDB.DOMUtils.addClass(noticebutton, BDFDB.disCN.noticepremiumaction);
BDFDB.DOMUtils.addClass(noticemessage, BDFDB.disCN.noticepremiumtext);
notice.insertBefore(BDFDB.DOMUtils.create(``), noticemessage);
}
}
if (!type) {
var comp = BDFDB.ColorUtils.convert(options.color, "RGBCOMP");
if (comp) {
var fontcolor = comp[0] > 180 && comp[1] > 180 && comp[2] > 180 ? "#000" : "#FFF";
var backgroundcolor = BDFDB.ColorUtils.convert(comp, "HEX");
var filter = comp[0] > 180 && comp[1] > 180 && comp[2] > 180 ? "brightness(0%)" : "brightness(100%)";
BDFDB.DOMUtils.appendLocalStyle("BDFDBcustomnotificationbarColorCorrection" + id, `${BDFDB.dotCN.noticewrapper}[notice-id="${id}"]{background-color:${backgroundcolor} !important;}${BDFDB.dotCN.noticewrapper}[notice-id="${id}"] .notice-message {color:${fontcolor} !important;}${BDFDB.dotCN.noticewrapper}[notice-id="${id}"] ${BDFDB.dotCN.noticebutton} {color:${fontcolor} !important;border-color:${BDFDB.ColorUtils.setAlpha(fontcolor,0.25,"RGBA")} !important;}${BDFDB.dotCN.noticewrapper}[notice-id="${id}"] ${BDFDB.dotCN.noticebutton}:hover {color:${backgroundcolor} !important;background-color:${fontcolor} !important;}${BDFDB.dotCN.noticewrapper}[notice-id="${id}"] ${BDFDB.dotCN.noticedismiss} {filter:${filter} !important;}`);
}
else BDFDB.DOMUtils.addClass(notice, BDFDB.disCN.noticedefault);
}
notice.style.setProperty("height", "36px", "important");
notice.style.setProperty("min-width", "70vw", "important");
notice.style.setProperty("left", "unset", "important");
notice.style.setProperty("right", "unset", "important");
let sidemargin = ((BDFDB.DOMUtils.getWidth(document.body.firstElementChild) - BDFDB.DOMUtils.getWidth(notice))/2);
notice.style.setProperty("left", sidemargin + "px", "important");
notice.style.setProperty("right", sidemargin + "px", "important");
notice.style.setProperty("min-width", "unset", "important");
notice.style.setProperty("width", "unset", "important");
notice.style.setProperty("max-width", "calc(100vw - " + (sidemargin*2) + "px)", "important");
notice.querySelector(BDFDB.dotCN.noticedismiss).addEventListener("click", _ => {
notice.style.setProperty("overflow", "hidden", "important");
notice.style.setProperty("height", "0px", "important");
BDFDB.TimeUtils.timeout(_ => {
BDFDB.ArrayUtils.remove(NotificationBars, id);
BDFDB.DOMUtils.removeLocalStyle("BDFDBcustomnotificationbar" + id);
BDFDB.DOMUtils.removeLocalStyle("BDFDBcustomnotificationbarColorCorrection" + id);
notice.remove();
}, 500);
});
return notice;
};
BDFDB.NotificationUtils.alert = function (header, body) {
if (typeof header == "string" && typeof header == "string" && window.BdApi && typeof BdApi.alert == "function") BdApi.alert(header, body);
};
var Tooltips = [];
BDFDB.TooltipUtils = {};
BDFDB.TooltipUtils.create = function (anker, text, options = {}) {
let itemlayercontainer = document.querySelector(BDFDB.dotCN.appmount + " > * > " + BDFDB.dotCN.itemlayercontainer);
if (!itemlayercontainer || (typeof text != "string" && !BDFDB.ObjectUtils.is(options.guild)) || !Node.prototype.isPrototypeOf(anker) || !document.contains(anker)) return null;
let id = BDFDB.NumberUtils.generateId(Tooltips);
let itemlayer = BDFDB.DOMUtils.create(`
`);
itemlayercontainer.appendChild(itemlayer);
let tooltip = itemlayer.firstElementChild;
if (options.id) tooltip.id = options.id.split(" ").join("");
if (!options.type || !BDFDB.disCN["tooltip" + options.type.toLowerCase()]) options.type = "top";
BDFDB.DOMUtils.addClass(tooltip, BDFDB.disCN["tooltip" + options.type.toLowerCase()]);
tooltip.type = options.type.toLowerCase();
let fontColorIsGradient = false, customBackgroundColor = false, style = "";
if (options.style) style += options.style;
if (options.fontColor) {
fontColorIsGradient = BDFDB.ObjectUtils.is(options.fontColor);
if (!fontColorIsGradient) style = (style ? (style + " ") : "") + `color: ${BDFDB.ColorUtils.convert(options.fontColor, "RGBA")} !important;`
}
if (options.backgroundColor) {
customBackgroundColor = true;
let backgroundColorIsGradient = BDFDB.ObjectUtils.is(options.backgroundColor);
let backgroundColor = !backgroundColorIsGradient ? BDFDB.ColorUtils.convert(options.backgroundColor, "RGBA") : BDFDB.ColorUtils.createGradient(options.backgroundColor);
style = (style ? (style + " ") : "") + `background: ${backgroundColor} !important; border-color: ${backgroundColorIsGradient ? BDFDB.ColorUtils.convert(options.backgroundColor[options.type == "left" ? 100 : 0], "RGBA") : backgroundColor} !important;`;
}
if (style) tooltip.style = style;
if (typeof options.zIndex == "number") {
itemlayer.style.setProperty("z-index", options.zIndex, "important");
tooltip.style.setProperty("z-index", options.zIndex, "important");
}
if (customBackgroundColor) BDFDB.DOMUtils.addClass(tooltip, BDFDB.disCN.tooltipcustom);
else if (options.color && BDFDB.disCN["tooltip" + options.color.toLowerCase()]) BDFDB.DOMUtils.addClass(tooltip, BDFDB.disCN["tooltip" + options.color.toLowerCase()]);
else BDFDB.DOMUtils.addClass(tooltip, BDFDB.disCN.tooltipblack);
if (options.list || BDFDB.ObjectUtils.is(options.guild)) BDFDB.DOMUtils.addClass(tooltip, BDFDB.disCN.tooltiplistitem);
if (options.selector) BDFDB.DOMUtils.addClass(tooltip, options.selector);
if (BDFDB.ObjectUtils.is(options.guild)) {
let streamOwnerIds = LibraryModules.StreamUtils.getAllApplicationStreams().filter(app => app.guildId === options.guild.id).map(app => app.ownerId);
let streamOwners = streamOwnerIds.map(ownerId => LibraryModules.UserStore.getUser(ownerId)).filter(n => n);
let connectedUsers = Object.keys(LibraryModules.VoiceUtils.getVoiceStates(options.guild.id)).map(userId => !streamOwnerIds.includes(userId) && BDFDB.LibraryModules.UserStore.getUser(userId)).filter(n => n);
let tooltiptext = text || options.guild.toString();
if (fontColorIsGradient) tooltiptext = `${BDFDB.StringUtils.htmlEscape(tooltiptext)}`;
BDFDB.ReactUtils.render(BDFDB.ReactUtils.createElement(BDFDB.ReactUtils.Fragment, {
children: [
BDFDB.ReactUtils.createElement("div", {
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.tooltiprow, BDFDB.disCN.tooltiprowguildname),
children: [
BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.GuildComponents.Badge, {
guild: options.guild,
size: LibraryModules.StringUtils.cssValueToNumber(DiscordClassModules.TooltipGuild.iconSize),
className: BDFDB.disCN.tooltiprowicon
}),
BDFDB.ReactUtils.createElement("span", {
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.tooltipguildnametext, (connectedUsers.length || streamOwners.length) && BDFDB.disCN.tooltipguildnametextlimitedsize),
children: fontColorIsGradient || options.html ? BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(tooltiptext)) : tooltiptext
})
]
}),
connectedUsers.length ? BDFDB.ReactUtils.createElement("div", {
className: BDFDB.disCN.tooltiprow,
children: [
BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.SvgIcon, {
name: InternalComponents.LibraryComponents.SvgIcon.Names.SPEAKER,
className: BDFDB.disCN.tooltipactivityicon
}),
BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.UserSummaryItem, {
users: connectedUsers,
max: 6
})
]
}) : null,
streamOwners.length ? BDFDB.ReactUtils.createElement("div", {
className: BDFDB.disCN.tooltiprow,
children: [
BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.SvgIcon, {
name: InternalComponents.LibraryComponents.SvgIcon.Names.STREAM,
className: BDFDB.disCN.tooltipactivityicon
}),
BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.UserSummaryItem, {
users: streamOwners,
max: 6
})
]
}) : null
].filter(n => n)
}), tooltip);
}
else {
if (fontColorIsGradient) tooltip.innerHTML = `${BDFDB.StringUtils.htmlEscape(text)}`;
else if (options.html === true) tooltip.innerHTML = text;
else tooltip.innerText = text;
}
tooltip.appendChild(BDFDB.DOMUtils.create(``));
tooltip.anker = anker;
if (options.hide) BDFDB.DOMUtils.appendLocalStyle("BDFDBhideOtherTooltips" + id, `#app-mount ${BDFDB.dotCN.tooltip}:not([tooltip-id="${id}"]) {display: none !important;}`, itemlayercontainer);
let mouseleave = _ => {BDFDB.DOMUtils.remove(itemlayer);};
anker.addEventListener("mouseleave", mouseleave);
let observer = new MutationObserver(changes => changes.forEach(change => {
let nodes = Array.from(change.removedNodes);
if (nodes.indexOf(itemlayer) > -1 || nodes.indexOf(anker) > -1 || nodes.some(n => n.contains(anker))) {
BDFDB.ArrayUtils.remove(Tooltips, id);
observer.disconnect();
BDFDB.DOMUtils.remove(itemlayer);
BDFDB.DOMUtils.removeLocalStyle("BDFDBhideOtherTooltips" + id, itemlayercontainer);
anker.removeEventListener("mouseleave", mouseleave);
}
}));
observer.observe(document.body, {subtree:true, childList:true});
BDFDB.TooltipUtils.update(tooltip);
if (options.delay) {
BDFDB.DOMUtils.toggle(itemlayer);
BDFDB.TimeUtils.timeout(_ => {BDFDB.DOMUtils.toggle(itemlayer);}, options.delay);
}
return itemlayer;
};
BDFDB.TooltipUtils.update = function (tooltip) {
if (!Node.prototype.isPrototypeOf(tooltip)) return;
let itemlayer = BDFDB.DOMUtils.getParent(BDFDB.dotCN.itemlayer, tooltip);
if (!Node.prototype.isPrototypeOf(itemlayer)) return;
tooltip = itemlayer.querySelector(BDFDB.dotCN.tooltip);
if (!Node.prototype.isPrototypeOf(tooltip) || !Node.prototype.isPrototypeOf(tooltip.anker) || !tooltip.type) return;
var pointer = tooltip.querySelector(BDFDB.dotCN.tooltippointer);
var left, top, trects = BDFDB.DOMUtils.getRects(tooltip.anker), irects = BDFDB.DOMUtils.getRects(itemlayer), arects = BDFDB.DOMUtils.getRects(document.querySelector(BDFDB.dotCN.appmount)), positionoffsets = {height: 10, width: 10};
switch (tooltip.type) {
case "top":
top = trects.top - irects.height - positionoffsets.height + 2;
left = trects.left + (trects.width - irects.width) / 2;
break;
case "bottom":
top = trects.top + trects.height + positionoffsets.height - 2;
left = trects.left + (trects.width - irects.width) / 2;
break;
case "left":
top = trects.top + (trects.height - irects.height) / 2;
left = trects.left - irects.width - positionoffsets.width + 2;
break;
case "right":
top = trects.top + (trects.height - irects.height) / 2;
left = trects.left + trects.width + positionoffsets.width - 2;
break;
}
itemlayer.style.setProperty("top", top + "px");
itemlayer.style.setProperty("left", left + "px");
pointer.style.removeProperty("margin-left");
pointer.style.removeProperty("margin-top");
if (tooltip.type == "top" || tooltip.type == "bottom") {
if (left < 0) {
itemlayer.style.setProperty("left", "5px");
pointer.style.setProperty("margin-left", `${left - 10}px`);
}
else {
var rightmargin = arects.width - (left + irects.width);
if (rightmargin < 0) {
itemlayer.style.setProperty("left", arects.width - irects.width - 5 + "px");
pointer.style.setProperty("margin-left", `${-1*rightmargin}px`);
}
}
}
else if (tooltip.type == "left" || tooltip.type == "right") {
if (top < 0) {
itemlayer.style.setProperty("top", "5px");
pointer.style.setProperty("margin-top", `${top - 10}px`);
}
else {
var bottommargin = arects.height - (top + irects.height);
if (bottommargin < 0) {
itemlayer.style.setProperty("top", arects.height - irects.height - 5 + "px");
pointer.style.setProperty("margin-top", `${-1*bottommargin}px`);
}
}
}
};
BDFDB.ObjectUtils = {};
BDFDB.ObjectUtils.is = function (obj) {
return obj && Object.prototype.isPrototypeOf(obj) && !Array.prototype.isPrototypeOf(obj);
};
BDFDB.ObjectUtils.extract = function (obj, ...keys) {
let newobj = {};
if (BDFDB.ObjectUtils.is(obj)) for (let key of keys.flat(10).filter(n => n)) if (obj[key]) newobj[key] = obj[key];
return newobj;
};
BDFDB.ObjectUtils.exclude = function (obj, ...keys) {
let newobj = Object.assign({}, obj);
BDFDB.ObjectUtils.delete(newobj, ...keys)
return newobj;
};
BDFDB.ObjectUtils.delete = function (obj, ...keys) {
if (BDFDB.ObjectUtils.is(obj)) for (let key of keys.flat(10).filter(n => n)) delete obj[key];
};
BDFDB.ObjectUtils.sort = function (obj, sort, except) {
if (!BDFDB.ObjectUtils.is(obj)) return {};
var newobj = {};
if (sort === undefined || !sort) for (let key of Object.keys(obj).sort()) newobj[key] = obj[key];
else {
let values = [];
for (let key in obj) values.push(obj[key]);
values = BDFDB.ArrayUtils.keySort(values, sort, except);
for (let value of values) for (let key in obj) if (BDFDB.equals(value, obj[key])) {
newobj[key] = value;
break;
}
}
return newobj;
};
BDFDB.ObjectUtils.reverse = function (obj, sort) {
if (!BDFDB.ObjectUtils.is(obj)) return {};
var newobj = {};
for (let key of (sort === undefined || !sort) ? Object.keys(obj).reverse() : Object.keys(obj).sort().reverse()) newobj[key] = obj[key];
return newobj;
};
BDFDB.ObjectUtils.filter = function (obj, filter, bykey = false) {
if (!BDFDB.ObjectUtils.is(obj)) return {};
if (typeof filter != "function") return obj;
return Object.keys(obj).filter(key => filter(bykey ? key : obj[key])).reduce((newobj, key) => (newobj[key] = obj[key], newobj), {});
};
BDFDB.ObjectUtils.push = function (obj, value) {
if (BDFDB.ObjectUtils.is(obj)) obj[Object.keys(obj).length] = value;
};
BDFDB.ObjectUtils.pop = function (obj, value) {
if (BDFDB.ObjectUtils.is(obj)) {
let keys = Object.keys(obj);
if (!keys.length) return;
let value = obj[keys[keys.length-1]];
delete obj[keys[keys.length-1]];
return value;
}
};
BDFDB.ObjectUtils.map = function (obj, mapfunc) {
if (!BDFDB.ObjectUtils.is(obj)) return {};
if (typeof mapfunc != "string" && typeof mapfunc != "function") return obj;
var newobj = {};
for (let key in obj) if (BDFDB.ObjectUtils.is(obj[key])) newobj[key] = typeof mapfunc == "string" ? obj[key][mapfunc] : mapfunc(obj[key], key);
return newobj;
};
BDFDB.ObjectUtils.toArray = function (obj) {
if (!BDFDB.ObjectUtils.is(obj)) return [];
return Object.entries(obj).map(n => n[1]);
};
BDFDB.ObjectUtils.deepAssign = function (obj, ...objs) {
if (!objs.length) return obj;
let nextobj = objs.shift();
if (BDFDB.ObjectUtils.is(obj) && BDFDB.ObjectUtils.is(nextobj)) {
for (let key in nextobj) {
if (BDFDB.ObjectUtils.is(nextobj[key])) {
if (!obj[key]) Object.assign(obj, {[key]:{}});
BDFDB.ObjectUtils.deepAssign(obj[key], nextobj[key]);
}
else Object.assign(obj, {[key]:nextobj[key]});
}
}
return BDFDB.ObjectUtils.deepAssign(obj, ...objs);
};
BDFDB.ObjectUtils.isEmpty = function (obj) {
return !BDFDB.ObjectUtils.is(obj) || Object.getOwnPropertyNames(obj).length == 0;
};
BDFDB.ArrayUtils = {};
BDFDB.ArrayUtils.is = function (array) {
return array && Array.isArray(array);
};
BDFDB.ArrayUtils.sum = function (array) {
return Array.isArray(array) ? array.reduce((total, num) => total + Math.round(num), 0) : 0;
};
BDFDB.ArrayUtils.keySort = function (array, key, except) {
if (!BDFDB.ArrayUtils.is(array)) return [];
if (key == null) return array;
if (except === undefined) except = null;
return array.sort((x, y) => {
var xvalue = x[key], yvalue = y[key];
if (xvalue !== except) return xvalue < yvalue ? -1 : xvalue > yvalue ? 1 : 0;
});
};
BDFDB.ArrayUtils.numSort = function (array) {
return array.sort((x, y) => {return x < y ? -1 : x > y ? 1 : 0;});
};
BDFDB.ArrayUtils.remove = function (array, value, all = false) {
if (!BDFDB.ArrayUtils.is(array)) return [];
if (!array.includes(value)) return array;
if (!all) array.splice(array.indexOf(value), 1);
else while (array.indexOf(value) > -1) array.splice(array.indexOf(value), 1);
return array;
};
BDFDB.ArrayUtils.getAllIndexes = function (array, value) {
if (!BDFDB.ArrayUtils.is(array) && typeof array != "string") return [];
var indexes = [], index = -1;
while ((index = array.indexOf(value, index + 1)) !== -1) indexes.push(index);
return indexes;
};
BDFDB.ArrayUtils.removeCopies = function (array) {
if (!BDFDB.ArrayUtils.is(array)) return [];
return [...new Set(array)];
};
BDFDB.ModuleUtils = {};
BDFDB.ModuleUtils.cached = window.BDFDB && window.BDFDB.ModuleUtils && window.BDFDB.ModuleUtils.cached || {};
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 (m[j] && (typeof m[j] == "object" || typeof m[j] == "function") && 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 (m.default[j] && (typeof m.default[j] == "object" || typeof m.default[j] == "function") && filter(m.default[j])) return getExport ? m.default[j] : req.c[i];
}
}
};
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.findModule = function (type, cachestring, filter, getExport) {
if (!BDFDB.ObjectUtils.is(BDFDB.ModuleUtils.cached[type])) BDFDB.ModuleUtils.cached[type] = {module:{}, export:{}};
if (getExport && BDFDB.ModuleUtils.cached[type].export[cachestring]) return BDFDB.ModuleUtils.cached[type].export[cachestring];
else if (!getExport && BDFDB.ModuleUtils.cached[type].module[cachestring]) return BDFDB.ModuleUtils.cached[type].module[cachestring];
else {
var m = BDFDB.ModuleUtils.find(filter, getExport);
if (m) {
if (getExport) BDFDB.ModuleUtils.cached[type].export[cachestring] = m;
else BDFDB.ModuleUtils.cached[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;
};
var WebModulesData = {};
WebModulesData.Patchtypes = ["before", "instead", "after"];
WebModulesData.Patchmap = {
BannedCard: "BannedUser",
ChannelWindow: "Channel",
InvitationCard: "InviteRow",
InviteCard: "InviteRow",
MemberCard: "Member",
PopoutContainer: "Popout",
QuickSwitchResult: "Result",
UserProfile: "UserProfileBody",
WebhookCard: "Webhook"
};
WebModulesData.ForceObserve = [
"DirectMessage",
"GuildIcon"
];
WebModulesData.NonRender = [
"ContextMenuItem",
"DiscordTag",
"InviteModalUserRow",
"Mention",
"Message",
"MessageHeader",
"MessageTimestamp",
"NameTag",
"NowPlayingItem",
"SystemMessage",
"SimpleMessageAccessories",
"UserInfo"
];
WebModulesData.PropsFind = [
"UnavailableGuildsButton"
];
WebModulesData.MemoComponent = [
"MessageContent",
"NowPlayingHeader"
];
WebModulesData.NonPrototype = [].concat(WebModulesData.NonRender, WebModulesData.PropsFind, WebModulesData.MemoComponent, [
"ChannelTextAreaContainer"
]);
WebModulesData.LoadedInComponents = {
AutocompleteChannelResult: "LibraryComponents.AutocompleteItems.Channel",
AutocompleteUserResult: "LibraryComponents.AutocompleteItems.User",
ContextMenuItem: "NativeSubComponents.ContextMenuItem",
QuickSwitchChannelResult: "LibraryComponents.QuickSwitchItems.Channel",
QuickSwitchGroupDMResult: "LibraryComponents.QuickSwitchItems.GroupDM",
QuickSwitchGuildResult: "LibraryComponents.QuickSwitchItems.Guild",
QuickSwitchUserResult: "LibraryComponents.QuickSwitchItems.User",
};
WebModulesData.Patchfinder = {
Account: "accountinfo",
App: "app",
AppSkeleton: "app",
AppView: "appcontainer",
AuthWrapper: "loginscreen",
BannedCard: "guildsettingsbannedcard",
ChannelMember: "member",
ChannelTextAreaForm: "chatform",
ChannelWindow: "chatcontent",
DirectMessage: "guildouter",
EmojiPicker: "emojipicker",
Guild: "guildouter",
GuildIcon: "avataricon",
GuildSettingsBans: "guildsettingsbannedcard",
GuildSettingsEmoji: "guildsettingsemojicard",
GuildSettingsMembers: "guildsettingsmembercard",
GuildSidebar: "guildchannels",
I18nLoaderWrapper: "app",
InstantInviteModal: "invitemodalwrapper",
InvitationCard: "invitemodalinviterow",
InviteCard: "guildsettingsinvitecard",
PopoutContainer: "popout",
Popouts: "popouts",
PrivateChannelCall: "callcurrentcontainer",
PrivateChannelCallParticipants: "callcurrentcontainer",
PrivateChannelRecipientsInvitePopout: "searchpopoutdmaddpopout",
PrivateChannelsList: "dmchannelsscroller",
QuickSwitchChannelResult: "quickswitchresult",
QuickSwitchGuildResult: "quickswitchresult",
QuickSwitchResult: "quickswitchresult",
MemberCard: "guildsettingsmembercard",
Messages: "messages",
MessagesPopout: "messagespopout",
ModalLayer: "layermodal",
MutualGuilds: "userprofilebody",
MutualFriends: "userprofilebody",
NameTag: "nametag",
Note: "usernote",
SearchResults: "searchresultswrap",
TypingUsers: "typing",
UnreadDMs: "guildsscroller",
Upload: "uploadmodal",
UserHook: "auditloguserhook",
UserPopout: "userpopout",
UserProfile: "userprofile",
V2C_ContentColumn: "contentcolumn",
V2C_List: "_repolist",
V2C_PluginCard: "_repoheader",
V2C_ThemeCard: "_repoheader"
};
WebModulesData.GlobalModules = {};
try {WebModulesData.GlobalModules["V2C_ContentColumn"] = V2C_ContentColumn;} catch(err) {BDFDB.LogUtils.warn(`Could not find global Module "V2C_ContentColumn"`);}
try {WebModulesData.GlobalModules["V2C_List"] = V2C_List;} catch(err) {BDFDB.LogUtils.warn(`Could not find global Module "V2C_List"`);}
try {WebModulesData.GlobalModules["V2C_PluginCard"] = V2C_PluginCard;} catch(err) {BDFDB.LogUtils.warn(`Could not find global Module "V2C_PluginCard"`);}
try {WebModulesData.GlobalModules["V2C_ThemeCard"] = V2C_ThemeCard;} catch(err) {BDFDB.LogUtils.warn(`Could not find global Module "V2C_ThemeCard"`);}
BDFDB.ModuleUtils.isPatched = function (plugin, module, methodName) {
if (!plugin || !BDFDB.ObjectUtils.is(module) || !module.BDFDBpatch || !methodName) return false;
const pluginId = (typeof plugin === "string" ? plugin : plugin.name).toLowerCase();
return pluginId && module[methodName] && module[methodName].__isBDFDBpatched && module.BDFDBpatch[methodName] && BDFDB.ObjectUtils.toArray(module.BDFDBpatch[methodName]).some(patchObj => BDFDB.ObjectUtils.toArray(patchObj).some(priorityObj => Object.keys(priorityObj).includes(pluginId)));
};
BDFDB.ModuleUtils.patch = function (plugin, module, methodNames, patchMethods, forceRepatch = false) {
if (!plugin || !BDFDB.ObjectUtils.is(module) || !methodNames || !BDFDB.ObjectUtils.is(patchMethods)) return null;
patchMethods = BDFDB.ObjectUtils.filter(patchMethods, type => WebModulesData.Patchtypes.includes(type), true);
if (BDFDB.ObjectUtils.isEmpty(patchMethods)) return null;
const pluginName = typeof plugin === "string" ? plugin : plugin.name;
const pluginId = pluginName.toLowerCase();
const patchPriority = BDFDB.ObjectUtils.is(plugin) && !isNaN(plugin.patchPriority) ? (plugin.patchPriority < 0 ? 0 : (plugin.patchPriority > 10 ? 10 : Math.round(plugin.patchPriority))) : 5;
if (!BDFDB.ObjectUtils.is(module.BDFDBpatch)) module.BDFDBpatch = {};
methodNames = [methodNames].flat(10).filter(n => n);
for (let methodName of methodNames) if (module[methodName] == null || typeof module[methodName] == "function") {
let i = 0;
if (!module.BDFDBpatch[methodName] || forceRepatch && (!module[methodName] || !module[methodName].__isBDFDBpatched)) {
if (!module.BDFDBpatch[methodName]) {
module.BDFDBpatch[methodName] = {};
for (let type of WebModulesData.Patchtypes) module.BDFDBpatch[methodName][type] = {};
}
if (!module[methodName]) module[methodName] = (_ => {});
const originalMethod = module[methodName];
module.BDFDBpatch[methodName].originalMethod = originalMethod;
module[methodName] = function () {
let callInstead = false, stopCall = false;
const data = {
thisObject: this,
methodArguments: arguments,
originalMethod: originalMethod,
originalMethodName: methodName,
callOriginalMethod: _ => {if (!stopCall) data.returnValue = data.originalMethod.apply(data.thisObject, data.methodArguments)},
callOriginalMethodAfterwards: _ => {callInstead = true;},
stopOriginalMethodCall: _ => {stopCall = true;}
};
if (module.BDFDBpatch && module.BDFDBpatch[methodName]) {
for (let priority in module.BDFDBpatch[methodName].before) for (let id in BDFDB.ObjectUtils.sort(module.BDFDBpatch[methodName].before[priority])) {
BDFDB.TimeUtils.suppress(module.BDFDBpatch[methodName].before[priority][id], `"before" callback of ${methodName} in ${module.constructor ? (module.constructor.displayName || module.constructor.name) : "module"}`, module.BDFDBpatch[methodName].before[priority][id].pluginName)(data);
}
let hasInsteadPatches = BDFDB.ObjectUtils.toArray(module.BDFDBpatch[methodName].instead).some(priorityObj => !BDFDB.ObjectUtils.isEmpty(priorityObj));
if (hasInsteadPatches) for (let priority in module.BDFDBpatch[methodName].instead) for (let id in BDFDB.ObjectUtils.sort(module.BDFDBpatch[methodName].instead[priority])) {
let tempreturn = BDFDB.TimeUtils.suppress(module.BDFDBpatch[methodName].instead[priority][id], `"instead" callback of ${methodName} in ${module.constructor ? (module.constructor.displayName || module.constructor.name) : "module"}`, module.BDFDBpatch[methodName].instead[priority][id].pluginName)(data);
if (tempreturn !== undefined) data.returnValue = tempreturn;
}
if ((!hasInsteadPatches || callInstead) && !stopCall) BDFDB.TimeUtils.suppress(data.callOriginalMethod, `originalMethod of ${methodName} in ${module.constructor ? (module.constructor.displayName || module.constructor.name) : "module"}`)();
for (let priority in module.BDFDBpatch[methodName].after) for (let id in BDFDB.ObjectUtils.sort(module.BDFDBpatch[methodName].after[priority])) {
let tempreturn = BDFDB.TimeUtils.suppress(module.BDFDBpatch[methodName].after[priority][id], `"after" callback of ${methodName} in ${module.constructor ? (module.constructor.displayName || module.constructor.name) : "module"}`, module.BDFDBpatch[methodName].after[priority][id].pluginName)(data);
if (tempreturn !== undefined) data.returnValue = tempreturn;
}
}
else BDFDB.TimeUtils.suppress(data.callOriginalMethod, `originalMethod of ${methodName} in ${module.constructor ? module.constructor.displayName || module.constructor.name : "module"}`)();
callInstead = false, stopCall = false;
return methodName == "render" && data.returnValue === undefined ? null : data.returnValue;
};
for (let key of Object.keys(originalMethod)) module[methodName][key] = originalMethod[key];
if (!module[methodName].__originalFunction) {
let realOriginalMethod = originalMethod.__originalMethod || originalMethod.__originalFunction || originalMethod;
if (typeof realOriginalMethod == "function") module[methodName].__originalFunction = realOriginalMethod;
}
module[methodName].__isBDFDBpatched = true;
}
for (let type in patchMethods) if (typeof patchMethods[type] == "function") {
if (!BDFDB.ObjectUtils.is(module.BDFDBpatch[methodName][type][patchPriority])) module.BDFDBpatch[methodName][type][patchPriority] = {};
module.BDFDBpatch[methodName][type][patchPriority][pluginId] = patchMethods[type];
module.BDFDBpatch[methodName][type][patchPriority][pluginId].pluginName = pluginName;
}
}
let cancel = _ => {BDFDB.ModuleUtils.unpatch(plugin, module, methodNames);};
if (BDFDB.ObjectUtils.is(plugin)) {
if (!BDFDB.ArrayUtils.is(plugin.patchCancels)) plugin.patchCancels = [];
plugin.patchCancels.push(cancel);
}
return cancel;
};
BDFDB.ModuleUtils.unpatch = function (plugin, module, methodNames) {
if (!module && !methodNames) {
if (BDFDB.ObjectUtils.is(plugin) && BDFDB.ArrayUtils.is(plugin.patchCancels)) while (plugin.patchCancels.length) (plugin.patchCancels.pop())();
}
else {
if (!BDFDB.ObjectUtils.is(module) || !module.BDFDBpatch) return;
const pluginId = !plugin ? null : (typeof plugin === "string" ? plugin : plugin.name).toLowerCase();
if (methodNames) {
for (let methodName of [methodNames].flat(10).filter(n => n)) if (module[methodName] && module.BDFDBpatch[methodName]) unpatch(methodName, pluginId);
}
else for (let patchedMethod of module.BDFDBpatch) unpatch(patchedMethod, pluginId);
}
function unpatch (funcName, pluginId) {
for (let type of WebModulesData.Patchtypes) {
if (pluginId) for (let priority in module.BDFDBpatch[funcName][type]) {
delete module.BDFDBpatch[funcName][type][priority][pluginId];
if (BDFDB.ObjectUtils.isEmpty(module.BDFDBpatch[funcName][type][priority])) delete module.BDFDBpatch[funcName][type][priority];
}
else delete module.BDFDBpatch[funcName][type];
}
if (!BDFDB.ObjectUtils.toArray(module.BDFDBpatch[funcName]).some(patchObj => BDFDB.ObjectUtils.is(patchObj) && !BDFDB.ObjectUtils.isEmpty(patchObj))) {
module[funcName] = module.BDFDBpatch[funcName].originalMethod;
delete module.BDFDBpatch[funcName];
if (BDFDB.ObjectUtils.isEmpty(module.BDFDBpatch)) delete module.BDFDBpatch;
}
}
};
BDFDB.ModuleUtils.forceAllUpdates = function (plugin, selectedtypes) {
if (BDFDB.ObjectUtils.is(plugin) && BDFDB.ObjectUtils.is(plugin.patchedModules)) {
const app = document.querySelector(BDFDB.dotCN.app);
const bdsettings = document.querySelector("#bd-settingspane-container " + BDFDB.dotCN.scrollerwrap);
if (app) {
let filteredmodules = [], patchtypes = {};
for (let patchtype in plugin.patchedModules) for (let type in plugin.patchedModules[patchtype]) {
let methodnames = [plugin.patchedModules[patchtype][type]].flat(10).filter(n => n);
if (methodnames.includes("componentDidMount") || methodnames.includes("componentDidUpdate") || methodnames.includes("render")) {
filteredmodules.push(type);
let unmappedtype = type.split(" _ _ ")[0];
if (!patchtypes[unmappedtype]) patchtypes[unmappedtype] = [];
patchtypes[unmappedtype].push(patchtype);
}
}
selectedtypes = [selectedtypes].flat(10).filter(n => n);
if (selectedtypes.length) {
selectedtypes = selectedtypes.map(type => type && WebModulesData.Patchmap[type] ? WebModulesData.Patchmap[type] + " _ _ " + type : type);
filteredmodules = filteredmodules.filter(type => selectedtypes.indexOf(type) > -1);
}
filteredmodules = BDFDB.ArrayUtils.removeCopies(filteredmodules);
if (filteredmodules.length) {
try {
const appinsdown = BDFDB.ReactUtils.findOwner(app, {name:filteredmodules, all:true, group:true, unlimited:true});
const appinsup = BDFDB.ReactUtils.findOwner(app, {name:filteredmodules, all:true, group:true, unlimited:true, up:true});
for (let type in appinsdown) for (let ins of appinsdown[type]) InternalBDFDB.forceInitiateProcess(plugin, ins, type, patchtypes[type]);
for (let type in appinsup) for (let ins of appinsup[type]) InternalBDFDB.forceInitiateProcess(plugin, ins, type, patchtypes[type]);
if (bdsettings) {
const bdsettingsins = BDFDB.ReactUtils.findOwner(bdsettings, {name:filteredmodules, all:true, group:true, unlimited:true});
for (let type in bdsettingsins) for (let ins of bdsettingsins[type]) InternalBDFDB.forceInitiateProcess(plugin, ins, type, patchtypes[type]);
}
}
catch (err) {BDFDB.LogUtils.error("Could not force update components! " + err, plugin.name);}
}
}
}
};
InternalBDFDB.forceInitiateProcess = function (plugin, instance, type, patchtypes) {
if (!plugin || !instance || !type) return;
let methodnames = [];
for (let patchtype in plugin.patchedModules) if (plugin.patchedModules[patchtype][type]) methodnames.push(plugin.patchedModules[patchtype][type]);
methodnames = BDFDB.ArrayUtils.removeCopies(methodnames).flat(10).filter(n => n);
if (methodnames.includes("componentDidMount")) InternalBDFDB.initiateProcess(plugin, type, {instance, methodname:"componentDidMount", patchtypes});
if (methodnames.includes("render")) BDFDB.ReactUtils.forceUpdate(instance);
else if (methodnames.includes("componentDidUpdate")) InternalBDFDB.initiateProcess(plugin, type, {instance, methodname:"componentDidUpdate", patchtypes});
};
InternalBDFDB.initiateProcess = function (plugin, type, e) {
if (BDFDB.ObjectUtils.is(plugin) && !plugin.stopping && e.instance) {
plugin = plugin == BDFDB && InternalBDFDB || plugin;
type = (type.split(" _ _ ")[1] || type).replace(/[^A-z0-9]|_/g, "");
type = type.charAt(0).toUpperCase() + type.slice(1);
if (typeof plugin["process" + type] == "function") {
if (typeof e.methodname == "string" && (e.methodname.indexOf("componentDid") == 0 || e.methodname.indexOf("componentWill") == 0)) {
e.node = BDFDB.ReactUtils.findDOMNode(e.instance);
if (e.node) return plugin["process" + type](e);
else BDFDB.TimeUtils.timeout(_ => {
e.node = BDFDB.ReactUtils.findDOMNode(e.instance);
if (e.node) return plugin["process" + type](e);
});
}
else if (e.returnvalue || e.patchtypes.includes("before")) return plugin["process" + type](e);
}
}
};
InternalBDFDB.patchPlugin = function (plugin) {
if (!BDFDB.ObjectUtils.is(plugin) || !BDFDB.ObjectUtils.is(plugin.patchedModules)) return;
BDFDB.ModuleUtils.unpatch(plugin);
for (let patchtype in plugin.patchedModules) for (let type in plugin.patchedModules[patchtype]) {
if (WebModulesData.GlobalModules[type] && typeof WebModulesData.GlobalModules[type] == "function") patchInstance(WebModulesData.GlobalModules[type], type, patchtype);
else {
let unmappedtype = type.split(" _ _ ")[1] || type;
let component = WebModulesData.LoadedInComponents[type] && BDFDB.ReactUtils.getValue(InternalComponents, WebModulesData.LoadedInComponents[type]);
if (component) patchInstance(WebModulesData.NonRender.includes(unmappedtype) ? (BDFDB.ModuleUtils.find(m => m == component, false) || {}).exports : component, type, patchtype);
else {
let classname = WebModulesData.Patchfinder[unmappedtype];
let mapped = WebModulesData.Patchmap[type];
let mappedtype = mapped ? mapped + " _ _ " + type : type;
let name = mappedtype.split(" _ _ ")[0];
if (mapped) {
plugin.patchedModules[patchtype][mappedtype] = plugin.patchedModules[patchtype][type];
delete plugin.patchedModules[patchtype][type];
}
if (WebModulesData.PropsFind.includes(unmappedtype)) patchInstance((BDFDB.ModuleUtils.findByProperties(name, false) || {}).exports, mappedtype, patchtype, true);
else if (WebModulesData.NonRender.includes(unmappedtype)) patchInstance((BDFDB.ModuleUtils.findByName(name, false) || {}).exports, mappedtype, patchtype, true);
else if (WebModulesData.MemoComponent.includes(unmappedtype)) patchInstance((BDFDB.ModuleUtils.findByName(name, false) || {exports:{}}).exports.default, mappedtype, patchtype, true);
else if (!classname) patchInstance(BDFDB.ModuleUtils.findByName(name), mappedtype, patchtype);
else if (DiscordClasses[classname]) checkForInstance(classname, mappedtype, patchtype, WebModulesData.ForceObserve.includes(unmappedtype));
}
}
}
function patchInstance(instance, type, patchtype, exported) {
if (instance) {
let name = type.split(" _ _ ")[0];
instance = instance._reactInternalFiber && instance._reactInternalFiber.type ? instance._reactInternalFiber.type : instance;
instance = exported || InternalBDFDB.isInstanceCorrect(instance, name) || WebModulesData.LoadedInComponents[type] ? instance : (BDFDB.ReactUtils.findConstructor(instance, name) || BDFDB.ReactUtils.findConstructor(instance, name, {up:true}));
if (instance) {
instance = instance._reactInternalFiber && instance._reactInternalFiber.type ? instance._reactInternalFiber.type : instance;
let patchMethods = {};
patchMethods[patchtype] = e => {return InternalBDFDB.initiateProcess(plugin, type, {instance:window != e.thisObject ? e.thisObject : {props:e.methodArguments[0]}, returnvalue:e.returnValue, methodname:e.originalMethodName, patchtypes:[patchtype]})};
BDFDB.ModuleUtils.patch(plugin, WebModulesData.NonPrototype.includes(name) ? instance : instance.prototype, plugin.patchedModules[patchtype][type], patchMethods);
}
}
}
function checkForInstance(classname, type, patchtype, forceobserve) {
const app = document.querySelector(BDFDB.dotCN.app), bdsettings = document.querySelector("#bd-settingspane-container " + BDFDB.dotCN.scrollerwrap);
let instancefound = false;
if (!forceobserve) {
if (app) {
let appins = BDFDB.ReactUtils.findConstructor(app, type, {unlimited:true}) || BDFDB.ReactUtils.findConstructor(app, type, {unlimited:true, up:true});
if (appins && (instancefound = true)) patchInstance(appins, type, patchtype);
}
if (!instancefound && bdsettings) {
let bdsettingsins = BDFDB.ReactUtils.findConstructor(bdsettings, type, {unlimited:true});
if (bdsettingsins && (instancefound = true)) patchInstance(bdsettingsins, type, patchtype);
}
}
if (!instancefound) {
let found = false, disclass = BDFDB.disCN[classname], dotclass = BDFDB.dotCN[classname];
for (let ele of document.querySelectorAll(dotclass)) {
let ins = BDFDB.ReactUtils.getInstance(ele);
if (isCorrectInstance(ins, type)) {
found = true;
patchInstance(ins, type, patchtype);
BDFDB.ModuleUtils.forceAllUpdates(plugin, type);
break;
}
}
if (!found) {
let instanceobserver = new MutationObserver(cs => {cs.forEach(c => {c.addedNodes.forEach(n => {
if (found || !n || !n.tagName) return;
let ele = null;
if ((ele = BDFDB.DOMUtils.containsClass(n, disclass) ? n : n.querySelector(dotclass)) != null) {
let ins = BDFDB.ReactUtils.getInstance(ele);
if (isCorrectInstance(ins, type)) {
found = true;
instanceobserver.disconnect();
patchInstance(ins, type, patchtype);
BDFDB.ModuleUtils.forceAllUpdates(plugin, type);
}
}
});});});
BDFDB.ObserverUtils.connect(plugin, BDFDB.dotCN.appmount, {name:"checkForInstanceObserver", instance:instanceobserver, multi:true
}, {childList:true, subtree:true});
}
}
}
function isCorrectInstance(instance, name) {
if (!instance) return false;
instance = instance._reactInternalFiber && instance._reactInternalFiber.type ? instance._reactInternalFiber.type : instance;
instance = InternalBDFDB.isInstanceCorrect(instance, name) ? instance : (BDFDB.ReactUtils.findConstructor(instance, name) || BDFDB.ReactUtils.findConstructor(instance, name, {up:true}));
return !!instance;
}
};
InternalBDFDB.isInstanceCorrect = function (instance, name) {
return instance && ((instance.type && (instance.type.render && instance.type.render.displayName === name || instance.type.displayName === name || instance.type.name === name || instance.type === name)) || instance.render && (instance.render.displayName === name || instance.render.name === name) || instance.displayName == name || instance.name === name);
};
InternalBDFDB.addContextListeners = function (plugin) {
for (let type of ComponentTypeData.NormalContextMenus) if (typeof plugin[`on${type}`] === "function") InternalBDFDB.patchContextMenuPlugin(plugin, type, InternalComponents.LibraryComponents.ContextMenus[type]);
for (let type of ComponentTypeData.FluxContextMenus) if (typeof plugin[`on${type}`] === "function") {
if (BDFDB.InternalData.componentPatchQueries[type].module) InternalBDFDB.patchContextMenuPlugin(plugin, type, BDFDB.InternalData.componentPatchQueries[type].module);
else {
BDFDB.InternalData.componentPatchQueries[type].query.push(plugin);
BDFDB.InternalData.componentPatchQueries[type].query.sort((x, y) => {return x.name < y.name ? -1 : x.name > y.name ? 1 : 0;});
}
}
for (let type of ComponentTypeData.QueuedComponents) if (typeof plugin[`on${type}`] === "function") {
if (BDFDB.InternalData.componentPatchQueries[type].module) InternalBDFDB.patchExportedContextMenuPlugin(plugin, type, BDFDB.InternalData.componentPatchQueries[type].module);
else {
BDFDB.InternalData.componentPatchQueries[type].query.push(plugin);
BDFDB.InternalData.componentPatchQueries[type].query.sort((x, y) => {return x.name < y.name ? -1 : x.name > y.name ? 1 : 0;});
}
}
};
InternalBDFDB.patchContextMenuPlugin = function (plugin, type, module) {
if (module && module.prototype) BDFDB.ModuleUtils.patch(plugin, module.prototype, "render", {after: e => {
if (e.thisObject && e.returnValue && typeof plugin[`on${type}`] === "function") plugin[`on${type}`]({instance:e.thisObject, returnvalue:e.returnValue, methodname:"render"});
}});
};
InternalBDFDB.patchExportedContextMenuPlugin = function (plugin, type, module) {
if (module && module.exports) BDFDB.ModuleUtils.patch(plugin, module.exports, "default", {after: e => {
if (e.returnValue && typeof plugin[`on${type}`] === "function") plugin[`on${type}`]({instance:{props:e.methodArguments[0]}, returnvalue:e.returnValue, methodname:"default"});
}});
};
InternalBDFDB.executeExtraPatchedPatches = function (type, e) {
if (BDFDB.ObjectUtils.is(BDFDB.InternalData.componentPatchQueries[type]) && BDFDB.ArrayUtils.is(BDFDB.InternalData.componentPatchQueries[type].query)) for (let plugin of BDFDB.InternalData.componentPatchQueries[type].query) if (e.returnvalue && typeof plugin[`on${type}`] === "function") plugin[`on${type}`](e);
};
InternalBDFDB.patchContextMenuLib = function (module, repatch) {
if (module && module.prototype) {
BDFDB.ModuleUtils.patch(BDFDB, module.prototype, "render", {after: e => {
if (e.thisObject.props.BDFDBcontextMenu && e.thisObject.props.children && e.returnValue && e.returnValue.props) {
e.returnValue.props.children = e.thisObject.props.children;
delete e.thisObject.props.value;
delete e.thisObject.props.children;
delete e.thisObject.props.BDFDBcontextMenu;
}
if (repatch) {
let newmodule = BDFDB.ReactUtils.getValue(e, "thisObject._reactInternalFiber.child.type");
if (newmodule && newmodule.displayName && BDFDB.InternalData.componentPatchQueries[newmodule.displayName] && !BDFDB.InternalData.componentPatchQueries[newmodule.displayName].module) {
BDFDB.InternalData.componentPatchQueries[newmodule.displayName].module = newmodule;
InternalBDFDB.patchContextMenuLib(newmodule, false);
while (BDFDB.InternalData.componentPatchQueries[newmodule.displayName].query.length) InternalBDFDB.patchContextMenuPlugin(BDFDB.InternalData.componentPatchQueries[newmodule.displayName].query.pop(), newmodule.displayName, newmodule);
}
}
}});
}
};
InternalBDFDB.patchExportedContextMenuLib = function (menu, type, shouldCloseOnPatch) {
let module = BDFDB.ModuleUtils.find(m => m == menu.type, false);
if (module && module.exports && module.exports.default) {
if (!InternalComponents.LibraryComponents.ContextMenus[type]) {
InternalComponents.LibraryComponents.ContextMenus[type] = module.exports.default;
BDFDB.LibraryComponents.ContextMenus[type] = module.exports.default;
}
if (!InternalComponents.LibraryComponents.ContextMenus._Exports[type]) {
InternalComponents.LibraryComponents.ContextMenus._Exports[type] = module.exports;
BDFDB.LibraryComponents.ContextMenus._Exports[type] = module.exports;
}
if (BDFDB.InternalData.componentPatchQueries[type] && !BDFDB.InternalData.componentPatchQueries[type].module) {
BDFDB.InternalData.componentPatchQueries[type].module = module;
while (BDFDB.InternalData.componentPatchQueries[type].query.length) InternalBDFDB.patchExportedContextMenuPlugin(BDFDB.InternalData.componentPatchQueries[type].query.pop(), type, module);
let close = shouldCloseOnPatch && BDFDB.ReactUtils.getValue(menu, "memoizedProps.onClose");
if (typeof close == "function") close();
}
if (!module.exports.default.displayName) module.exports.default.displayName = type;
}
};
InternalBDFDB.getContextMenuType = function (menutype, component) {
if (menutype) {
if (menutype == "MessageContextMenu" && component && component.type != InternalComponents.LibraryComponents.ContextMenus.MessageContextMenu) return "MessageOptionContextMenu";
else if (menutype.endsWith("ContextMenu")) return menutype;
else if (InternalComponents.LibraryComponents.ContextMenus._Types.includes(menutype)) {
if (menutype.indexOf("USER_") == 0) return "UserContextMenu";
else if (menutype.indexOf("CHANNEL_") == 0) return "ChannelContextMenu";
else if (menutype.indexOf("GUILD_") == 0) return "GuildContextMenu";
else if (menutype.indexOf("MESSAGE_") == 0) return "MessageContextMenu";
}
}
return null;
};
BDFDB.DiscordConstants = BDFDB.ModuleUtils.findByProperties("Permissions", "ActivityTypes");
var DiscordObjects = {};
DiscordObjects.Channel = BDFDB.ModuleUtils.findByPrototypes("getRecipientId", "isManaged", "getGuildId");
DiscordObjects.Guild = BDFDB.ModuleUtils.findByPrototypes("getIconURL", "getMaxEmojiSlots", "getRole");
DiscordObjects.Invite = BDFDB.ModuleUtils.findByPrototypes("getExpiresAt", "isExpired");
DiscordObjects.Message = BDFDB.ModuleUtils.findByPrototypes("getReaction", "getAuthorName", "getChannelId");
DiscordObjects.Messages = BDFDB.ModuleUtils.findByPrototypes("jumpToMessage", "hasAfterCached", "forEach");
DiscordObjects.Timestamp = BDFDB.ModuleUtils.findByPrototypes("add", "dayOfYear", "hasAlignedHourOffset");
DiscordObjects.User = BDFDB.ModuleUtils.findByPrototypes("hasFlag", "isLocalBot", "isClaimed");
BDFDB.DiscordObjects = Object.assign({}, DiscordObjects);
var LibraryRequires = {};
for (let name of ["child_process", "electron", "fs", "path", "process", "request"]) {
try {LibraryRequires[name] = require(name);} catch (err) {}
}
BDFDB.LibraryRequires = Object.assign({}, LibraryRequires);
var LibraryModules = {};
LibraryModules.AckUtils = BDFDB.ModuleUtils.findByProperties("localAck", "bulkAck");
LibraryModules.APIUtils = BDFDB.ModuleUtils.findByProperties("getAPIBaseURL");
LibraryModules.AnalyticsUtils = BDFDB.ModuleUtils.findByProperties("isThrottled", "track");
LibraryModules.AnimationUtils = BDFDB.ModuleUtils.findByProperties("spring", "decay");
LibraryModules.BadgeUtils = BDFDB.ModuleUtils.findByProperties("getBadgeCountString", "getBadgeWidthForValue");
LibraryModules.CategoryCollapseStore = BDFDB.ModuleUtils.findByProperties("getCollapsedCategories", "isCollapsed");
LibraryModules.CategoryCollapseUtils = BDFDB.ModuleUtils.findByProperties("categoryCollapse", "categoryCollapseAll");
LibraryModules.ChannelStore = BDFDB.ModuleUtils.findByProperties("getChannel", "getChannels");
LibraryModules.ColorUtils = BDFDB.ModuleUtils.findByProperties("hex2int", "hex2rgb");
LibraryModules.ContextMenuUtils = BDFDB.ModuleUtils.findByProperties("closeContextMenu", "openContextMenu");
LibraryModules.CopyLinkUtils = BDFDB.ModuleUtils.findByProperties("SUPPORTS_COPY", "copy");
LibraryModules.CurrentUserStore = BDFDB.ModuleUtils.findByProperties("getCurrentUser");
LibraryModules.CurrentVoiceUtils = BDFDB.ModuleUtils.findByProperties("getAveragePing", "isConnected");
LibraryModules.DirectMessageStore = BDFDB.ModuleUtils.findByProperties("getPrivateChannelIds", "getPrivateChannelTimestamps");
LibraryModules.DirectMessageUnreadStore = BDFDB.ModuleUtils.findByProperties("getUnreadPrivateChannelIds");
LibraryModules.DispatchApiUtils = BDFDB.ModuleUtils.findByProperties("dirtyDispatch", "isDispatching");
LibraryModules.DispatchUtils = BDFDB.ModuleUtils.findByProperties("ComponentDispatch");
LibraryModules.DirectMessageUtils = BDFDB.ModuleUtils.findByProperties("addRecipient", "openPrivateChannel");
LibraryModules.EmojiUtils = BDFDB.ModuleUtils.findByProperties("translateInlineEmojiToSurrogates", "translateSurrogatesToInlineEmoji");
LibraryModules.FriendUtils = BDFDB.ModuleUtils.findByProperties("getFriendIDs", "getRelationships");
LibraryModules.FolderStore = BDFDB.ModuleUtils.findByProperties("getGuildFolderById", "getFlattenedGuilds");
LibraryModules.FolderUtils = BDFDB.ModuleUtils.findByProperties("isFolderExpanded", "getExpandedFolders");
LibraryModules.GuildBoostUtils = BDFDB.ModuleUtils.findByProperties("getTierName", "getUserLevel");
LibraryModules.GuildChannelStore = BDFDB.ModuleUtils.findByProperties("getChannels", "getDefaultChannel");
LibraryModules.GuildEmojiStore = BDFDB.ModuleUtils.findByProperties("getGuildEmoji", "getDisambiguatedEmojiContext");
LibraryModules.GuildSettingsUtils = BDFDB.ModuleUtils.findByProperties("updateChannelOverrideSettings", "updateNotificationSettings");
LibraryModules.GuildStore = BDFDB.ModuleUtils.findByProperties("getGuild", "getGuilds");
LibraryModules.GuildUnavailableStore = BDFDB.ModuleUtils.findByProperties("isUnavailable", "totalUnavailableGuilds");
LibraryModules.GuildUtils = BDFDB.ModuleUtils.findByProperties("transitionToGuildSync");
LibraryModules.HistoryUtils = BDFDB.ModuleUtils.findByProperties("transitionTo", "replaceWith", "getHistory");;
LibraryModules.IconUtils = BDFDB.ModuleUtils.findByProperties("getGuildIconURL", "getGuildBannerURL");
LibraryModules.InviteUtils = BDFDB.ModuleUtils.findByProperties("acceptInvite", "createInvite");
LibraryModules.KeyCodeUtils = Object.assign({}, BDFDB.ModuleUtils.findByProperties("toCombo", "keyToCode"));
LibraryModules.KeyCodeUtils.getString = function (keyarray) {
return LibraryModules.KeyCodeUtils.toString([keyarray].flat(10).filter(n => n).map(keycode => [BDFDB.DiscordConstants.KeyboardDeviceTypes.KEYBOARD_KEY, keycode, BDFDB.DiscordConstants.KeyboardEnvs.BROWSER]), true);
};
LibraryModules.KeyEvents = BDFDB.ModuleUtils.findByProperties("aliases", "code", "codes");
LibraryModules.LanguageStore = BDFDB.ModuleUtils.findByProperties("getLanguages", "Messages");
LibraryModules.LastChannelStore = BDFDB.ModuleUtils.findByProperties("getLastSelectedChannelId");
LibraryModules.LastGuildStore = BDFDB.ModuleUtils.findByProperties("getLastSelectedGuildId");
LibraryModules.LoginUtils = BDFDB.ModuleUtils.findByProperties("login", "logout");
LibraryModules.MemberStore = BDFDB.ModuleUtils.findByProperties("getMember", "getMembers");
LibraryModules.MessagePinUtils = BDFDB.ModuleUtils.findByProperties("pinMessage", "unpinMessage");
LibraryModules.MessageStore = BDFDB.ModuleUtils.findByProperties("getMessage", "getMessages");
LibraryModules.MessageUtils = BDFDB.ModuleUtils.findByProperties("receiveMessage", "editMessage");
LibraryModules.ModalUtils = BDFDB.ModuleUtils.findByProperties("openModal", "hasModalOpen");
LibraryModules.MutedUtils = BDFDB.ModuleUtils.findByProperties("isGuildOrCategoryOrChannelMuted");
LibraryModules.NoteStore = BDFDB.ModuleUtils.findByProperties("getNotes", "getNote");
LibraryModules.NotificationSettingsUtils = BDFDB.ModuleUtils.findByProperties("setDesktopType", "setTTSType");
LibraryModules.NotificationSettingsStore = BDFDB.ModuleUtils.findByProperties("getDesktopType", "getTTSType");
LibraryModules.PlatformUtils = BDFDB.ModuleUtils.findByProperties("isWindows", "isLinux");
LibraryModules.PermissionUtils = BDFDB.ModuleUtils.findByProperties("getChannelPermissions", "canUser");
LibraryModules.PermissionRoleUtils = BDFDB.ModuleUtils.findByProperties("getHighestRole", "can");
LibraryModules.QuoteUtils = BDFDB.ModuleUtils.findByProperties("canQuote", "createQuotedText");
LibraryModules.ReactionUtils = BDFDB.ModuleUtils.findByProperties("addReaction", "removeReaction");
LibraryModules.SearchPageUtils = BDFDB.ModuleUtils.findByProperties("searchNextPage", "searchPreviousPage");
LibraryModules.SelectChannelUtils = BDFDB.ModuleUtils.findByProperties("selectChannel", "selectPrivateChannel");
LibraryModules.SettingsUtils = BDFDB.ModuleUtils.findByProperties("updateRemoteSettings", "updateLocalSettings");
LibraryModules.SoundUtils = BDFDB.ModuleUtils.findByProperties("playSound", "createSound");
LibraryModules.SpellCheckUtils = BDFDB.ModuleUtils.findByProperties("learnWord", "toggleSpellcheck");
LibraryModules.SlateUtils = BDFDB.ModuleUtils.findByProperties("serialize", "deserialize");
LibraryModules.SlateSelectionUtils = BDFDB.ModuleUtils.findByProperties("serialize", "serializeSelection");
LibraryModules.StateStoreUtils = BDFDB.ModuleUtils.findByProperties("useStateFromStores", "useStateFromStoresArray");
LibraryModules.StatusMetaUtils = BDFDB.ModuleUtils.findByProperties("getApplicationActivity", "getStatus");
LibraryModules.StoreChangeUtils = BDFDB.ModuleUtils.findByProperties("get", "set", "clear", "remove");
LibraryModules.StreamUtils = BDFDB.ModuleUtils.findByProperties("getStreamForUser", "getActiveStream");
LibraryModules.StringUtils = BDFDB.ModuleUtils.findByProperties("cssValueToNumber", "upperCaseFirstChar");
LibraryModules.UnreadGuildUtils = BDFDB.ModuleUtils.findByProperties("hasUnread", "getUnreadGuilds");
LibraryModules.UnreadChannelUtils = BDFDB.ModuleUtils.findByProperties("getUnreadCount", "getOldestUnreadMessageId");
LibraryModules.UploadUtils = BDFDB.ModuleUtils.findByProperties("upload", "instantBatchUpload");
LibraryModules.UserNameUtils = BDFDB.ModuleUtils.findByProperties("getName", "getNickname");
LibraryModules.UserStore = BDFDB.ModuleUtils.findByProperties("getUser", "getUsers");
LibraryModules.Utilities = BDFDB.ModuleUtils.findByProperties("flatMap", "cloneDeep");
LibraryModules.VoiceUtils = BDFDB.ModuleUtils.findByProperties("getAllVoiceStates", "getVoiceStatesForChannel");
LibraryModules.ZoomUtils = BDFDB.ModuleUtils.findByProperties("setZoom", "setFontSize");
BDFDB.LibraryModules = Object.assign({}, LibraryModules);
LibraryModules.React = BDFDB.ModuleUtils.findByProperties("createElement", "cloneElement");
LibraryModules.ReactDOM = BDFDB.ModuleUtils.findByProperties("render", "findDOMNode");
BDFDB.ReactUtils = Object.assign({}, LibraryModules.React, LibraryModules.ReactDOM);
BDFDB.ReactUtils.childrenToArray = function (parent) {
if (parent && parent.props && parent.props.children && !BDFDB.ArrayUtils.is(parent.props.children)) {
var child = parent.props.children;
parent.props.children = [];
parent.props.children.push(child);
}
return parent.props.children;
}
BDFDB.ReactUtils.createElement = function (component, props) {
if (component && component.defaultProps) for (let key in component.defaultProps) if (props[key] == null) props[key] = component.defaultProps[key];
try {return LibraryModules.React.createElement(component || "div", props || {}) || null;}
catch (err) {BDFDB.LogUtils.error("Could not create react element! " + err);}
return null;
};
BDFDB.ReactUtils.elementToReact = function (node, ref) {
if (BDFDB.ReactUtils.isValidElement(node)) return node;
else if (!Node.prototype.isPrototypeOf(node)) return null;
else if (node.nodeType == Node.TEXT_NODE) return node.nodeValue;
let attributes = {}, importantStyles = [];
if (typeof ref == "function") attributes.ref = ref;
for (let attr of node.attributes) attributes[attr.name] = attr.value;
if (node.attributes.style) attributes.style = BDFDB.ObjectUtils.filter(node.style, n => node.style[n] && isNaN(parseInt(n)), true);
attributes.children = [];
if (node.style && node.style.cssText) for (let propstr of node.style.cssText.split(";")) if (propstr.endsWith("!important")) {
let key = propstr.split(":")[0];
let camelprop = key.replace(/-([a-z]?)/g, (m, g) => g.toUpperCase());
if (attributes.style[camelprop] != null) importantStyles.push(key);
}
for (let child of node.childNodes) attributes.children.push(BDFDB.ReactUtils.elementToReact(child));
let reactEle = BDFDB.ReactUtils.createElement(node.tagName, attributes);
BDFDB.ReactUtils.forceStyle(reactEle, importantStyles);
return reactEle;
};
BDFDB.ReactUtils.forceStyle = function (reactEle, styles) {
if (!BDFDB.ReactUtils.isValidElement(reactEle) || !BDFDB.ObjectUtils.is(reactEle.props.style) || !BDFDB.ArrayUtils.is(styles) || !styles.length) return;
let ref = reactEle.ref;
reactEle.ref = instance => {
if (typeof ref == "function") ref(instance);
let node = BDFDB.ReactUtils.findDOMNode(instance);
if (Node.prototype.isPrototypeOf(node)) for (let key of styles) {
let propValue = reactEle.props.style[key.replace(/-([a-z]?)/g, (m, g) => g.toUpperCase())];
if (propValue != null) node.style.setProperty(key, propValue, "important");
}
};
};
BDFDB.ReactUtils.findChildren = function (nodeOrInstance, config) {
if (!nodeOrInstance || !BDFDB.ObjectUtils.is(config) || !config.name && !config.key && !config.props && !config.filter) return [null, -1];
var instance = Node.prototype.isPrototypeOf(nodeOrInstance) ? BDFDB.ReactUtils.getInstance(nodeOrInstance) : nodeOrInstance;
if (!BDFDB.ObjectUtils.is(instance) && !BDFDB.ArrayUtils.is(instance)) return [null, -1];
config.name = config.name && [config.name].flat().filter(n => n);
config.key = config.key && [config.key].flat().filter(n => n);
config.props = config.props && [config.props].flat().filter(n => n);
config.filter = typeof config.filter == "function" && config.filter;
var parent = firstarray = instance;
while (!BDFDB.ArrayUtils.is(firstarray) && firstarray.props && firstarray.props.children) firstarray = firstarray.props.children;
if (!BDFDB.ArrayUtils.is(firstarray)) {
if (parent && parent.props) {
parent.props.children = [parent.props.children];
firstarray = parent.props.children;
}
else firstarray = [];
}
return getChildren(instance);
function getChildren (children) {
var result = [firstarray, -1];
if (!children) return result;
if (!BDFDB.ArrayUtils.is(children)) {
if (check(children)) result = found(children);
else if (children.props && children.props.children) {
parent = children;
result = getChildren(children.props.children);
}
}
else {
for (let i = 0; result[1] == -1 && i < children.length; i++) if (children[i]) {
if (BDFDB.ArrayUtils.is(children[i])) {
parent = children;
result = getChildren(children[i]);
}
else if (check(children[i])) {
parent = children;
result = found(children[i]);
}
else if (children[i].props && children[i].props.children) {
parent = children[i];
result = getChildren(children[i].props.children);
}
}
}
return result;
}
function found (child) {
if (BDFDB.ArrayUtils.is(parent)) return [parent, parent.indexOf(child)];
else {
parent.props.children = [];
parent.props.children.push(child);
return [parent.props.children, 0];
}
}
function check (instance) {
if (!instance) return false;
let props = instance.stateNode ? instance.stateNode.props : instance.props;
return instance.type && config.name && config.name.some(name => InternalBDFDB.isInstanceCorrect(instance, name)) || config.key && config.key.some(key => instance.key == key) || props && config.props && config.props.every(prop => BDFDB.ArrayUtils.is(prop) ? (BDFDB.ArrayUtils.is(prop[1]) ? prop[1].some(checkvalue => propCheck(props, prop[0], checkvalue)) : propCheck(props, prop[0], prop[1])) : props[prop] !== undefined) || config.filter && config.filter(instance);
}
function propCheck (props, key, value) {
return key != null && props[key] != null && value != null && (key == "className" ? (" " + props[key] + " ").indexOf(" " + value + " ") > -1 : BDFDB.equals(props[key], value));
}
};
BDFDB.ReactUtils.findConstructor = function (nodeOrInstance, types, config = {}) {
if (!BDFDB.ObjectUtils.is(config)) return null;
if (!nodeOrInstance || !types) return config.all ? (config.group ? {} : []) : null;
var instance = Node.prototype.isPrototypeOf(nodeOrInstance) ? BDFDB.ReactUtils.getInstance(nodeOrInstance) : nodeOrInstance;
if (!BDFDB.ObjectUtils.is(instance)) return config.all ? (config.group ? {} : []) : null;
types = types && [types].flat(10).filter(n => typeof n == "string");
if (!types.length) return config.all ? (config.group ? {} : []) : null;;
var depth = -1;
var start = performance.now();
var maxdepth = config.unlimited ? 999999999 : (config.depth === undefined ? 30 : config.depth);
var maxtime = config.unlimited ? 999999999 : (config.time === undefined ? 150 : config.time);
var whitelist = config.up ? {return:true, sibling:true, default:true, _reactInternalFiber:true} : {child:true, sibling:true, default:true, _reactInternalFiber:true};
var foundconstructors = config.group ? {} : [];
var singleconstructor = getConstructor(instance);
if (config.all) {
for (let i in foundconstructors) {
if (config.group) for (let j in foundconstructors[i]) delete foundconstructors[i][j].BDFDBreactSearch;
else delete foundconstructors[i].BDFDBreactSearch;
}
return foundconstructors;
}
else return singleconstructor;
function getConstructor (instance) {
depth++;
var result = undefined;
if (instance && !Node.prototype.isPrototypeOf(instance) && !BDFDB.ReactUtils.getInstance(instance) && depth < maxdepth && performance.now() - start < maxtime) {
if (instance.type && types.some(name => (instance.type.render && instance.type.render.displayName || instance.type.displayName || instance.type.name) === name.split(" _ _ ")[0])) {
if (config.all === undefined || !config.all) result = instance.type;
else if (config.all) {
if (!instance.type.BDFDBreactSearch) {
instance.type.BDFDBreactSearch = true;
if (config.group) {
if (instance.type && (instance.type.render && instance.type.render.displayName || instance.type.displayName || instance.type.name)) {
let group = config.name.find(n => (instance.type.render && instance.type.render.displayName || instance.type.displayName || instance.type.name || instance.type).split(" _ _ ")[0] == n) || "Default";
if (!BDFDB.ArrayUtils.is(foundinstances[group])) foundinstances[group] = [];
foundinstances[group].push(instance.stateNode);
}
}
else foundinstances.push(instance.type);
}
}
}
if (result === undefined) {
let keys = Object.getOwnPropertyNames(instance);
for (let i = 0; result === undefined && i < keys.length; i++) {
let key = keys[i];
if (key && whitelist[key] && (typeof instance[key] === "object" || typeof instance[key] === "function")) result = getConstructor(instance[key]);
}
}
}
depth--;
return result;
}
};
BDFDB.ReactUtils.findDOMNode = function (instance) {
if (Node.prototype.isPrototypeOf(instance)) return instance;
if (!instance || !instance.updater || typeof instance.updater.isMounted !== "function" || !instance.updater.isMounted(instance)) return null;
var node = LibraryModules.ReactDOM.findDOMNode(instance) || BDFDB.ReactUtils.getValue(instance, "child.stateNode");
return Node.prototype.isPrototypeOf(node) ? node : null;
};
BDFDB.ReactUtils.findOwner = function (nodeOrInstance, config) {
if (!BDFDB.ObjectUtils.is(config)) return null;
if (!nodeOrInstance || !config.name && !config.key && !config.props) return config.all ? (config.group ? {} : []) : null;
var instance = Node.prototype.isPrototypeOf(nodeOrInstance) ? BDFDB.ReactUtils.getInstance(nodeOrInstance) : nodeOrInstance;
if (!BDFDB.ObjectUtils.is(instance)) return config.all ? (config.group ? {} : []) : null;
config.name = config.name && [config.name].flat().filter(n => n);
config.key = config.key && [config.key].flat().filter(n => n);
config.props = config.props && [config.props].flat().filter(n => n);
var depth = -1;
var start = performance.now();
var maxdepth = config.unlimited ? 999999999 : (config.depth === undefined ? 30 : config.depth);
var maxtime = config.unlimited ? 999999999 : (config.time === undefined ? 150 : config.time);
var whitelist = config.up ? {return:true, sibling:true, _reactInternalFiber:true} : {child:true, sibling:true, _reactInternalFiber:true};
var foundinstances = config.group ? {} : [];
var singleinstance = getOwner(instance);
if (config.all) {
for (let i in foundinstances) {
if (config.group) for (let j in foundinstances[i]) delete foundinstances[i][j].BDFDBreactSearch;
else delete foundinstances[i].BDFDBreactSearch;
}
return foundinstances;
}
else return singleinstance;
function getOwner (instance) {
depth++;
var result = undefined;
if (instance && !Node.prototype.isPrototypeOf(instance) && !BDFDB.ReactUtils.getInstance(instance) && depth < maxdepth && performance.now() - start < maxtime) {
let props = instance.stateNode ? instance.stateNode.props : instance.props;
if (instance.stateNode && !Node.prototype.isPrototypeOf(instance.stateNode) && (instance.type && config.name && config.name.some(name => InternalBDFDB.isInstanceCorrect(instance, name.split(" _ _ ")[0])) || config.key && config.key.some(key => instance.key == key) || props && config.props && config.props.every(prop => BDFDB.ArrayUtils.is(prop) ? (BDFDB.ArrayUtils.is(prop[1]) ? prop[1].some(checkvalue => BDFDB.equals(props[prop[0]], checkvalue)) : BDFDB.equals(props[prop[0]], prop[1])) : props[prop] !== undefined))) {
if (config.all === undefined || !config.all) result = instance.stateNode;
else if (config.all) {
if (!instance.stateNode.BDFDBreactSearch) {
instance.stateNode.BDFDBreactSearch = true;
if (config.group) {
if (config.name && instance.type && (instance.type.render && instance.type.render.displayName || instance.type.displayName || instance.type.name || instance.type)) {
let group = config.name.find(n => (instance.type.render && instance.type.render.displayName || instance.type.displayName || instance.type.name || instance.type).split(" _ _ ")[0] == n) || "Default";
if (!BDFDB.ArrayUtils.is(foundinstances[group])) foundinstances[group] = [];
foundinstances[group].push(instance.stateNode);
}
}
else foundinstances.push(instance.stateNode);
}
}
}
if (result === undefined) {
let keys = Object.getOwnPropertyNames(instance);
for (let i = 0; result === undefined && i < keys.length; i++) {
let key = keys[i];
if (key && whitelist[key] && (typeof instance[key] === "object" || typeof instance[key] === "function")) result = getOwner(instance[key]);
}
}
}
depth--;
return result;
}
};
BDFDB.ReactUtils.findProps = function (nodeOrInstance, config) {
if (!BDFDB.ObjectUtils.is(config)) return null;
if (!nodeOrInstance || !config.name && !config.key) return null;
var instance = Node.prototype.isPrototypeOf(nodeOrInstance) ? BDFDB.ReactUtils.getInstance(nodeOrInstance) : nodeOrInstance;
if (!BDFDB.ObjectUtils.is(instance)) return null;
config.name = config.name && [config.name].flat().filter(n => n);
config.key = config.key && [config.key].flat().filter(n => n);
var depth = -1;
var start = performance.now();
var maxdepth = config.unlimited ? 999999999 : (config.depth === undefined ? 30 : config.depth);
var maxtime = config.unlimited ? 999999999 : (config.time === undefined ? 150 : config.time);
var whitelist = config.up ? {return:true, sibling:true, _reactInternalFiber:true} : {child:true, sibling:true, _reactInternalFiber:true};
return findProps(instance);
function findProps (instance) {
depth++;
var result = undefined;
if (instance && !Node.prototype.isPrototypeOf(instance) && !BDFDB.ReactUtils.getInstance(instance) && depth < maxdepth && performance.now() - start < maxtime) {
if (instance.memoizedProps && (instance.type && config.name && config.name.some(name => (instance.type.render && instance.type.render.displayName || instance.type.displayName || instance.type.name || instance.type) === name.split(" _ _ ")[0]) || config.key && config.key.some(key => instance.key == key))) result = instance.memoizedProps;
if (result === undefined) {
let keys = Object.getOwnPropertyNames(instance);
for (let i = 0; result === undefined && i < keys.length; i++) {
let key = keys[i];
if (key && whitelist[key] && (typeof instance[key] === "object" || typeof instance[key] === "function")) result = findProps(instance[key]);
}
}
}
depth--;
return result;
}
};
BDFDB.ReactUtils.findValue = function (nodeOrInstance, searchkey, config = {}) {
if (!BDFDB.ObjectUtils.is(config)) return null;
if (!nodeOrInstance || typeof searchkey != "string") return config.all ? [] : null;
var instance = Node.prototype.isPrototypeOf(nodeOrInstance) ? BDFDB.ReactUtils.getInstance(nodeOrInstance) : nodeOrInstance;
if (!BDFDB.ObjectUtils.is(instance)) return config.all ? [] : null;
instance = instance._reactInternalFiber || instance;
var depth = -1;
var start = performance.now();
var maxdepth = config.unlimited ? 999999999 : (config.depth === undefined ? 30 : config.depth);
var maxtime = config.unlimited ? 999999999 : (config.time === undefined ? 150 : config.time);
var whitelist = {
props: true,
state: true,
stateNode: true,
updater: true,
prototype: true,
type: true,
children: config.up ? false : true,
memoizedProps: true,
memoizedState: true,
child: config.up ? false : true,
return: config.up ? true : false,
sibling: config.up ? false : true
};
var blacklist = {
contextSection: true
};
if (BDFDB.ObjectUtils.is(config.whitelist)) Object.assign(whitelist, config.whiteList);
if (BDFDB.ObjectUtils.is(config.blacklist)) Object.assign(blacklist, config.blacklist);
var foundkeys = [];
var singlekey = getKey(instance);
if (config.all) return foundkeys;
else return singlekey;
function getKey(instance) {
depth++;
var result = undefined;
if (instance && !Node.prototype.isPrototypeOf(instance) && !BDFDB.ReactUtils.getInstance(instance) && depth < maxdepth && performance.now() - start < maxtime) {
let keys = Object.getOwnPropertyNames(instance);
for (let i = 0; result === undefined && i < keys.length; i++) {
let key = keys[i];
if (key && !blacklist[key]) {
var value = instance[key];
if (searchkey === key && (config.value === undefined || BDFDB.equals(config.value, value))) {
if (config.all === undefined || !config.all) result = value;
else if (config.all) {
if (config.noCopies === undefined || !config.noCopies) foundkeys.push(value);
else if (config.noCopies) {
var copy = false;
for (let foundkey of foundkeys) if (BDFDB.equals(value, foundkey)) {
copy = true;
break;
}
if (!copy) foundkeys.push(value);
}
}
}
else if ((typeof value === "object" || typeof value === "function") && (whitelist[key] || key[0] == "." || !isNaN(key[0]))) result = getKey(value);
}
}
}
depth--;
return result;
}
};
BDFDB.ReactUtils.forceUpdate = function (...instances) {
for (let ins of instances.flat(10).filter(n => n)) if (ins.updater && typeof ins.updater.isMounted == "function" && ins.updater.isMounted(ins)) ins.forceUpdate();
};
BDFDB.ReactUtils.getInstance = function (node) {
if (!BDFDB.ObjectUtils.is(node)) return null;
return node[Object.keys(node).find(key => key.startsWith("__reactInternalInstance"))];
};
BDFDB.ReactUtils.getValue = function (nodeOrInstance, valuepath) {
if (!nodeOrInstance || !valuepath) return null;
var instance = Node.prototype.isPrototypeOf(nodeOrInstance) ? BDFDB.ReactUtils.getInstance(nodeOrInstance) : nodeOrInstance;
if (!BDFDB.ObjectUtils.is(instance)) return null;
var found = instance, values = valuepath.split(".").filter(n => n);
for (value of values) {
if (!found) return null;
found = found[value];
}
return found;
};
BDFDB.ReactUtils.render = function (component, node) {
if (!BDFDB.ReactUtils.isValidElement(component) || !Node.prototype.isPrototypeOf(node)) return;
try {
LibraryModules.ReactDOM.render(component, node);
let observer = new MutationObserver(changes => changes.forEach(change => {
let nodes = Array.from(change.removedNodes);
if (nodes.indexOf(node) > -1 || nodes.some(n => n.contains(node))) {
observer.disconnect();
BDFDB.ReactUtils.unmountComponentAtNode(node);
}
}));
observer.observe(document.body, {subtree:true, childList:true});
}
catch (err) {BDFDB.LogUtils.error("Could not render react element! " + err);}
};
InternalBDFDB.setDefaultProps = function (component, defaultProps) {
if (BDFDB.ObjectUtils.is(component)) component.defaultProps = Object.assign({}, component.defaultProps, defaultProps);
};
BDFDB.sameProto = function (a, b) {
if (a != null && typeof a == "object") return a.constructor && a.constructor.prototype && typeof a.constructor.prototype.isPrototypeOf == "function" && a.constructor.prototype.isPrototypeOf(b);
else return typeof a == typeof b;
};
BDFDB.equals = function (mainA, mainB, sorted) {
var i = -1;
if (sorted === undefined || typeof sorted !== "boolean") sorted = false;
return equal(mainA, mainB);
function equal(a, b) {
i++;
var result = true;
if (i > 1000) result = null;
else {
if (typeof a !== typeof b) result = false;
else if (typeof a === "function") result = a.toString() == b.toString();
else if (typeof a === "undefined") result = true;
else if (typeof a === "symbol") result = true;
else if (typeof a === "boolean") result = a == b;
else if (typeof a === "string") result = a == b;
else if (typeof a === "number") {
if (isNaN(a) || isNaN(b)) result = isNaN(a) == isNaN(b);
else result = a == b;
}
else if (!a && !b) result = true;
else if (!a || !b) result = false;
else if (typeof a === "object") {
var keysA = Object.getOwnPropertyNames(a);
var keysB = Object.getOwnPropertyNames(b);
if (keysA.length !== keysB.length) result = false;
else for (let j = 0; result === true && j < keysA.length; j++) {
if (sorted) result = equal(a[keysA[j]], b[keysB[j]]);
else result = equal(a[keysA[j]], b[keysA[j]]);
}
}
}
i--;
return result;
}
};
let MessageRerenderTimeout;
BDFDB.MessageUtils = {};
BDFDB.MessageUtils.rerenderAll = function () {
BDFDB.TimeUtils.clear(MessageRerenderTimeout);
MessageRerenderTimeout = BDFDB.TimeUtils.timeout(_ => {
let MessagesIns = BDFDB.ReactUtils.findOwner(document.querySelector(BDFDB.dotCN.app), {name:"Messages", unlimited:true});
let MessagesPrototype = BDFDB.ReactUtils.getValue(MessagesIns, "_reactInternalFiber.type.prototype");
if (MessagesIns && MessagesPrototype) {
let patchCancel = BDFDB.ModuleUtils.patch({name:"tempPatch"}, MessagesPrototype, "render", {after: e => {
patchCancel();
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnValue, {props: ["message", "channel"]});
if (index > -1) for (let ele of children) if (ele.props.message) ele.props.message = new BDFDB.DiscordObjects.Message(ele.props.message);
}});
BDFDB.ReactUtils.forceUpdate(MessagesIns);
}
}, 1000);
};
BDFDB.UserUtils = {};
var myDataUser = LibraryModules.CurrentUserStore ? LibraryModules.CurrentUserStore.getCurrentUser() : null;
BDFDB.UserUtils.is = function (user) {
return user && user instanceof BDFDB.DiscordObjects.User;
};
BDFDB.UserUtils.me = new Proxy(myDataUser || {}, {
get: function (list, item) {
if (!myDataUser) myDataUser = LibraryModules.CurrentUserStore.getCurrentUser();
return myDataUser ? myDataUser[item] : null;
}
});
BDFDB.UserUtils.getStatus = function (id = BDFDB.UserUtils.me.id) {
id = typeof id == "number" ? id.toFixed() : id;
let activity = BDFDB.UserUtils.getActivitiy(id);
return activity && activity.type == BDFDB.DiscordConstants.ActivityTypes.STREAMING ? "streaming" : LibraryModules.StatusMetaUtils.getStatus(id);
};
BDFDB.UserUtils.getStatusColor = function (status) {
status = typeof status == "string" ? status.toLowerCase() : null;
switch (status) {
case "online": return BDFDB.DiscordConstants.Colors.STATUS_GREEN;
case "mobile": return BDFDB.DiscordConstants.Colors.STATUS_GREEN;
case "idle": return BDFDB.DiscordConstants.Colors.STATUS_YELLOW;
case "dnd": return BDFDB.DiscordConstants.Colors.STATUS_RED;
case "playing": return BDFDB.DiscordConstants.Colors.BRAND;
case "listening": return BDFDB.DiscordConstants.Colors.SPOTIFY;
case "streaming": return BDFDB.DiscordConstants.Colors.TWITCH;
default: return BDFDB.DiscordConstants.Colors.STATUS_GREY;
}
};
BDFDB.UserUtils.getActivitiy = function (id = BDFDB.UserUtils.me.id) {
for (let activity of LibraryModules.StatusMetaUtils.getActivities(id)) if (activity.type != BDFDB.DiscordConstants.ActivityTypes.CUSTOM_STATUS) return activity;
return null;
};
BDFDB.UserUtils.getAvatar = function (id = BDFDB.UserUtils.me.id) {
var user = LibraryModules.UserStore.getUser(typeof id == "number" ? id.toFixed() : id);
if (!user) return window.location.origin + "/assets/322c936a8c8be1b803cd94861bdfa868.png";
else return ((user.avatar ? "" : window.location.origin) + LibraryModules.IconUtils.getUserAvatarURL(user)).split("?")[0];
};
BDFDB.UserUtils.can = function (permission, id = BDFDB.UserUtils.me.id, channelid = LibraryModules.LastChannelStore.getChannelId()) {
if (!BDFDB.DiscordConstants.Permissions[permission]) BDFDB.LogUtils.warn(permission + " not found in Permissions");
else {
var channel = LibraryModules.ChannelStore.getChannel(channelid);
if (channel) return LibraryModules.PermissionUtils.canUser(id, BDFDB.DiscordConstants.Permissions[permission], channel);
}
return false;
};
BDFDB.GuildUtils = {};
BDFDB.GuildUtils.is = function (guild) {
return guild && guild instanceof BDFDB.DiscordObjects.Guild;
};
BDFDB.GuildUtils.getIcon = function (id) {
var guild = LibraryModules.GuildStore.getGuild(typeof id == "number" ? id.toFixed() : id);
if (!guild || !guild.icon) return null;
return LibraryModules.IconUtils.getGuildIconURL(guild).split("?")[0];
};
BDFDB.GuildUtils.getBanner = function (id) {
var guild = LibraryModules.GuildStore.getGuild(typeof id == "number" ? id.toFixed() : id);
if (!guild || !guild.banner) return null;
return LibraryModules.IconUtils.getGuildBannerURL(guild).split("?")[0];
};
BDFDB.GuildUtils.getFolder = function (id) {
return BDFDB.LibraryModules.FolderStore.guildFolders.filter(n => n.folderId).find(n => n.guildIds.includes(id));
};
BDFDB.GuildUtils.getId = function (div) {
if (!Node.prototype.isPrototypeOf(div) || !BDFDB.ReactUtils.getInstance(div)) return;
let guilddiv = BDFDB.DOMUtils.getParent(BDFDB.dotCN.guildouter, div);
if (!guilddiv) return;
var iconwrap = guilddiv.querySelector(BDFDB.dotCN.guildiconwrapper);
var id = iconwrap && iconwrap.href ? iconwrap.href.split("/").slice(-2)[0] : null;
return id && !isNaN(parseInt(id)) ? id.toString() : null;
};
BDFDB.GuildUtils.getData = function (eleOrInfoOrId) {
if (!eleOrInfoOrId) return null;
let id = Node.prototype.isPrototypeOf(eleOrInfoOrId) ? BDFDB.GuildUtils.getId(eleOrInfoOrId) : (typeof eleOrInfoOrId == "object" ? eleOrInfoOrId.id : eleOrInfoOrId);
id = typeof id == "number" ? id.toFixed() : id;
for (let info of BDFDB.GuildUtils.getAll()) if (info && info.id == id) return info;
return null;
};
BDFDB.GuildUtils.getAll = function () {
var found = [], objs = [];
for (let ins of BDFDB.ReactUtils.findOwner(document.querySelector(BDFDB.dotCN.guilds), {name:["Guild","GuildIcon"], all:true, unlimited:true})) {
if (ins.props && ins.props.guild) objs.push(Object.assign(new ins.props.guild.constructor(ins.props.guild), {div:ins.handleContextMenu && BDFDB.ReactUtils.findDOMNode(ins), instance:ins}));
}
for (let id of BDFDB.LibraryModules.FolderStore.getFlattenedGuildIds()) {
let foundobj = null;
for (let obj of objs) if (obj.id == id) {
foundobj = obj
break;
}
if (foundobj) found.push(foundobj);
else {
let guild = BDFDB.LibraryModules.GuildStore.getGuild(id);
found.push(Object.assign(new guild.constructor(guild), {div:null, instance:null}))
}
}
return found;
};
BDFDB.GuildUtils.getUnread = function (servers) {
var found = [];
for (let eleOrInfoOrId of servers === undefined || !BDFDB.ArrayUtils.is(servers) ? BDFDB.GuildUtils.getAll() : servers) {
if (!eleOrInfoOrId) return null;
let id = Node.prototype.isPrototypeOf(eleOrInfoOrId) ? BDFDB.GuildUtils.getId(eleOrInfoOrId) : (typeof eleOrInfoOrId == "object" ? eleOrInfoOrId.id : eleOrInfoOrId);
id = typeof id == "number" ? id.toFixed() : id;
if (id && (LibraryModules.UnreadGuildUtils.hasUnread(id) || LibraryModules.UnreadGuildUtils.getMentionCount(id) > 0)) found.push(eleOrInfoOrId);
}
return found;
};
BDFDB.GuildUtils.getPinged = function (servers) {
var found = [];
for (let eleOrInfoOrId of servers === undefined || !BDFDB.ArrayUtils.is(servers) ? BDFDB.GuildUtils.getAll() : servers) {
if (!eleOrInfoOrId) return null;
let id = Node.prototype.isPrototypeOf(eleOrInfoOrId) ? BDFDB.GuildUtils.getId(eleOrInfoOrId) : (typeof eleOrInfoOrId == "object" ? eleOrInfoOrId.id : eleOrInfoOrId);
id = typeof id == "number" ? id.toFixed() : id;
if (id && LibraryModules.UnreadGuildUtils.getMentionCount(id) > 0) found.push(eleOrInfoOrId);
}
return found;
};
BDFDB.GuildUtils.getMuted = function (servers) {
var found = [];
for (let eleOrInfoOrId of servers === undefined || !BDFDB.ArrayUtils.is(servers) ? BDFDB.GuildUtils.getAll() : servers) {
if (!eleOrInfoOrId) return null;
let id = Node.prototype.isPrototypeOf(eleOrInfoOrId) ? BDFDB.GuildUtils.getId(eleOrInfoOrId) : (typeof eleOrInfoOrId == "object" ? eleOrInfoOrId.id : eleOrInfoOrId);
id = typeof id == "number" ? id.toFixed() : id;
if (id && LibraryModules.MutedUtils.isGuildOrCategoryOrChannelMuted(id)) found.push(eleOrInfoOrId);
}
return found;
};
BDFDB.GuildUtils.getSelected = function () {
var info = LibraryModules.GuildStore.getGuild(LibraryModules.LastGuildStore.getGuildId());
if (info) return BDFDB.GuildUtils.getData(info.id) || Object.assign(new info.constructor(info), {div:null, instance:null});
else return null;
};
BDFDB.GuildUtils.openMenu = function (eleOrInfoOrId, e = BDFDB.InternalData.mousePosition) {
if (!eleOrInfoOrId) return;
let id = Node.prototype.isPrototypeOf(eleOrInfoOrId) ? BDFDB.GuildUtils.getId(eleOrInfoOrId) : (typeof eleOrInfoOrId == "object" ? eleOrInfoOrId.id : eleOrInfoOrId);
let guild = LibraryModules.GuildStore.getGuild(id);
if (guild) LibraryModules.ContextMenuUtils.openContextMenu(e, function (e) {
return BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.ContextMenus._Exports.GuildContextMenu && InternalComponents.LibraryComponents.ContextMenus._Exports.GuildContextMenu.default, Object.assign({}, e, {
type: BDFDB.DiscordConstants.ContextMenuTypes.GUILD_ICON_BAR,
guild: guild,
badge: LibraryModules.UnreadGuildUtils.getMentionCount(guild.id),
link: BDFDB.DiscordConstants.Routes.CHANNEL(guild.id, LibraryModules.LastChannelStore.getChannelId(guild.id)),
selected: guild.id == LibraryModules.LastGuildStore.getGuildId()
}));
});
};
BDFDB.GuildUtils.markAsRead = function (guilds) {
if (!guilds) return;
var unreadchannels = [];
for (let guild of BDFDB.ArrayUtils.is(guilds) ? guilds : (typeof guilds == "string" || typeof guilds == "number" ? Array.of(guilds) : Array.from(guilds))) {
let id = Node.prototype.isPrototypeOf(guild) ? BDFDB.GuildUtils.getId(guild) : (guild && typeof guild == "object" ? guild.id : guild);
let channels = id && LibraryModules.GuildChannelStore.getChannels(id);
if (channels) for (let type in channels) if (BDFDB.ArrayUtils.is(channels[type])) for (let channelobj of channels[type]) unreadchannels.push(channelobj.channel.id);
}
if (unreadchannels.length) LibraryModules.AckUtils.bulkAck(unreadchannels);
};
BDFDB.FolderUtils = {};
BDFDB.FolderUtils.getId = function (div) {
if (!Node.prototype.isPrototypeOf(div) || !BDFDB.ReactUtils.getInstance(div)) return;
div = BDFDB.DOMUtils.getParent(BDFDB.dotCN.guildfolderwrapper, div);
if (!div) return;
return BDFDB.ReactUtils.findValue(div, "folderId", {up:true});
};
BDFDB.FolderUtils.getDefaultName = function (folderId) {
let folder = BDFDB.LibraryModules.FolderStore.getGuildFolderById(folderId);
if (!folder) return "";
let rest = 2 * BDFDB.DiscordConstants.MAX_GUILD_FOLDER_NAME_LENGTH;
let names = [], allNames = folder.guildIds.map(guildId => (BDFDB.LibraryModules.GuildStore.getGuild(guildId) || {}).name).filter(n => n);
for (let name of allNames) if (name.length < rest || names.length === 0) {
names.push(name);
rest -= name.length;
}
return names.join(", ") + (names.length < allNames.length ? ", ..." : "");
};
BDFDB.FolderUtils.getDiv = function (eleOrInfoOrId) {
if (!eleOrInfoOrId) return null;
let info = BDFDB.FolderUtils.getData(eleOrInfoOrId);
return info ? info.div : null;
};
BDFDB.FolderUtils.getData = function (eleOrInfoOrId) {
if (!eleOrInfoOrId) return null;
let id = Node.prototype.isPrototypeOf(eleOrInfoOrId) ? BDFDB.FolderUtils.getId(eleOrInfoOrId) : (typeof eleOrInfoOrId == "object" ? eleOrInfoOrId.id : eleOrInfoOrId);
id = typeof id == "number" ? id.toFixed() : id;
for (let info of BDFDB.FolderUtils.getAll()) if (info && info.folderId == id) return info;
return null;
};
BDFDB.FolderUtils.getAll = function () {
var found = [];
for (let ins of BDFDB.ReactUtils.findOwner(document.querySelector(BDFDB.dotCN.guildswrapper), {name:"GuildFolder", all:true, unlimited:true})) {
if (ins.props && ins.props.folderId) found.push(Object.assign({}, ins.props, {div:BDFDB.ReactUtils.findDOMNode(ins), instance:ins}));
}
return found;
};
BDFDB.ChannelUtils = {};
BDFDB.ChannelUtils.is = function (channel) {
return channel && channel instanceof BDFDB.DiscordObjects.Channel;
};
BDFDB.ChannelUtils.isTextChannel = function (channelOrId) {
let channel = typeof channelOrId == "string" ? LibraryModules.ChannelStore.getChannel(channelOrId) : channelOrId;
return BDFDB.ObjectUtils.is(channel) && (channel.type == BDFDB.DiscordConstants.ChannelTypes.GUILD_TEXT || channel.type == BDFDB.DiscordConstants.ChannelTypes.GUILD_STORE || channel.type == BDFDB.DiscordConstants.ChannelTypes.GUILD_ANNOUNCEMENT);
};
BDFDB.ChannelUtils.getId = function (div) {
if (!Node.prototype.isPrototypeOf(div) || !BDFDB.ReactUtils.getInstance(div)) return;
div = BDFDB.DOMUtils.getParent(BDFDB.dotCNC.categorycontainerdefault + BDFDB.dotCNC.channelcontainerdefault + BDFDB.dotCN.dmchannel, div);
if (!div) return;
var info = BDFDB.ReactUtils.findValue(div, "channel");
return info ? info.id.toString() : null;
};
BDFDB.ChannelUtils.getDiv = function (eleOrInfoOrId) {
if (!eleOrInfoOrId) return null;
let info = BDFDB.ChannelUtils.getData(eleOrInfoOrId);
return info ? info.div : null;
};
BDFDB.ChannelUtils.getData = function (eleOrInfoOrId) {
if (!eleOrInfoOrId) return null;
let id = Node.prototype.isPrototypeOf(eleOrInfoOrId) ? BDFDB.ChannelUtils.getId(eleOrInfoOrId) : (typeof eleOrInfoOrId == "object" ? eleOrInfoOrId.id : eleOrInfoOrId);
id = typeof id == "number" ? id.toFixed() : id;
for (let info of BDFDB.ChannelUtils.getAll()) if (info && info.id == id) return info;
return null;
};
BDFDB.ChannelUtils.getName = function (id, addPrefix) {
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(id);
if (!channel) return "";
switch (channel.type) {
case BDFDB.DiscordConstants.ChannelTypes.DM:
let user = channel.recipients.map(BDFDB.LibraryModules.UserStore.getUser).filter(n => n)[0];
return (addPrefix && "@" || "") + (user && user.toString() || "");
case BDFDB.DiscordConstants.ChannelTypes.GROUP_DM:
if (channel.name) return channel.name;
let users = channel.recipients.map(BDFDB.LibraryModules.UserStore.getUser).filter(n => n);
return users.length > 0 ? users.map(user => user.toString).join(", ") : BDFDB.LanguageUtils.LanguageStrings.UNNAMED;
case BDFDB.DiscordConstants.ChannelTypes.GUILD_ANNOUNCEMENT:
case BDFDB.DiscordConstants.ChannelTypes.GUILD_TEXT:
return (addPrefix && "#" || "") + channel.name;
default:
return channel.name
}
};
BDFDB.ChannelUtils.getAll = function () {
var found = [];
for (let ins of BDFDB.ReactUtils.findOwner(document.querySelector(BDFDB.dotCN.channels), {name: ["ChannelCategoryItem", "ChannelItem", "PrivateChannel"], all:true, unlimited:true})) if (ins.props && !ins.props.ispin && ins.props.channel && ins._reactInternalFiber.return) {
var div = BDFDB.ReactUtils.findDOMNode(ins);
div = div && BDFDB.DOMUtils.containsClass(div.parentElement, BDFDB.disCN.categorycontainerdefault, BDFDB.disCN.channelcontainerdefault, false) ? div.parentElement : div;
found.push(Object.assign(new ins.props.channel.constructor(ins.props.channel), {div, instance:ins}));
}
return found;
};
BDFDB.ChannelUtils.getSelected = function () {
var info = LibraryModules.ChannelStore.getChannel(LibraryModules.LastChannelStore.getChannelId());
if (info) return BDFDB.ChannelUtils.getData(info.id) || Object.assign(new info.constructor(info), {div:null, instance:null});
else return null;
};
BDFDB.ChannelUtils.openMenu = function (eleOrInfoOrId, e = BDFDB.InternalData.mousePosition) {
if (!eleOrInfoOrId) return;
let id = Node.prototype.isPrototypeOf(eleOrInfoOrId) ? BDFDB.ChannelUtils.getId(eleOrInfoOrId) : (typeof eleOrInfoOrId == "object" ? eleOrInfoOrId.id : eleOrInfoOrId);
let channel = LibraryModules.ChannelStore.getChannel(id);
if (channel) {
let type = null;
for (let t in BDFDB.DiscordConstants.ChannelTypes) if (BDFDB.DiscordConstants.ChannelTypes[t] == channel.type) {
type = BDFDB.DiscordConstants.ContextMenuTypes[(t == "GUILD_CATEGORY" ? "CHANNEL_" : "CHANNEL_LIST_") + t.replace("GUILD_", "")];
break;
}
if (type) LibraryModules.ContextMenuUtils.openContextMenu(e, function (e) {
return BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.ContextMenus._Exports.ChannelContextMenu && InternalComponents.LibraryComponents.ContextMenus._Exports.ChannelContextMenu.default, Object.assign({}, e, {
type: type,
channel: channel,
guild: LibraryModules.GuildStore.getGuild(channel.guild_id),
selected: channel.id == LibraryModules.LastChannelStore.getChannelId()
}));
});
}
};
BDFDB.ChannelUtils.markAsRead = function (channels) {
if (!channels) return;
var unreadchannels = [];
for (let channel of channels = BDFDB.ArrayUtils.is(channels) ? channels : (typeof channels == "string" || typeof channels == "number" ? Array.of(channels) : Array.from(channels))) {
let id = Node.prototype.isPrototypeOf(channel) ? BDFDB.ChannelUtils.getId(channel) : (channel && typeof channel == "object" ? channel.id : channel);
if (id) unreadchannels.push(id);
}
if (unreadchannels.length) LibraryModules.AckUtils.bulkAck(unreadchannels);
};
BDFDB.DMUtils = {};
BDFDB.DMUtils.isDMChannel = function (channelOrId) {
let channel = typeof channelOrId == "string" ? LibraryModules.ChannelStore.getChannel(channelOrId) : channelOrId;
return BDFDB.ObjectUtils.is(channel) && (channel.type == BDFDB.DiscordConstants.ChannelTypes.DM || channel.type == BDFDB.DiscordConstants.ChannelTypes.GROUP_DM);
};
BDFDB.DMUtils.getIcon = function (id) {
var channel = LibraryModules.ChannelStore.getChannel(id = typeof id == "number" ? id.toFixed() : id);
if (!channel) return null;
if (!channel.icon) return channel.type == 1 ? BDFDB.UserUtils.getAvatar(channel.recipients[0]) : (channel.type == 3 ? window.location.origin + LibraryModules.IconUtils.getChannelIconURL(channel).split("?")[0] : null);
return LibraryModules.IconUtils.getChannelIconURL(channel).split("?")[0];
};
BDFDB.DMUtils.getId = function (div) {
if (!Node.prototype.isPrototypeOf(div) || !BDFDB.ReactUtils.getInstance(div)) return;
let dmdiv = BDFDB.DOMUtils.getParent(BDFDB.dotCN.guildouter, div);
if (!dmdiv) return;
var iconwrap = dmdiv.querySelector(BDFDB.dotCN.guildiconwrapper);
var id = iconwrap && iconwrap.href ? iconwrap.href.split("/").slice(-1)[0] : null;
return id && !isNaN(parseInt(id)) ? id.toString() : null;
};
BDFDB.DMUtils.getDiv = function (eleOrInfoOrId) {
if (!eleOrInfoOrId) return null;
if (Node.prototype.isPrototypeOf(eleOrInfoOrId)) {
var div = BDFDB.DOMUtils.getParent(BDFDB.dotCN.guildouter, eleOrInfoOrId);
return div ? div.parentElement : div;
}
else {
let id = typeof eleOrInfoOrId == "object" ? eleOrInfoOrId.id : eleOrInfoOrId;
if (id) {
var div = BDFDB.DOMUtils.getParent(BDFDB.dotCN.guildouter, document.querySelector(`${BDFDB.dotCNS.guilds + BDFDB.dotCN.dmpill + " + * " + BDFDB.dotCN.guildiconwrapper}[href*="/channels/@me/${id}"]`));
return div && BDFDB? div.parentElement : div;
}
}
return null;
};
BDFDB.DMUtils.getData = function (eleOrInfoOrId) {
if (!eleOrInfoOrId) return null;
let id = Node.prototype.isPrototypeOf(eleOrInfoOrId) ? BDFDB.BDFDB.DMUtils.getId(eleOrInfoOrId) : (typeof eleOrInfoOrId == "object" ? eleOrInfoOrId.id : eleOrInfoOrId);
id = typeof id == "number" ? id.toFixed() : id;
for (let info of BDFDB.DMUtils.getAll()) if (info && info.id == id) return info;
return null;
};
BDFDB.DMUtils.getAll = function () {
var found = [];
for (let ins of BDFDB.ReactUtils.findOwner(document.querySelector(BDFDB.dotCN.guilds), {name:"DirectMessage", all:true, unlimited:true})) {
if (ins.props && ins.props.channel) found.push(Object.assign(new ins.props.channel.constructor(ins.props.channel), {div:BDFDB.ReactUtils.findDOMNode(ins), instance:ins}));
}
return found;
};
BDFDB.DMUtils.openMenu = function (eleOrInfoOrId, e = BDFDB.InternalData.mousePosition) {
if (!eleOrInfoOrId) return;
let id = Node.prototype.isPrototypeOf(eleOrInfoOrId) ? BDFDB.ChannelUtils.getId(eleOrInfoOrId) : (typeof eleOrInfoOrId == "object" ? eleOrInfoOrId.id : eleOrInfoOrId);
let channel = LibraryModules.ChannelStore.getChannel(id);
if (channel) {
if (channel.isMultiUserDM()) LibraryModules.ContextMenuUtils.openContextMenu(e, function (e) {
return BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.ContextMenus.GroupDMContextMenu, Object.assign({}, e, {
channelId: channel.id,
selected: channel.id == LibraryModules.LastChannelStore.getChannelId()
}));
}, {noBlurEvent: true});
else LibraryModules.ContextMenuUtils.openContextMenu(e, function (e) {
return BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.ContextMenus._Exports.UserContextMenu && InternalComponents.LibraryComponents.ContextMenus._Exports.UserContextMenu.default, Object.assign({}, e, {
type: BDFDB.DiscordConstants.ContextMenuTypes.USER_PRIVATE_CHANNELS,
user: LibraryModules.UserStore.getUser(channel.recipients[0]),
channelId: channel.id,
selected: channel.id == LibraryModules.LastChannelStore.getChannelId()
}));
});
}
};
BDFDB.DMUtils.markAsRead = function (dms) {
if (!dms) return;
var unreadchannels = [];
for (let dm of dms = BDFDB.ArrayUtils.is(dms) ? dms : (typeof dms == "string" || typeof dms == "number" ? Array.of(dms) : Array.from(dms))) {
let id = Node.prototype.isPrototypeOf(dm) ? BDFDB.BDFDB.DMUtils.getId(dm) : (dm && typeof dm == "object" ? dm.id : dm);
if (id) unreadchannels.push(id);
}
for (let i in unreadchannels) BDFDB.TimeUtils.timeout(_ => {LibraryModules.AckUtils.ack(unreadchannels[i]);}, i * 1000);
};
BDFDB.DataUtils = {};
BDFDB.DataUtils.cached = window.BDFDB && window.BDFDB.DataUtils && window.BDFDB.DataUtils.cached || {};
BDFDB.DataUtils.save = function (data, plugin, key, id) {
let configPath, pluginName;
if (!BDFDB.BDUtils.isBDv2()) {
pluginName = typeof plugin === "string" ? plugin : plugin.name;
configPath = LibraryRequires.path.join(BDFDB.BDUtils.getPluginsFolder(), pluginName + ".config.json");
}
else {
pluginName = typeof plugin === "string" ? plugin.toLowerCase() : null;
let contentpath = pluginName ? BDFDB.Plugins[pluginName] ? BDFDB.Plugins[pluginName].contentPath : null : plugin.contentPath;
if (!contentpath) return;
configPath = LibraryRequires.path.join(contentpath, "settings.json");
}
let config = BDFDB.DataUtils.cached[pluginName] !== undefined ? BDFDB.DataUtils.cached[pluginName] : (InternalBDFDB.readConfig(configPath) || {});
if (key === undefined) config = BDFDB.ObjectUtils.is(data) ? BDFDB.ObjectUtils.sort(data) : data;
else {
if (id === undefined) config[key] = BDFDB.ObjectUtils.is(data) ? BDFDB.ObjectUtils.sort(data) : data;
else {
if (!BDFDB.ObjectUtils.is(config[key])) config[key] = {};
config[key][id] = BDFDB.ObjectUtils.is(data) ? BDFDB.ObjectUtils.sort(data) : data;
}
}
let configIsObject = BDFDB.ObjectUtils.is(config);
if (key !== undefined && configIsObject && BDFDB.ObjectUtils.is(config[key]) && BDFDB.ObjectUtils.isEmpty(config[key])) delete config[key];
if (BDFDB.ObjectUtils.isEmpty(config)) {
delete BDFDB.DataUtils.cached[pluginName];
if (LibraryRequires.fs.existsSync(configPath)) LibraryRequires.fs.unlinkSync(configPath);
}
else {
if (configIsObject) config = BDFDB.ObjectUtils.sort(config);
BDFDB.DataUtils.cached[pluginName] = configIsObject ? BDFDB.ObjectUtils.deepAssign({}, config) : config;
LibraryRequires.fs.writeFileSync(configPath, JSON.stringify(config, null, " "));
}
};
BDFDB.DataUtils.load = function (plugin, key, id) {
let configPath, pluginName;
if (!BDFDB.BDUtils.isBDv2()) {
pluginName = typeof plugin === "string" ? plugin : plugin.name;
configPath = LibraryRequires.path.join(BDFDB.BDUtils.getPluginsFolder(), pluginName + ".config.json");
}
else {
pluginName = typeof plugin === "string" ? plugin.toLowerCase() : null;
let contentpath = pluginName ? BDFDB.Plugins[pluginName] ? BDFDB.Plugins[pluginName].contentPath : null : plugin.contentPath;
if (!contentpath) return {};
configPath = LibraryRequires.path.join(contentpath, "settings.json");
}
let config = BDFDB.DataUtils.cached[pluginName] !== undefined ? BDFDB.DataUtils.cached[pluginName] : (InternalBDFDB.readConfig(configPath) || {});
let configIsObject = BDFDB.ObjectUtils.is(config);
BDFDB.DataUtils.cached[pluginName] = configIsObject ? BDFDB.ObjectUtils.deepAssign({}, config) : config;
if (key === undefined) return config;
else {
let keydata = configIsObject ? (BDFDB.ObjectUtils.is(config[key]) || config[key] == undefined ? BDFDB.ObjectUtils.deepAssign({}, config[key]) : config[key]) : null;
if (id === undefined) return keydata;
else return !BDFDB.ObjectUtils.is(keydata) || keydata[id] === undefined ? null : keydata[id];
}
};
BDFDB.DataUtils.remove = function (plugin, key, id) {
let configPath, pluginName;
if (!BDFDB.BDUtils.isBDv2()) {
pluginName = typeof plugin === "string" ? plugin : plugin.name;
configPath = LibraryRequires.path.join(BDFDB.BDUtils.getPluginsFolder(), pluginName + ".config.json");
}
else {
pluginName = typeof plugin === "string" ? plugin.toLowerCase() : null;
let contentpath = pluginName ? BDFDB.Plugins[pluginName] ? BDFDB.Plugins[pluginName].contentPath : null : plugin.contentPath;
if (!contentpath) return;
configPath = LibraryRequires.path.join(contentpath, "settings.json");
}
let config = BDFDB.DataUtils.cached[pluginName] !== undefined ? BDFDB.DataUtils.cached[pluginName] : (InternalBDFDB.readConfig(configPath) || {});
let configIsObject = BDFDB.ObjectUtils.is(config);
if (key === undefined || !configIsObject) config = {};
else {
if (id === undefined) delete config[key];
else if (BDFDB.ObjectUtils.is(config[key])) delete config[key][id];
}
if (BDFDB.ObjectUtils.is(config[key]) && BDFDB.ObjectUtils.isEmpty(config[key])) delete config[key];
if (BDFDB.ObjectUtils.isEmpty(config)) {
delete BDFDB.DataUtils.cached[pluginName];
if (LibraryRequires.fs.existsSync(configPath)) LibraryRequires.fs.unlinkSync(configPath);
}
else {
if (configIsObject) config = BDFDB.ObjectUtils.sort(config);
BDFDB.DataUtils.cached[pluginName] = configIsObject ? BDFDB.ObjectUtils.deepAssign({}, config) : config;
LibraryRequires.fs.writeFileSync(configPath, JSON.stringify(config, null, " "));
}
};
BDFDB.DataUtils.get = function (plugin, key, id) {
plugin = typeof plugin == "string" ? BDFDB.BDUtils.getPlugin(plugin) : plugin;
if (!BDFDB.ObjectUtils.is(plugin)) return id === undefined ? {} : null;
let defaults = (plugin == BDFDB && InternalBDFDB || plugin).defaults;
if (!BDFDB.ObjectUtils.is(defaults) || !defaults[key]) return id === undefined ? {} : null;
let oldC = BDFDB.DataUtils.load(plugin, key), newC = {}, update = false;
for (let k in defaults[key]) {
let isObj = BDFDB.ObjectUtils.is(defaults[key][k].value);
if (oldC[k] == null || isObj && (!BDFDB.ObjectUtils.is(oldC[k]) || Object.keys(defaults[key][k].value).some(n => defaults[key][k].value[n] != null && !BDFDB.sameProto(defaults[key][k].value[n], oldC[k][n])))) {
newC[k] = isObj ? BDFDB.ObjectUtils.deepAssign({}, defaults[key][k].value) : defaults[key][k].value;
update = true;
}
else newC[k] = oldC[k];
}
if (update) BDFDB.DataUtils.save(newC, plugin, key);
if (id === undefined) return newC;
else return newC[id] === undefined ? null : newC[id];
};
InternalBDFDB.readConfig = function (path) {
try {return JSON.parse(LibraryRequires.fs.readFileSync(path));}
catch (err) {return {};}
};
BDFDB.ColorUtils = {};
BDFDB.ColorUtils.convert = function (color, conv, type) {
if (BDFDB.ObjectUtils.is(color)) {
var newcolor = {};
for (let pos in color) newcolor[pos] = BDFDB.ColorUtils.convert(color[pos], conv, type);
return newcolor;
}
else {
conv = conv === undefined || !conv ? conv = "RGBCOMP" : conv.toUpperCase();
type = type === undefined || !type || !["RGB", "RGBA", "RGBCOMP", "HSL", "HSLA", "HSLCOMP", "HEX", "HEXA", "INT"].includes(type.toUpperCase()) ? BDFDB.ColorUtils.getType(color) : type.toUpperCase();
if (conv == "RGBCOMP") {
switch (type) {
case "RGBCOMP":
if (color.length == 3) return processRGB(color);
else if (color.length == 4) {
let a = processA(color.pop());
return processRGB(color).concat(a);
}
break;
case "RGB":
return processRGB(color.replace(/\s/g, "").slice(4, -1).split(","));
case "RGBA":
let comp = color.replace(/\s/g, "").slice(5, -1).split(",");
let a = processA(comp.pop());
return processRGB(comp).concat(a);
case "HSLCOMP":
if (color.length == 3) return BDFDB.ColorUtils.convert(`hsl(${processHSL(color).join(",")})`, "RGBCOMP");
else if (color.length == 4) {
let a = processA(color.pop());
return BDFDB.ColorUtils.convert(`hsl(${processHSL(color).join(",")})`, "RGBCOMP").concat(a);
}
break;
case "HSL":
var hslcomp = processHSL(color.replace(/\s/g, "").slice(4, -1).split(","));
var r, g, b, m, c, x, p, q;
var h = hslcomp[0] / 360, l = parseInt(hslcomp[1]) / 100, s = parseInt(hslcomp[2]) / 100; m = Math.floor(h * 6); c = h * 6 - m; x = s * (1 - l); p = s * (1 - c * l); q = s * (1 - (1 - c) * l);
switch (m % 6) {
case 0: r = s, g = q, b = x; break;
case 1: r = p, g = s, b = x; break;
case 2: r = x, g = s, b = q; break;
case 3: r = x, g = p, b = s; break;
case 4: r = q, g = x, b = s; break;
case 5: r = s, g = x, b = p; break;
}
return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
case "HSLA":
var hslcomp = color.replace(/\s/g, "").slice(5, -1).split(",");
return BDFDB.ColorUtils.convert(`hsl(${hslcomp.slice(0, 3).join(",")})`, "RGBCOMP").concat(processA(hslcomp.pop()));
case "HEX":
var hex = /^#([a-f\d]{1})([a-f\d]{1})([a-f\d]{1})$|^#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(color);
return [parseInt(hex[1] + hex[1] || hex[4], 16).toString(), parseInt(hex[2] + hex[2] || hex[5], 16).toString(), parseInt(hex[3] + hex[3] || hex[6], 16).toString()];
case "HEXA":
var hex = /^#([a-f\d]{1})([a-f\d]{1})([a-f\d]{1})([a-f\d]{1})$|^#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(color);
return [parseInt(hex[1] + hex[1] || hex[5], 16).toString(), parseInt(hex[2] + hex[2] || hex[6], 16).toString(), parseInt(hex[3] + hex[3] || hex[7], 16).toString(), Math.floor(BDFDB.NumberUtils.mapRange([0, 255], [0, 100], parseInt(hex[4] + hex[4] || hex[8], 16).toString()))/100];
case "INT":
color = processINT(color);
return [(color >> 16 & 255).toString(), (color >> 8 & 255).toString(), (color & 255).toString()];
default:
return null;
}
}
else {
var rgbcomp = type == "RGBCOMP" ? color : BDFDB.ColorUtils.convert(color, "RGBCOMP", type);
if (rgbcomp) switch (conv) {
case "RGB":
return `rgb(${processRGB(rgbcomp.slice(0, 3)).join(",")})`;
case "RGBA":
rgbcomp = rgbcomp.slice(0, 4);
var a = rgbcomp.length == 4 ? processA(rgbcomp.pop()) : 1;
return `rgba(${processRGB(rgbcomp).concat(a).join(",")})`;
case "HSLCOMP":
var a = rgbcomp.length == 4 ? processA(rgbcomp.pop()) : null;
var hslcomp = processHSL(BDFDB.ColorUtils.convert(rgbcomp, "HSL").replace(/\s/g, "").split(","));
return a != null ? hslcomp.concat(a) : hslcomp;
case "HSL":
var r = processC(rgbcomp[0]), g = processC(rgbcomp[1]), b = processC(rgbcomp[2]);
var max = Math.max(r, g, b), min = Math.min(r, g, b), dif = max - min, h, l = max === 0 ? 0 : dif / max, s = max / 255;
switch (max) {
case min: h = 0; break;
case r: h = g - b + dif * (g < b ? 6 : 0); h /= 6 * dif; break;
case g: h = b - r + dif * 2; h /= 6 * dif; break;
case b: h = r - g + dif * 4; h /= 6 * dif; break;
}
return `hsl(${processHSL([Math.round(h * 360), l * 100, s * 100]).join(",")})`;
case "HSLA":
var j0 = rgbcomp.length == 4 ? processA(rgbcomp.pop()) : 1;
return `hsla(${BDFDB.ColorUtils.convert(rgbcomp, "HSL").slice(4, -1).split(",").concat(j0).join(",")})`;
case "HEX":
return ("#" + (0x1000000 + (rgbcomp[2] | rgbcomp[1] << 8 | rgbcomp[0] << 16)).toString(16).slice(1)).toUpperCase();
case "HEXA":
return ("#" + (0x1000000 + (rgbcomp[2] | rgbcomp[1] << 8 | rgbcomp[0] << 16)).toString(16).slice(1) + (0x100 + Math.round(BDFDB.NumberUtils.mapRange([0, 100], [0, 255], processA(rgbcomp[3]) * 100))).toString(16).slice(1)).toUpperCase();
case "INT":
return processINT(rgbcomp[2] | rgbcomp[1] << 8 | rgbcomp[0] << 16);
default:
return null;
}
}
}
return null;
function processC(c) {if (c == null) {return 255;} else {c = parseInt(c.toString().replace(/[^0-9\-]/g, ""));return isNaN(c) || c > 255 ? 255 : c < 0 ? 0 : c;}};
function processRGB(comp) {return comp.map(c => {return processC(c);});};
function processA(a) {if (a == null) {return 1;} else {a = a.toString();a = (a.indexOf("%") > -1 ? 0.01 : 1) * parseFloat(a.replace(/[^0-9\.\-]/g, ""));return isNaN(a) || a > 1 ? 1 : a < 0 ? 0 : a;}};
function processSL(sl) {if (sl == null) {return "100%";} else {sl = parseFloat(sl.toString().replace(/[^0-9\.\-]/g, ""));return (isNaN(sl) || sl > 100 ? 100 : sl < 0 ? 0 : sl) + "%";}};
function processHSL(comp) {let h = parseFloat(comp.shift().toString().replace(/[^0-9\.\-]/g, ""));h = isNaN(h) || h > 360 ? 360 : h < 0 ? 0 : h;return [h].concat(comp.map(sl => {return processSL(sl);}));};
function processINT(c) {if (c == null) {return 16777215;} else {c = parseInt(c.toString().replace(/[^0-9]/g, ""));return isNaN(c) || c > 16777215 ? 16777215 : c < 0 ? 0 : c;}};
};
BDFDB.ColorUtils.setAlpha = function (color, a, conv) {
if (BDFDB.ObjectUtils.is(color)) {
var newcolor = {};
for (let pos in color) newcolor[pos] = BDFDB.ColorUtils.setAlpha(color[pos], a, conv);
return newcolor;
}
else {
var comp = BDFDB.ColorUtils.convert(color, "RGBCOMP");
if (comp) {
a = a.toString();
a = (a.indexOf("%") > -1 ? 0.01 : 1) * parseFloat(a.replace(/[^0-9\.\-]/g, ""));
a = isNaN(a) || a > 1 ? 1 : a < 0 ? 0 : a;
comp[3] = a;
conv = (conv || BDFDB.ColorUtils.getType(color)).toUpperCase();
conv = conv == "RGB" || conv == "HSL" || conv == "HEX" ? conv + "A" : conv;
return BDFDB.ColorUtils.convert(comp, conv);
}
}
return null;
};
BDFDB.ColorUtils.getAlpha = function (color) {
var comp = BDFDB.ColorUtils.convert(color, "RGBCOMP");
if (comp) {
if (comp.length == 3) return 1;
else if (comp.length == 4) {
let a = comp[3].toString();
a = (a.indexOf("%") > -1 ? 0.01 : 1) * parseFloat(a.replace(/[^0-9\.\-]/g, ""));
return isNaN(a) || a > 1 ? 1 : a < 0 ? 0 : a;
}
}
return null;
};
BDFDB.ColorUtils.change = function (color, value, conv) {
value = parseFloat(value);
if (color != null && typeof value == "number" && !isNaN(value)) {
if (BDFDB.ObjectUtils.is(color)) {
var newcolor = {};
for (let pos in color) newcolor[pos] = BDFDB.ColorUtils.change(color[pos], value, conv);
return newcolor;
}
else {
var comp = BDFDB.ColorUtils.convert(color, "RGBCOMP");
if (comp) {
if (parseInt(value) !== value) {
value = value.toString();
value = (value.indexOf("%") > -1 ? 0.01 : 1) * parseFloat(value.replace(/[^0-9\.\-]/g, ""));
value = isNaN(value) ? 0 : value;
return BDFDB.ColorUtils.convert([Math.round(comp[0] * (1 + value)), Math.round(comp[1] * (1 + value)), Math.round(comp[2] * (1 + value))], conv || BDFDB.ColorUtils.getType(color));
}
else return BDFDB.ColorUtils.convert([Math.round(comp[0] + value), Math.round(comp[1] + value), Math.round(comp[2] + value)], conv || BDFDB.ColorUtils.getType(color));
}
}
}
return null;
};
BDFDB.ColorUtils.invert = function (color, conv) {
if (BDFDB.ObjectUtils.is(color)) {
var newcolor = {};
for (let pos in color) newcolor[pos] = BDFDB.ColorUtils.invert(color[pos], conv);
return newcolor;
}
else {
var comp = BDFDB.ColorUtils.convert(color, "RGBCOMP");
if (comp) return BDFDB.ColorUtils.convert([255 - comp[0], 255 - comp[1], 255 - comp[2]], conv || BDFDB.ColorUtils.getType(color));
}
return null;
};
BDFDB.ColorUtils.compare = function (color1, color2) {
if (color1 && color2) {
color1 = BDFDB.ColorUtils.convert(color1, "RGBA");
color2 = BDFDB.ColorUtils.convert(color2, "RGBA");
if (color1 && color2) return BDFDB.equals(color1, color2);
}
return null;
};
BDFDB.ColorUtils.isBright = function (color, compare = 160) {
color = BDFDB.ColorUtils.convert(color, "RGBCOMP");
if (!color) return false;
return parseInt(compare) < Math.sqrt(0.299 * color[0]**2 + 0.587 * color[1]**2 + 0.144 * color[2]**2);
};
BDFDB.ColorUtils.getType = function (color) {
if (color != null) {
if (typeof color === "object" && (color.length == 3 || color.length == 4)) {
if (isRGB(color)) return "RGBCOMP";
else if (isHSL(color)) return "HSLCOMP";
}
else if (typeof color === "string") {
if (/^#[a-f\d]{3}$|^#[a-f\d]{6}$/i.test(color)) return "HEX";
else if (/^#[a-f\d]{4}$|^#[a-f\d]{8}$/i.test(color)) return "HEXA";
else {
color = color.toUpperCase();
var comp = color.replace(/[^0-9\.\-\,\%]/g, "").split(",");
if (color.indexOf("RGB(") == 0 && comp.length == 3 && isRGB(comp)) return "RGB";
else if (color.indexOf("RGBA(") == 0 && comp.length == 4 && isRGB(comp)) return "RGBA";
else if (color.indexOf("HSL(") == 0 && comp.length == 3 && isHSL(comp)) return "HSL";
else if (color.indexOf("HSLA(") == 0 && comp.length == 4 && isHSL(comp)) return "HSLA";
}
}
else if (typeof color === "number" && parseInt(color) == color && color > -1 && color < 16777216) return "INT";
}
return null;
function isRGB(comp) {return comp.slice(0, 3).every(rgb => rgb.toString().indexOf("%") == -1 && parseFloat(rgb) == parseInt(rgb));};
function isHSL(comp) {return comp.slice(1, 3).every(hsl => hsl.toString().indexOf("%") == hsl.length - 1);};
};
BDFDB.ColorUtils.createGradient = function (colorobj, direction = "to right") {
var sortedgradient = {};
var gradientstring = "linear-gradient(" + direction;
for (let pos of Object.keys(colorobj).sort()) {
let color = BDFDB.ColorUtils.convert(colorobj[pos], "RGBA");
gradientstring += color ? `, ${color} ${pos*100}%` : ''
}
return gradientstring += ")";
};
BDFDB.ColorUtils.getSwatchColor = function (container, number) {
if (!Node.prototype.isPrototypeOf(container)) return;
let swatches = container.querySelector(`${BDFDB.dotCN.colorpickerswatches}[number="${number}"], ${BDFDB.dotCN.colorpickerswatch}[number="${number}"]`);
if (!swatches) return null;
return BDFDB.ColorUtils.convert(BDFDB.ReactUtils.findValue(BDFDB.ReactUtils.getInstance(swatches), "selectedColor", {up:true, blacklist:{"props":true}}));
};
BDFDB.ColorUtils.openPicker = function (container, target, color, options = {gradient: true, alpha: true, callback: _ => {}}) {
let itemlayercontainer = document.querySelector(BDFDB.dotCN.appmount + " > * > " + BDFDB.dotCN.itemlayercontainer);
if (!itemlayercontainer || !container || !target) return;
if (typeof options.callback != "function") options.callback = _ => {};
let hexFormat = options.alpha ? "HEXA" : "HEX";
let hexRegex = options.alpha ? /^#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i : /^#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i;
let isGradient = color && BDFDB.ObjectUtils.is(color);
let selectedColor = BDFDB.ColorUtils.convert(isGradient ? color[Object.keys(color)[0]] : color, hexFormat) || (options.alpha ? "#000000FF" : "#000000");
let [h, s, l] = BDFDB.ColorUtils.convert(selectedColor, "HSLCOMP");
let a = BDFDB.ColorUtils.getAlpha(isGradient ? color[Object.keys(color)[0]] : color);
a = a == null ? 1 : a;
let targetrects = BDFDB.DOMUtils.getRects(target);
let colorPicker = BDFDB.DOMUtils.create(`
`);
itemlayercontainer.appendChild(colorPicker);
var removePopout = e => {
if (!colorPicker.contains(e.target)) {
document.removeEventListener("mousedown", removePopout);
colorPicker.remove();
}
};
document.addEventListener("mousedown", removePopout);
let hexinput = colorPicker.querySelector(BDFDB.dotCNS.colorpickerhexinput + BDFDB.dotCN.input);
let satpane = colorPicker.querySelector(".saturation-color");
let satcursor = colorPicker.querySelector(".saturation-cursor");
let huepane = colorPicker.querySelector(".hue-horizontal");
let huecursor = colorPicker.querySelector(".hue-cursor");
let alphabar = colorPicker.querySelector(".alpha-bar");
let alphapane = colorPicker.querySelector(".alpha-horizontal");
let alphacursor = colorPicker.querySelector(".alpha-cursor");
let gradientbutton = colorPicker.querySelector(".gradient-button");
let gradientbar = colorPicker.querySelector(".gradient-bar");
let gradientpane = colorPicker.querySelector(".gradient-horizontal");
let sMinX, sMaxX, sMinY, sMaxY, hMinX, hMaxX, aMinX, aMaxX, gMinX, gMaxX;
updateRects();
if (isGradient) for (let pos in color) if (pos > 0 && pos < 1) gradientpane.appendChild(BDFDB.DOMUtils.create(`
`));
updateColors(false);
if (!options.gradient) BDFDB.DOMUtils.remove(colorPicker.querySelectorAll(".gradient-button, .gradient-bar"));
if (!options.alpha) BDFDB.DOMUtils.remove(colorPicker.querySelectorAll(".alpha-bar"));
BDFDB.ListenerUtils.addToChildren(colorPicker, "mousedown", ".move-corner", e => {
let rects = BDFDB.DOMUtils.getRects(colorPicker);
let transform = getComputedStyle(colorPicker, null).getPropertyValue("transform").replace(/[^0-9,-]/g,"").split(",");
let left = rects.left - (transform.length > 4 ? parseFloat(transform[4]) : 0);
let top = rects.top - (transform.length > 4 ? parseFloat(transform[5]) : 0);
let oldX = e.pageX;
let oldY = e.pageY;
let mouseup = _ => {
BDFDB.DOMUtils.removeLocalStyle("disableTextSelection");
document.removeEventListener("mouseup", mouseup);
document.removeEventListener("mousemove", mousemove);
};
let mousemove = e2 => {
left = left - (oldX - e2.pageX);
top = top - (oldY - e2.pageY);
oldX = e2.pageX;
oldY = e2.pageY;
colorPicker.style.setProperty("left", left + "px", "important");
colorPicker.style.setProperty("top", top + "px", "important");
updateRects();
};
document.addEventListener("mouseup", mouseup);
document.addEventListener("mousemove", mousemove);
});
satpane.addEventListener("mousedown", e => {
s = BDFDB.NumberUtils.mapRange([sMinX, sMaxX], [0, 100], e.clientX) + "%";
l = BDFDB.NumberUtils.mapRange([sMinY, sMaxY], [100, 0], e.clientY) + "%";
updateColors(true);
let mouseup = _ => {
document.removeEventListener("mouseup", mouseup);
document.removeEventListener("mousemove", mousemove);
};
let mousemove = e2 => {
s = BDFDB.NumberUtils.mapRange([sMinX, sMaxX], [0, 100], e2.clientX) + "%";
l = BDFDB.NumberUtils.mapRange([sMinY, sMaxY], [100, 0], e2.clientY) + "%";
updateColors(true);
};
document.addEventListener("mouseup", mouseup);
document.addEventListener("mousemove", mousemove);
});
huepane.addEventListener("mousedown", e => {
h = BDFDB.NumberUtils.mapRange([hMinX, hMaxX], [0, 360], e.clientX);
updateColors(true);
let mouseup = _ => {
document.removeEventListener("mouseup", mouseup);
document.removeEventListener("mousemove", mousemove);
};
let mousemove = e2 => {
h = BDFDB.NumberUtils.mapRange([hMinX, hMaxX], [0, 360], e2.clientX);
updateColors(true);
};
document.addEventListener("mouseup", mouseup);
document.addEventListener("mousemove", mousemove);
});
alphapane.addEventListener("mousedown", e => {
a = BDFDB.NumberUtils.mapRange([aMinX, aMaxX], [0, 1], e.clientX);
updateColors(true);
let bubble = BDFDB.DOMUtils.create(``);
let mouseup = _ => {
bubble.remove();
document.removeEventListener("mouseup", mouseup);
document.removeEventListener("mousemove", mousemove);
};
let mousemove = e2 => {
if (!bubble.parentElement) alphacursor.appendChild(bubble);
a = Math.floor(BDFDB.NumberUtils.mapRange([aMinX, aMaxX], [0, 100], e2.clientX))/100;
bubble.innerText = a;
updateColors(true);
};
document.addEventListener("mouseup", mouseup);
document.addEventListener("mousemove", mousemove);
});
gradientpane.addEventListener("mousedown", e => {
BDFDB.TimeUtils.timeout(_ => {
if (BDFDB.DOMUtils.containsClass(e.target.parentElement, "gradient-cursor")) {
if (e.which == 1) {
if (!BDFDB.DOMUtils.containsClass(e.target.parentElement, "selected")) {
BDFDB.DOMUtils.removeClass(gradientpane.querySelectorAll(".gradient-cursor.selected"), "selected");
BDFDB.DOMUtils.addClass(e.target.parentElement, "selected");
[h, s, l] = BDFDB.ColorUtils.convert(e.target.style.getPropertyValue("background-color"), "HSLCOMP");
a = BDFDB.ColorUtils.getAlpha(e.target.style.getPropertyValue("background-color"));
updateColors(true);
}
if (!BDFDB.DOMUtils.containsClass(e.target.parentElement, "edge")) {
let mouseup = _ => {
document.removeEventListener("mouseup", mouseup);
document.removeEventListener("mousemove", mousemove);
};
let mousemove = e2 => {
e.target.parentElement.style.setProperty("left", BDFDB.NumberUtils.mapRange([gMinX, gMaxX], [1, 99], e2.clientX) + "%");
updateGradient();
};
document.addEventListener("mouseup", mouseup);
document.addEventListener("mousemove", mousemove);
}
}
else if (e.which == 3 && !BDFDB.DOMUtils.containsClass(e.target.parentElement, "edge")) {
BDFDB.DOMUtils.remove(e.target.parentElement);
if (BDFDB.DOMUtils.containsClass(e.target.parentElement, "selected")) {
let firstcursor = gradientpane.querySelector(".gradient-cursor");
BDFDB.DOMUtils.addClass(firstcursor, "selected");
[h, s, l] = BDFDB.ColorUtils.convert(firstcursor.firstElementChild.style.getPropertyValue("background-color"), "HSLCOMP");
a = BDFDB.ColorUtils.getAlpha(firstElementChild.style.getPropertyValue("background-color"));
}
updateColors(true);
}
}
else if (gradientpane == e.target && e.which == 1) {
BDFDB.DOMUtils.removeClass(gradientpane.querySelectorAll(".gradient-cursor.selected"), "selected");
let newcursor = BDFDB.DOMUtils.create(`