From 8b1c3ad677cb5c40952bebf245fa5e6643ebc339 Mon Sep 17 00:00:00 2001 From: Mirco Wittrien Date: Fri, 8 Oct 2021 11:14:54 +0200 Subject: [PATCH] Fixes --- Library/0BDFDB.plugin.js | 65 ++++++--------- Library/_res/0BDFDB.data.json | 9 ++- .../FriendNotifications.plugin.js | 40 ++------- .../ReadAllNotificationsButton.plugin.js | 81 +++++++------------ 4 files changed, 65 insertions(+), 130 deletions(-) diff --git a/Library/0BDFDB.plugin.js b/Library/0BDFDB.plugin.js index 269de17234..86cc9c5ced 100644 --- a/Library/0BDFDB.plugin.js +++ b/Library/0BDFDB.plugin.js @@ -2,7 +2,7 @@ * @name BDFDB * @author DevilBro * @authorId 278543574059057154 - * @version 1.9.1 + * @version 1.9.2 * @description Required Library for DevilBro's Plugins * @invite Jx3TjNS * @donate https://www.paypal.me/MircoWittrien @@ -19,19 +19,14 @@ module.exports = (_ => { "info": { "name": "BDFDB", "author": "DevilBro", - "version": "1.9.1", + "version": "1.9.2", "description": "Required Library for DevilBro's Plugins" }, "rawUrl": `https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js`, "changeLog": { - "added": { - "data-user-id": "Added to Friends List Entries", - "data-author-is-friend": "Added to Friends Flag to Messages" - }, "fixed": { - "BD Browser": "Fixed compartibility issues", - "Server Changes": "Fixed Stuff for anything changing Servers (ServerDetails, DisplayServerAsChannels)", - "React Search": "Fixed some Incompatibilities with other Plugins" + "Server Changes AGAIN": "Fixed Stuff for anything changing Servers", + "BD Browser": "Fixed compartibility issues" } } }; @@ -2144,13 +2139,13 @@ module.exports = (_ => { mapped: InternalData.ModuleUtilsConfig.PatchMap[type] }; config.nonRender = config.specialFilter || BDFDB.ObjectUtils.toArray(pluginData.patchTypes).flat(10).filter(n => n && !InternalData.ModuleUtilsConfig.InstanceFunctions.includes(n)).length > 0; - config.nonPrototype = !!(config.codeFind || config.propertyFind || config.nonRender); + config.nonPrototype = !!(config.subComponent && config.subComponent.strings || config.stringFind || config.subComponent && config.subComponent.props || config.propertyFind || config.nonRender); let component = InternalData.ModuleUtilsConfig.LoadedInComponents[type] && BDFDB.ObjectUtils.get(InternalComponents, InternalData.ModuleUtilsConfig.LoadedInComponents[type]); if (component) InternalBDFDB.patchComponent(pluginData, config.nonRender ? (BDFDB.ModuleUtils.find(m => m == component && m, config.exported) || {}).exports : component, type, config); else { let mappedType = config.mapped ? config.mapped + " _ _ " + type : type; - let name = config.subComponent || mappedType.split(" _ _ ")[0]; + let name = config.subComponent && config.subComponent.name || mappedType.split(" _ _ ")[0]; if (config.mapped) for (let patchType in plugin.patchedModules) if (plugin.patchedModules[patchType][type]) { plugin.patchedModules[patchType][mappedType] = plugin.patchedModules[patchType][type]; delete plugin.patchedModules[patchType][type]; @@ -2159,11 +2154,11 @@ module.exports = (_ => { let patchSpecial = (func, argument) => { let module = BDFDB.ModuleUtils[func](argument, config.exported); let exports = module && !config.exported && module.exports || module; - exports && InternalBDFDB.patchComponent(pluginData, InternalBDFDB.isMemo(exports) ? exports.default : exports, mappedType, config); + exports && InternalBDFDB.patchComponent(pluginData, InternalBDFDB.isMemoOrForwardRef(exports) ? exports.default : exports, mappedType, config); }; if (config.classNames.length) InternalBDFDB.checkForInstance(pluginData, mappedType, config); - else if (config.stringFind) patchSpecial("findByString", config.stringFind); - else if (config.propertyFind) patchSpecial("findByProperties", config.propertyFind); + else if (config.subComponent && config.subComponent.strings || config.stringFind) patchSpecial("findByString", config.subComponent && config.subComponent.strings || config.stringFind); + else if (config.subComponent && config.subComponent.props || config.propertyFind) patchSpecial("findByProperties", config.subComponent && config.subComponent.props || config.propertyFind); else if (config.nonRender) patchSpecial("findByName", name); else InternalBDFDB.patchComponent(pluginData, BDFDB.ModuleUtils.findByName(name), mappedType, config); } @@ -2180,8 +2175,8 @@ module.exports = (_ => { let toBePatched = config.nonPrototype || !instance.prototype ? instance : instance.prototype; toBePatched = toBePatched && toBePatched.type && typeof toBePatched.type.render == "function" ? toBePatched.type : toBePatched; if (config.subComponent) { - for (let pluginData of pluginDataObjs) BDFDB.PatchUtils.patch(pluginData.plugin, toBePatched, "default", {after: e => { - for (let patchType in pluginData.patchTypes) BDFDB.PatchUtils.patch(pluginData.plugin, e.returnValue, "type", { + for (let pluginData of pluginDataObjs) BDFDB.PatchUtils.patch(pluginData.plugin, toBePatched, config.subComponent.type || "default", {after: e => { + for (let patchType in pluginData.patchTypes) BDFDB.PatchUtils.patch(pluginData.plugin, config.subComponent.children && e.returnValue.props && e.returnValue.props.children ? e.returnValue.props.children[0] || e.returnValue.props.children : e.returnValue , "type", { [patchType]: e2 => InternalBDFDB.initiateProcess(pluginData.plugin, type, { instance: e2.thisObject, returnvalue: e2.returnValue, @@ -2214,8 +2209,8 @@ module.exports = (_ => { return value && (!prop.value || [prop.value].flat(10).filter(n => typeof n == "string").some(n => value.toUpperCase().indexOf(n.toUpperCase()) == 0)); }) && ins.return.type; }; - InternalBDFDB.isMemo = function (exports) { - return exports && exports.default && typeof exports.default.$$typeof == "symbol" && (exports.default.$$typeof.toString() || "").indexOf("memo") > -1; + InternalBDFDB.isMemoOrForwardRef = function (exports) { + return exports && exports.default && typeof exports.default.$$typeof == "symbol" && ((exports.default.$$typeof.toString() || "").indexOf("memo") > -1 || (exports.default.$$typeof.toString() || "").indexOf("forward_ref") > -1); }; InternalBDFDB.checkEle = function (pluginDataObjs, ele, type, config) { pluginDataObjs = [pluginDataObjs].flat(10).filter(n => n); @@ -2226,7 +2221,7 @@ module.exports = (_ => { if (component) { if (config.nonRender) { let exports = (BDFDB.ModuleUtils.find(m => m == component && m, false) || {}).exports; - InternalBDFDB.patchComponent(pluginDataObjs, InternalBDFDB.isMemo(exports) ? exports.default : exports, type, config); + InternalBDFDB.patchComponent(pluginDataObjs, InternalBDFDB.isMemoOrForwardRef(exports) ? exports.default : exports, type, config); } else InternalBDFDB.patchComponent(pluginDataObjs, component, type, config); BDFDB.PatchUtils.forceAllUpdates(pluginDataObjs.map(n => n.plugin), type); @@ -3177,26 +3172,14 @@ module.exports = (_ => { BDFDB.GuildUtils.rerenderAll = function (instant) { BDFDB.TimeUtils.clear(BDFDB.GuildUtils.rerenderAll.timeout); BDFDB.GuildUtils.rerenderAll.timeout = BDFDB.TimeUtils.timeout(_ => { - let GuildsIns = BDFDB.ReactUtils.findOwner(document.querySelector(BDFDB.dotCN.app), {name: "Guilds", unlimited: true}); - let GuildsPrototype = BDFDB.ObjectUtils.get(GuildsIns, `${BDFDB.ReactUtils.instanceKey}.type.prototype`); - if (GuildsIns && GuildsPrototype) { - let injectPlaceholder = returnValue => { - let [children, index] = BDFDB.ReactUtils.findParent(returnValue, {name: "ConnectedUnreadDMs"}); - if (index > -1) children.splice(index + 1, 0, BDFDB.ReactUtils.createElement("div", {})); - BDFDB.ReactUtils.forceUpdate(GuildsIns); - }; - BDFDB.PatchUtils.patch({name: "BDFDB GuildUtils"}, GuildsPrototype, "render", {after: e => { - if (typeof e.returnValue.props.children == "function") { - let childrenRender = e.returnValue.props.children; - e.returnValue.props.children = BDFDB.TimeUtils.suppress((...args) => { - let children = childrenRender(...args); - injectPlaceholder(children); - return children; - }); - } - else injectPlaceholder(e.returnValue); + let ShakeableIns = BDFDB.ReactUtils.findOwner(document.querySelector(BDFDB.dotCN.appcontainer), {name: "Shakeable", unlimited: true, up: true}); + let ShakeablePrototype = BDFDB.ObjectUtils.get(ShakeableIns, `${BDFDB.ReactUtils.instanceKey}.type.prototype`); + if (ShakeableIns && ShakeablePrototype) { + BDFDB.PatchUtils.patch({name: "BDFDB GuildUtils"}, ShakeablePrototype, "render", {after: e => { + e.returnValue.props.children = typeof e.returnValue.props.children == "function" ? (_ => {return null;}) : []; + BDFDB.ReactUtils.forceUpdate(ShakeableIns); }}, {once: true}); - BDFDB.ReactUtils.forceUpdate(GuildsIns); + BDFDB.ReactUtils.forceUpdate(ShakeableIns); } }, instant ? 0 : 1000); }; @@ -6222,13 +6205,13 @@ module.exports = (_ => { let isDraggedGuild = this.props.draggingGuildId === this.props.guild.id; let guild = isDraggedGuild ? BDFDB.ReactUtils.createElement("div", { - children: BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.GuildComponents.Items.DragPlaceholder, {}) + children: BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.GuildComponents.DragPlaceholder, {}) }) : BDFDB.ReactUtils.createElement("div", { className: BDFDB.disCN.guildcontainer, children: BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.GuildComponents.BlobMask, { selected: this.state.isDropHovering || this.props.selected || this.state.hovered, - upperBadge: this.props.unavailable ? InternalComponents.LibraryComponents.GuildComponents.Items.renderUnavailableBadge() : InternalComponents.LibraryComponents.GuildComponents.Items.renderIconBadge(BDFDB.ObjectUtils.extract(this.props, "audio", "video", "screenshare", "liveStage", "hasLiveVoiceChannel", "participating", "participatingInStage")), - lowerBadge: this.props.badge > 0 ? InternalComponents.LibraryComponents.GuildComponents.Items.renderMentionBadge(this.props.badge) : null, + upperBadge: this.props.unavailable ? LibraryModules.GuildBadgeUtils.renderUnavailableBadge() : LibraryModules.GuildBadgeUtils.renderIconBadge(BDFDB.ObjectUtils.extract(this.props, "audio", "video", "screenshare", "liveStage", "hasLiveVoiceChannel", "participating", "participatingInStage")), + lowerBadge: this.props.badge > 0 ? LibraryModules.GuildBadgeUtils.renderMentionBadge(this.props.badge) : null, lowerBadgeWidth: InternalComponents.LibraryComponents.Badges.getBadgeWidthForValue(this.props.badge), children: BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.NavItem, { to: { diff --git a/Library/_res/0BDFDB.data.json b/Library/_res/0BDFDB.data.json index c87bcd5f88..31a4ec1f82 100644 --- a/Library/_res/0BDFDB.data.json +++ b/Library/_res/0BDFDB.data.json @@ -205,11 +205,11 @@ "EmojiPicker": {"strings": ["EMOJI_PICKER_TAB_PANEL_ID", "diversitySelector"]}, "FocusRing": {"props": ["FocusRingScope"]}, "GuestHomeButton": {"props": ["GuestHomeButton"]}, - "Guild": {"subComponent": "ConnectedGuild"}, - "GuildFolder": {"class": "guildfolderwrapper", "special": [{"path": "return.memoizedProps.folderId"}, {"path": "return.memoizedProps.guildIds"}]}, + "Guild": {"subComponent": {"type": "default", "name": "ConnectedGuild"}}, + "GuildFolder": {"props": ["GuildFolderComponent"]}, "GuildIcon": {"class": "avataricon"}, "GuildRoleSettings": {"class": "settingswindowcontentregion"}, - "Guilds": {"strings": ["guildsnav", "ListNavigatorProvider"]}, + "Guilds": {"subComponent": {"type": "type", "children": true, "strings": ["guildsnav", "ListNavigatorProvider"]}}, "GuildSettings": {"class": "layer"}, "GuildSettingsBans": {"class": "guildsettingsbannedcard"}, "GuildSettingsEmoji": {"class": "guildsettingsemojicard"}, @@ -310,10 +310,11 @@ "FriendsEmptyState": {"strings": ["FriendsEmptyState", "FriendsSections"], "value": "default"}, "GuildComponents Badge": {"name": "GuildBadge"}, "GuildComponents BlobMask": {"name": "BlobMask"}, + "GuildComponents DragPlaceholder": {"name": "DragPlaceholder"}, "GuildComponents Icon": {"name": "GuildIconWrapper"}, - "GuildComponents Items": {"props": ["Separator", "DragPlaceholder"]}, "GuildComponents MutedText": {"props": ["useMutedUntilText"], "value": "default"}, "GuildComponents Pill": {"strings": ["opacity:1,height:", "20:8", "default.item"]}, + "GuildComponents Separator": {"strings": ["className", "default.guildSeparator"]}, "Header": {"name": "Header"}, "HeaderBarComponents": {"name": "HeaderBarContainer"}, "Image": {"props": ["ImageReadyStates"]}, diff --git a/Plugins/FriendNotifications/FriendNotifications.plugin.js b/Plugins/FriendNotifications/FriendNotifications.plugin.js index 8b80aea522..54978627a1 100644 --- a/Plugins/FriendNotifications/FriendNotifications.plugin.js +++ b/Plugins/FriendNotifications/FriendNotifications.plugin.js @@ -2,7 +2,7 @@ * @name FriendNotifications * @author DevilBro * @authorId 278543574059057154 - * @version 1.7.8 + * @version 1.7.9 * @description Shows a Notification when a Friend or a User, you choose to observe, changes their Status * @invite Jx3TjNS * @donate https://www.paypal.me/MircoWittrien @@ -17,12 +17,12 @@ module.exports = (_ => { "info": { "name": "FriendNotifications", "author": "DevilBro", - "version": "1.7.8", + "version": "1.7.9", "description": "Shows a Notification when a Friend or a User, you choose to observe, changes their Status" }, "changeLog": { "fixed": { - "Log In Option": "Now also works for Desktop Notifications" + "Log In Option": "Now also Works for Desktop Notifications" } } }; @@ -245,7 +245,7 @@ module.exports = (_ => { this.patchedModules = { after: { - Guilds: "render" + Guilds: "type" } }; @@ -296,6 +296,8 @@ module.exports = (_ => { forceUpdateAll () { defaultSettings = Object.assign(BDFDB.ObjectUtils.map(statuses, status => notificationTypes[status.value ? "TOAST" : "DISABLED"].value), {timelog: true}, BDFDB.DataUtils.load(this, "defaultSettings")); + + BDFDB.GuildUtils.rerenderAll(); BDFDB.PatchUtils.forceAllUpdates(this); } @@ -734,34 +736,8 @@ module.exports = (_ => { } processGuilds (e) { - if (this.settings.general.addOnlineCount) { - if (typeof e.returnvalue.props.children == "function") { - let childrenRender = e.returnvalue.props.children; - e.returnvalue.props.children = BDFDB.TimeUtils.suppress((...args) => { - let children = childrenRender(...args); - this.checkTree(children); - return children; - }, "", this); - } - else this.checkTree(e.returnvalue); - } - } - - checkTree (returnvalue) { - let tree = BDFDB.ReactUtils.findChild(returnvalue, {filter: n => n && n.props && typeof n.props.children == "function"}); - if (tree) { - let childrenRender = tree.props.children; - tree.props.children = BDFDB.TimeUtils.suppress((...args) => { - let children = childrenRender(...args); - this.injectCounter(children); - return children; - }, "", this); - } - else this.injectCounter(returnvalue); - } - - injectCounter (returnvalue) { - let [children, index] = BDFDB.ReactUtils.findParent(returnvalue, {name: "ConnectedUnreadDMs"}); + console.log(e); + let [children, index] = BDFDB.ReactUtils.findParent(e.returnvalue, {name: "UnreadDMs"}); if (index > -1) children.splice(index, 0, BDFDB.ReactUtils.createElement(FriendOnlineCounterComponent, { amount: this.getOnlineCount() })); diff --git a/Plugins/ReadAllNotificationsButton/ReadAllNotificationsButton.plugin.js b/Plugins/ReadAllNotificationsButton/ReadAllNotificationsButton.plugin.js index b0d7cb6a14..cb715f44a1 100644 --- a/Plugins/ReadAllNotificationsButton/ReadAllNotificationsButton.plugin.js +++ b/Plugins/ReadAllNotificationsButton/ReadAllNotificationsButton.plugin.js @@ -2,7 +2,7 @@ * @name ReadAllNotificationsButton * @author DevilBro * @authorId 278543574059057154 - * @version 1.6.8 + * @version 1.6.9 * @description Adds a Clear Button to the Server List and the Mentions Popout * @invite Jx3TjNS * @donate https://www.paypal.me/MircoWittrien @@ -17,7 +17,7 @@ module.exports = (_ => { "info": { "name": "ReadAllNotificationsButton", "author": "DevilBro", - "version": "1.6.8", + "version": "1.6.9", "description": "Adds a Clear Button to the Server List and the Mentions Popout" } }; @@ -70,12 +70,11 @@ module.exports = (_ => { } : (([Plugin, BDFDB]) => { var _this; var blacklist, clearing; - var settings = {}; const ReadAllButtonComponent = class ReadAllButton extends BdApi.React.Component { clearClick() { - if (settings.includeGuilds) this.clearGuilds(settings.includeMuted ? this.getGuilds() : this.getUnread()); - if (settings.includeDMs) BDFDB.DMUtils.markAsRead(this.getPingedDMs()); + if (_this.settings.batch.guilds) this.clearGuilds(_this.settings.batch.muted ? this.getGuilds() : this.getUnread()); + if (_this.settings.batch.dms) BDFDB.DMUtils.markAsRead(this.getPingedDMs()); } clearGuilds(guildIds) { BDFDB.GuildUtils.markAsRead(guildIds.filter(id => id && !blacklist.includes(id))); @@ -104,7 +103,7 @@ module.exports = (_ => { className: BDFDB.disCNS.guildiconchildwrapper + BDFDB.disCN._readallnotificationsbuttonbutton, children: "read all", onClick: _ => { - if (!settings.confirmClear) this.clearClick(); + if (!_this.settings.general.confirmClear) this.clearClick(); else BDFDB.ModalUtils.confirm(_this, _this.labels.modal_confirmnotifications, _ => this.clearClick()); }, onContextMenu: event => { @@ -149,18 +148,20 @@ module.exports = (_ => { _this = this; this.defaults = { - settings: { - addClearButton: {value: true, inner: false, description: "Add a 'Clear Mentions' button to the recent mentions popout"}, - confirmClear: {value: false, inner: false, description: "Ask for your confirmation before clearing reads"}, - includeGuilds: {value: true, inner: true, description: "unread Servers"}, - includeMuted: {value: false, inner: true, description: "muted unread Servers"}, - includeDMs: {value: false, inner: true, description: "unread DMs"} + general: { + addClearButton: {value: true, description: "Add a 'Clear Mentions' button to the recent mentions popout"}, + confirmClear: {value: false, description: "Ask for your confirmation before clearing reads"} + }, + batch: { + guilds: {value: true, description: "unread Servers"}, + muted: {value: false, description: "muted unread Servers"}, + dms: {value: false, description: "unread DMs"} } }; this.patchedModules = { after: { - Guilds: "render", + Guilds: "type", RecentMentions: "default", RecentsHeader: "default" } @@ -211,22 +212,22 @@ module.exports = (_ => { settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, { title: "Settings", collapseStates: collapseStates, - children: Object.keys(settings).filter(key => !this.defaults.settings[key].inner).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, { + children: Object.keys(this.defaults.general).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, { type: "Switch", plugin: this, - keys: ["settings", key], - label: this.defaults.settings[key].description, - value: settings[key] + keys: ["general", key], + label: this.defaults.general[key].description, + value: this.settings.general[key] })).concat(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelList, { - title: "When left clicking the 'read all' button mark following Elements as read:", + title: "When left clicking the 'read all' Button mark following Elements as read:", first: false, last: true, - children: Object.keys(settings).filter(key => this.defaults.settings[key].inner).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, { + children: Object.keys(this.defaults.batch).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, { type: "Switch", plugin: this, - keys: ["settings", key], - label: this.defaults.settings[key].description, - value: settings[key] + keys: ["batch", key], + label: this.defaults.batch[key].description, + value: this.settings.batch[key] })) })) })); @@ -274,38 +275,12 @@ module.exports = (_ => { } forceUpdateAll () { - settings = BDFDB.DataUtils.get(this, "settings"); - BDFDB.PatchUtils.forceAllUpdates(this); + BDFDB.GuildUtils.rerenderAll(); } - + processGuilds (e) { - if (typeof e.returnvalue.props.children == "function") { - let childrenRender = e.returnvalue.props.children; - e.returnvalue.props.children = (...args) => { - let children = childrenRender(...args); - this.checkTree(children); - return children; - }; - } - else this.checkTree(e.returnvalue); - } - - checkTree (returnvalue) { - let tree = BDFDB.ReactUtils.findChild(returnvalue, {filter: n => n && n.props && typeof n.props.children == "function"}); - if (tree) { - let childrenRender = tree.props.children; - tree.props.children = BDFDB.TimeUtils.suppress((...args) => { - let children = childrenRender(...args); - this.handleGuilds(children); - return children; - }, "", this); - } - else this.handleGuilds(returnvalue); - } - - handleGuilds (returnvalue) { - let [children, index] = BDFDB.ReactUtils.findParent(returnvalue, {name: "ConnectedUnreadDMs"}); + let [children, index] = BDFDB.ReactUtils.findParent(e.returnvalue, {name: "UnreadDMs"}); if (index > -1) children.splice(index + 1, 0, BDFDB.ReactUtils.createElement(ReadAllButtonComponent, {})); } @@ -314,7 +289,7 @@ module.exports = (_ => { } processRecentsHeader (e) { - if (settings.addClearButton && e.instance.props.tab == "Recent Mentions") e.returnvalue.props.children.push(BDFDB.ReactUtils.createElement("div", { + if (this.settings.general.addClearButton && e.instance.props.tab == "Recent Mentions") e.returnvalue.props.children.push(BDFDB.ReactUtils.createElement("div", { children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, { text: `${BDFDB.LanguageUtils.LanguageStrings.CLOSE} (${BDFDB.LanguageUtils.LanguageStrings.FORM_LABEL_ALL})`, children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Clickable, { @@ -352,7 +327,7 @@ module.exports = (_ => { }, i * 1000); } }; - if (settings.confirmClear) BDFDB.ModalUtils.confirm(this, this.labels.modal_confirmmentions, clear); + if (this.settings.general.confirmClear) BDFDB.ModalUtils.confirm(this, this.labels.modal_confirmmentions, clear); else clear(); } })