From af1edc88bf4be9a74b6cd32b9c8e0c17935b5f77 Mon Sep 17 00:00:00 2001 From: sadan4 <117494111+sadan4@users.noreply.github.com> Date: Wed, 13 Nov 2024 13:27:21 -0500 Subject: [PATCH 1/5] FakeNitro: Fix embedding animated emojis (#3012) --- src/plugins/fakeNitro/index.tsx | 8 ++++---- src/utils/discord.tsx | 13 ++++++++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/plugins/fakeNitro/index.tsx b/src/plugins/fakeNitro/index.tsx index 087bb555..86c5ae4d 100644 --- a/src/plugins/fakeNitro/index.tsx +++ b/src/plugins/fakeNitro/index.tsx @@ -20,11 +20,11 @@ import { addPreEditListener, addPreSendListener, removePreEditListener, removePr import { definePluginSettings } from "@api/Settings"; import { Devs } from "@utils/constants"; import { ApngBlendOp, ApngDisposeOp, importApngJs } from "@utils/dependencies"; -import { getCurrentGuild } from "@utils/discord"; +import { getCurrentGuild, getEmojiURL } from "@utils/discord"; import { Logger } from "@utils/Logger"; import definePlugin, { OptionType, Patch } from "@utils/types"; import { findByCodeLazy, findByPropsLazy, findStoreLazy, proxyLazyWebpack } from "@webpack"; -import { Alerts, ChannelStore, DraftType, EmojiStore, FluxDispatcher, Forms, GuildMemberStore, IconUtils, lodash, Parser, PermissionsBits, PermissionStore, UploadHandler, UserSettingsActionCreators, UserStore } from "@webpack/common"; +import { Alerts, ChannelStore, DraftType, EmojiStore, FluxDispatcher, Forms, GuildMemberStore, lodash, Parser, PermissionsBits, PermissionStore, UploadHandler, UserSettingsActionCreators, UserStore } from "@webpack/common"; import type { Emoji } from "@webpack/types"; import type { Message } from "discord-types/general"; import { applyPalette, GIFEncoder, quantize } from "gifenc"; @@ -920,7 +920,7 @@ export default definePlugin({ const emojiString = `<${emoji.animated ? "a" : ""}:${emoji.originalName || emoji.name}:${emoji.id}>`; - const url = new URL(IconUtils.getEmojiURL({ id: emoji.id, animated: emoji.animated, size: s.emojiSize })); + const url = new URL(getEmojiURL(emoji.id, emoji.animated, s.emojiSize)); url.searchParams.set("size", s.emojiSize.toString()); url.searchParams.set("name", emoji.name); @@ -953,7 +953,7 @@ export default definePlugin({ hasBypass = true; - const url = new URL(IconUtils.getEmojiURL({ id: emoji.id, animated: emoji.animated, size: s.emojiSize })); + const url = new URL(getEmojiURL(emoji.id, emoji.animated, s.emojiSize)); url.searchParams.set("size", s.emojiSize.toString()); url.searchParams.set("name", emoji.name); diff --git a/src/utils/discord.tsx b/src/utils/discord.tsx index 91fd791b..ec96d0d4 100644 --- a/src/utils/discord.tsx +++ b/src/utils/discord.tsx @@ -19,7 +19,7 @@ import "./discord.css"; import { MessageObject } from "@api/MessageEvents"; -import { ChannelStore, ComponentDispatch, Constants, FluxDispatcher, GuildStore, i18n, InviteActions, MessageActions, PrivateChannelsStore, RestAPI, SelectedChannelStore, SelectedGuildStore, UserProfileActions, UserProfileStore, UserSettingsActionCreators, UserUtils } from "@webpack/common"; +import { ChannelStore, ComponentDispatch, Constants, FluxDispatcher, GuildStore, i18n, IconUtils, InviteActions, MessageActions, PrivateChannelsStore, RestAPI, SelectedChannelStore, SelectedGuildStore, UserProfileActions, UserProfileStore, UserSettingsActionCreators, UserUtils } from "@webpack/common"; import { Channel, Guild, Message, User } from "discord-types/general"; import { Except } from "type-fest"; @@ -212,3 +212,14 @@ export async function fetchUserProfile(id: string, options?: FetchUserProfileOpt export function getUniqueUsername(user: User) { return user.discriminator === "0" ? user.username : user.tag; } + +/** + * Get the URL for an emoji. This function always returns a gif URL for animated emojis, instead of webp + * @param id The emoji id + * @param animated Whether the emoji is animated + * @param size The size for the emoji + */ +export function getEmojiURL(id: string, animated: boolean, size: number) { + const url = IconUtils.getEmojiURL({ id, animated, size }); + return animated ? url.replace(".webp", ".gif") : url; +} From 211569f7f5c4023f3ef5f4a3b52b6e495d025ff6 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Wed, 13 Nov 2024 15:41:57 -0300 Subject: [PATCH 2/5] AlwaysExpandRoles: Fix collapse roles button not appearing --- src/plugins/alwaysExpandRoles/index.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/plugins/alwaysExpandRoles/index.ts b/src/plugins/alwaysExpandRoles/index.ts index 1c20b977..c674f90c 100644 --- a/src/plugins/alwaysExpandRoles/index.ts +++ b/src/plugins/alwaysExpandRoles/index.ts @@ -28,10 +28,18 @@ export default definePlugin({ patches: [ { find: 'action:"EXPAND_ROLES"', - replacement: { - match: /(roles:\i(?=.+?(\i)\(!0\)[,;]\i\({action:"EXPAND_ROLES"}\)).+?\[\i,\2\]=\i\.useState\()!1\)/, - replace: (_, rest, setExpandedRoles) => `${rest}!0)` - } + replacement: [ + { + match: /(roles:\i(?=.+?(\i)\(!0\)[,;]\i\({action:"EXPAND_ROLES"}\)).+?\[\i,\2\]=\i\.useState\()!1\)/, + replace: (_, rest, setExpandedRoles) => `${rest}!0)` + }, + { + // Fix not calculating non-expanded roles because the above patch makes the default "expanded", + // which makes the collapse button never show up and calculation never occur + match: /(?<=useLayoutEffect\(\(\)=>{if\()\i/, + replace: isExpanded => "false" + } + ] } ] }); From 66a75747f80ad89e4047b378a7552847c1f2fd8e Mon Sep 17 00:00:00 2001 From: sadan4 <117494111+sadan4@users.noreply.github.com> Date: Wed, 13 Nov 2024 15:44:13 -0500 Subject: [PATCH 3/5] ViewIcons: Fix conflict with unread Group DMs (#3011) --- src/plugins/viewIcons/index.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/plugins/viewIcons/index.tsx b/src/plugins/viewIcons/index.tsx index 62970814..c53116b4 100644 --- a/src/plugins/viewIcons/index.tsx +++ b/src/plugins/viewIcons/index.tsx @@ -209,10 +209,11 @@ export default definePlugin({ }, // Group DMs top small & large icon { - find: /\.recipients\.length>=2(?! `${m},onClick:()=>$self.openAvatar(${iconUrl})` + // We have to check that icon is not an unread GDM in the server bar + replace: (m, iconUrl) => `${m},onClick:()=>arguments[0]?.size!=="SIZE_48"&&$self.openAvatar(${iconUrl})` } }, // User DMs top small icon From e0d66ff0719ce9c51c685dbdd6000ffc06b06d25 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Wed, 13 Nov 2024 18:02:18 -0300 Subject: [PATCH 4/5] NoMosaic: Fix plugin not working in Canary --- src/plugins/consoleJanitor/index.ts | 7 ------- src/plugins/noMosaic/index.ts | 6 +++--- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/plugins/consoleJanitor/index.ts b/src/plugins/consoleJanitor/index.ts index 4c5499cf..a02fcad1 100644 --- a/src/plugins/consoleJanitor/index.ts +++ b/src/plugins/consoleJanitor/index.ts @@ -151,13 +151,6 @@ export default definePlugin({ replace: "" } }, - { - find: "[DEPRECATED] `context` will be removed in a future version. Instead use `import { createStore, useStore } from 'zustand'`. See: https://github.com/pmndrs/zustand/discussions/1180.", - replacement: { - match: /console\.warn\("\[DEPRECATED\] `context` will be removed in a future version\. Instead use `import { createStore, useStore } from 'zustand'`\. See: https:\/\/github\.com\/pmndrs\/zustand\/discussions\/1180\."\);/, - replace: "" - } - }, // Patches discords generic logger function { find: "Σ:", diff --git a/src/plugins/noMosaic/index.ts b/src/plugins/noMosaic/index.ts index 962b90fe..6ff34a35 100644 --- a/src/plugins/noMosaic/index.ts +++ b/src/plugins/noMosaic/index.ts @@ -20,7 +20,7 @@ const settings = definePluginSettings({ export default definePlugin({ name: "NoMosaic", authors: [Devs.AutumnVN], - description: "Removes Discord new image mosaic", + description: "Removes Discord image mosaic", tags: ["image", "mosaic", "media"], settings, @@ -29,8 +29,8 @@ export default definePlugin({ { find: '=>"IMAGE"===', replacement: { - match: /=>"IMAGE"===\i\|\|"VIDEO"===\i;/, - replace: "=>false;" + match: /=>"IMAGE"===\i\|\|"VIDEO"===\i(?:\|\|("VISUAL_PLACEHOLDER"===\i))?;/, + replace: (_, visualPlaceholderPred) => visualPlaceholderPred != null ? `=>${visualPlaceholderPred};` : "=>false;" } }, { From 25ceff5ec2ba708f3668bac7a4338549b09ad71c Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Wed, 13 Nov 2024 18:44:21 -0300 Subject: [PATCH 5/5] ChunkLoader: Avoid CSS debugging chunk --- src/debug/loadLazyChunks.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/debug/loadLazyChunks.ts b/src/debug/loadLazyChunks.ts index b7a8fbc6..6923d3a2 100644 --- a/src/debug/loadLazyChunks.ts +++ b/src/debug/loadLazyChunks.ts @@ -27,7 +27,12 @@ export async function loadLazyChunks() { const LazyChunkRegex = canonicalizeMatch(/(?:(?:Promise\.all\(\[)?(\i\.e\("?[^)]+?"?\)[^\]]*?)(?:\]\))?)\.then\(\i\.bind\(\i,"?([^)]+?)"?\)\)/g); + const foundCssDebuggingLoad = false; + async function searchAndLoadLazyChunks(factoryCode: string) { + // Workaround to avoid loading the CSS debugging chunk which turns the app pink + const hasCssDebuggingLoad = foundCssDebuggingLoad ? false : factoryCode.includes(".cssDebuggingEnabled&&"); + const lazyChunks = factoryCode.matchAll(LazyChunkRegex); const validChunkGroups = new Set<[chunkIds: number[], entryPoint: number]>(); @@ -43,6 +48,16 @@ export async function loadLazyChunks() { let invalidChunkGroup = false; for (const id of chunkIds) { + if (hasCssDebuggingLoad) { + if (chunkIds.length > 1) { + throw new Error("Found multiple chunks in factory that loads the CSS debugging chunk"); + } + + invalidChunks.add(id); + invalidChunkGroup = true; + break; + } + if (wreq.u(id) == null || wreq.u(id) === "undefined.js") continue; const isWorkerAsset = await fetch(wreq.p + wreq.u(id))