diff options
-rw-r--r-- | src/api/ContextMenu.ts | 5 | ||||
-rw-r--r-- | src/plugins/devCompanion.dev.tsx | 2 | ||||
-rw-r--r-- | src/plugins/emoteCloner.tsx | 6 | ||||
-rw-r--r-- | src/plugins/fakeNitro.tsx | 57 | ||||
-rw-r--r-- | src/plugins/imageZoom/index.tsx | 98 | ||||
-rw-r--r-- | src/plugins/messageLogger/index.tsx | 1 | ||||
-rw-r--r-- | src/plugins/pronoundb/pronoundbUtils.ts | 2 | ||||
-rw-r--r-- | src/plugins/reverseImageSearch.tsx | 2 | ||||
-rw-r--r-- | src/plugins/viewIcons.tsx | 8 |
9 files changed, 69 insertions, 112 deletions
diff --git a/src/api/ContextMenu.ts b/src/api/ContextMenu.ts index 16f9f32..4e52131 100644 --- a/src/api/ContextMenu.ts +++ b/src/api/ContextMenu.ts @@ -118,7 +118,12 @@ interface ContextMenuProps { onClose: (callback: (...args: Array<any>) => any) => void; } +const patchedMenus = new WeakSet(); + export function _patchContextMenu(props: ContextMenuProps) { + if (patchedMenus.has(props)) return; + patchedMenus.add(props); + props.contextMenuApiArguments ??= []; const contextMenuPatches = navPatches.get(props.navId); diff --git a/src/plugins/devCompanion.dev.tsx b/src/plugins/devCompanion.dev.tsx index b84dd75..e9b7394 100644 --- a/src/plugins/devCompanion.dev.tsx +++ b/src/plugins/devCompanion.dev.tsx @@ -238,8 +238,6 @@ function initWs(isManual = false) { } const contextMenuPatch: NavContextMenuPatchCallback = kids => { - if (kids.some(k => k?.props?.id === NAV_ID)) return; - kids.unshift( <Menu.MenuItem id={NAV_ID} diff --git a/src/plugins/emoteCloner.tsx b/src/plugins/emoteCloner.tsx index 4a018ec..809518c 100644 --- a/src/plugins/emoteCloner.tsx +++ b/src/plugins/emoteCloner.tsx @@ -220,8 +220,7 @@ const messageContextMenuPatch: NavContextMenuPatchCallback = (children, props) = const name = match[1] ?? "FakeNitroEmoji"; const group = findGroupChildrenByChildId("copy-link", children); - if (group && !group.some(child => child?.props?.id === "emote-cloner")) - group.push(buildMenuItem(favoriteableId, name, isGifUrl(itemHref ?? itemSrc))); + if (group) group.push(buildMenuItem(favoriteableId, name, isGifUrl(itemHref ?? itemSrc))); }; const expressionPickerPatch: NavContextMenuPatchCallback = (children, props: { target: HTMLElement; }) => { @@ -230,8 +229,7 @@ const expressionPickerPatch: NavContextMenuPatchCallback = (children, props: { t const firstChild = props.target.firstChild as HTMLImageElement; - if (!children.some(c => c?.props?.id === "emote-cloner")) - children.push(buildMenuItem(id, name, firstChild && isGifUrl(firstChild.src))); + children.push(buildMenuItem(id, name, firstChild && isGifUrl(firstChild.src))); }; export default definePlugin({ diff --git a/src/plugins/fakeNitro.tsx b/src/plugins/fakeNitro.tsx index c2b81d1..4a4f47d 100644 --- a/src/plugins/fakeNitro.tsx +++ b/src/plugins/fakeNitro.tsx @@ -136,6 +136,11 @@ const settings = definePluginSettings({ default: true, restartNeeded: true }, + transformCompoundSentence: { + description: "Whether to transform fake stickers and emojis in compound sentences (sentences with more content than just the fake emoji or sticker link)", + type: OptionType.BOOLEAN, + default: false + }, enableStreamQualityBypass: { description: "Allow streaming in nitro quality", type: OptionType.BOOLEAN, @@ -305,45 +310,6 @@ export default definePlugin({ } ], - options: { - enableEmojiBypass: { - description: "Allow sending fake emojis", - type: OptionType.BOOLEAN, - default: true, - restartNeeded: true, - }, - emojiSize: { - description: "Size of the emojis when sending", - type: OptionType.SLIDER, - default: 48, - markers: [32, 48, 64, 128, 160, 256, 512], - }, - transformEmojis: { - description: "Whether to transform fake emojis into real ones", - type: OptionType.BOOLEAN, - default: true, - restartNeeded: true, - }, - enableStickerBypass: { - description: "Allow sending fake stickers", - type: OptionType.BOOLEAN, - default: true, - restartNeeded: true, - }, - stickerSize: { - description: "Size of the stickers when sending", - type: OptionType.SLIDER, - default: 160, - markers: [32, 64, 128, 160, 256, 512], - }, - enableStreamQualityBypass: { - description: "Allow streaming in nitro quality", - type: OptionType.BOOLEAN, - default: true, - restartNeeded: true, - } - }, - get guildId() { return getCurrentGuild()?.id; }, @@ -419,7 +385,7 @@ export default definePlugin({ }, patchFakeNitroEmojisOrRemoveStickersLinks(content: Array<any>, inline: boolean) { - if (content.length > 1) return content; + if (content.length > 1 && !settings.store.transformCompoundSentence) return content; const newContent: Array<any> = []; @@ -442,7 +408,7 @@ export default definePlugin({ const emojiName = EmojiStore.getCustomEmojiById(fakeNitroMatch[1])?.name ?? url?.searchParams.get("name") ?? "FakeNitroEmoji"; newContent.push(Parser.defaultRules.customEmoji.react({ - jumboable: !inline, + jumboable: !inline && content.length === 1, animated: fakeNitroMatch[2] === "gif", emojiId: fakeNitroMatch[1], name: emojiName, @@ -466,8 +432,8 @@ export default definePlugin({ newContent.push(element); } - const firstTextElementIdx = newContent.findIndex(element => typeof element === "string"); - if (firstTextElementIdx !== -1) newContent[firstTextElementIdx] = newContent[firstTextElementIdx].trimStart(); + const firstContent = newContent[0]; + if (typeof firstContent === "string") newContent[0] = firstContent.trimStart(); return newContent; }, @@ -476,7 +442,8 @@ export default definePlugin({ const itemsToMaybePush: Array<string> = []; const contentItems = message.content.split(/\s/); - if (contentItems.length === 1) itemsToMaybePush.push(contentItems[0]); + if (contentItems.length === 1 && !settings.store.transformCompoundSentence) itemsToMaybePush.push(contentItems[0]); + else itemsToMaybePush.push(...contentItems); itemsToMaybePush.push(...message.attachments.filter(attachment => attachment.content_type === "image/gif").map(attachment => attachment.url)); @@ -517,7 +484,7 @@ export default definePlugin({ }, shouldIgnoreEmbed(embed: Message["embeds"][number], message: Message) { - if (message.content.split(/\s/).length > 1) return false; + if (message.content.split(/\s/).length > 1 && !settings.store.transformCompoundSentence) return false; switch (embed.type) { case "image": { diff --git a/src/plugins/imageZoom/index.tsx b/src/plugins/imageZoom/index.tsx index 6014756..d65df08 100644 --- a/src/plugins/imageZoom/index.tsx +++ b/src/plugins/imageZoom/index.tsx @@ -76,56 +76,54 @@ export const settings = definePluginSettings({ const imageContextMenuPatch: NavContextMenuPatchCallback = (children, _) => { - if (!children.some(child => child?.props?.id === "image-zoom")) { - children.push( - <Menu.MenuGroup id="image-zoom"> - {/* thanks SpotifyControls */} - <Menu.MenuControlItem - id="zoom" - label="Zoom" - control={(props, ref) => ( - <Menu.MenuSliderControl - ref={ref} - {...props} - minValue={1} - maxValue={50} - value={settings.store.zoom} - onChange={debounce((value: number) => settings.store.zoom = value, 100)} - /> - )} - /> - <Menu.MenuControlItem - id="size" - label="Lens Size" - control={(props, ref) => ( - <Menu.MenuSliderControl - ref={ref} - {...props} - minValue={50} - maxValue={1000} - value={settings.store.size} - onChange={debounce((value: number) => settings.store.size = value, 100)} - /> - )} - /> - <Menu.MenuControlItem - id="zoom-speed" - label="Zoom Speed" - control={(props, ref) => ( - <Menu.MenuSliderControl - ref={ref} - {...props} - minValue={0.1} - maxValue={5} - value={settings.store.zoomSpeed} - onChange={debounce((value: number) => settings.store.zoomSpeed = value, 100)} - renderValue={(value: number) => `${value.toFixed(3)}x`} - /> - )} - /> - </Menu.MenuGroup> - ); - } + children.push( + <Menu.MenuGroup id="image-zoom"> + {/* thanks SpotifyControls */} + <Menu.MenuControlItem + id="zoom" + label="Zoom" + control={(props, ref) => ( + <Menu.MenuSliderControl + ref={ref} + {...props} + minValue={1} + maxValue={50} + value={settings.store.zoom} + onChange={debounce((value: number) => settings.store.zoom = value, 100)} + /> + )} + /> + <Menu.MenuControlItem + id="size" + label="Lens Size" + control={(props, ref) => ( + <Menu.MenuSliderControl + ref={ref} + {...props} + minValue={50} + maxValue={1000} + value={settings.store.size} + onChange={debounce((value: number) => settings.store.size = value, 100)} + /> + )} + /> + <Menu.MenuControlItem + id="zoom-speed" + label="Zoom Speed" + control={(props, ref) => ( + <Menu.MenuSliderControl + ref={ref} + {...props} + minValue={0.1} + maxValue={5} + value={settings.store.zoomSpeed} + onChange={debounce((value: number) => settings.store.zoomSpeed = value, 100)} + renderValue={(value: number) => `${value.toFixed(3)}x`} + /> + )} + /> + </Menu.MenuGroup> + ); }; export default definePlugin({ diff --git a/src/plugins/messageLogger/index.tsx b/src/plugins/messageLogger/index.tsx index 8199271..808fd34 100644 --- a/src/plugins/messageLogger/index.tsx +++ b/src/plugins/messageLogger/index.tsx @@ -49,7 +49,6 @@ const patchMessageContextMenu: NavContextMenuPatchCallback = (children, props) = const { deleted, editHistory, id, channel_id } = message; if (!deleted && !editHistory?.length) return; - if (children.some(c => c?.props?.id === MENU_ITEM_ID)) return; children.push(( <Menu.MenuItem diff --git a/src/plugins/pronoundb/pronoundbUtils.ts b/src/plugins/pronoundb/pronoundbUtils.ts index 0884261..c2354c3 100644 --- a/src/plugins/pronoundb/pronoundbUtils.ts +++ b/src/plugins/pronoundb/pronoundbUtils.ts @@ -35,7 +35,7 @@ const bulkFetch = debounce(async () => { const pronouns = await bulkFetchPronouns(ids); for (const id of ids) { // Call all callbacks for the id - requestQueue[id].forEach(c => c(pronouns[id])); + requestQueue[id]?.forEach(c => c(pronouns[id])); delete requestQueue[id]; } }); diff --git a/src/plugins/reverseImageSearch.tsx b/src/plugins/reverseImageSearch.tsx index 4e0a361..74b2619 100644 --- a/src/plugins/reverseImageSearch.tsx +++ b/src/plugins/reverseImageSearch.tsx @@ -43,7 +43,7 @@ const imageContextMenuPatch: NavContextMenuPatchCallback = (children, props) => const src = itemHref ?? itemSrc; const group = findGroupChildrenByChildId("copy-link", children); - if (group && !group.some(child => child?.props?.id === "search-image")) { + if (group) { group.push(( <Menu.MenuItem label="Search Image" diff --git a/src/plugins/viewIcons.tsx b/src/plugins/viewIcons.tsx index 8b3d31d..cff4fe6 100644 --- a/src/plugins/viewIcons.tsx +++ b/src/plugins/viewIcons.tsx @@ -80,12 +80,7 @@ function openImage(url: string) { )); } -const seen = new WeakSet(); - const UserContext: NavContextMenuPatchCallback = (children, { user, guildId }: UserContextProps) => { - if (seen.has(children)) return; - seen.add(children); - const memberAvatar = GuildMemberStore.getMember(guildId!, user.id)?.avatar || null; children.splice(1, 0, ( @@ -111,9 +106,6 @@ const UserContext: NavContextMenuPatchCallback = (children, { user, guildId }: U }; const GuildContext: NavContextMenuPatchCallback = (children, { guild: { id, icon, banner } }: GuildContextProps) => { - if (seen.has(children)) return; - seen.add(children); - if (!banner && !icon) return; // before copy id (if it exists) |