Plugin

CopyEmojiMarkdown

Allows you to copy emojis as formatted string (<:blobcatcozy:1026533070955872337>)

Emotes Utility
index.tsx
Download

Source

src/plugins/copyEmojiMarkdown/index.tsx
1/*
2 * FiveCord โ€” a Discord client mod
3 * Copyright (c) 2025 FiveCord
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
7import { definePluginSettings } from "@api/Settings";
8import { Devs } from "@utils/constants";
9import { copyWithToast } from "@utils/discord";
10import definePlugin, { OptionType } from "@utils/types";
11import { findByPropsLazy } from "@webpack";
12import { Menu } from "@webpack/common";
13
14const { convertNameToSurrogate } = findByPropsLazy("convertNameToSurrogate");
15
16interface Emoji {
17 type: string;
18 id: string;
19 name: string;
20}
21
22interface Target {
23 dataset: Emoji;
24 firstChild: HTMLImageElement;
25}
26
27function getEmojiMarkdown(target: Target, copyUnicode: boolean): string {
28 const { id: emojiId, name: emojiName } = target.dataset;
29
30 if (!emojiId) {
31 return copyUnicode
32 ? convertNameToSurrogate(emojiName)
33 : `:${emojiName}:`;
34 }
35
36 const url = new URL(target.firstChild.src);
37 const hasParam = url.searchParams.get("animated") === "true";
38 const isGif = url.pathname.endsWith(".gif");
39
40 return `<${(hasParam || isGif) ? "a" : ""}:${emojiName.replace(/~\d+$/, "")}:${emojiId}>`;
41}
42
43const settings = definePluginSettings({
44 copyUnicode: {
45 type: OptionType.BOOLEAN,
46 description: "Copy the raw unicode character instead of :name: for default emojis (๐Ÿ‘ฝ)",
47 default: true,
48 },
49});
50
51export default definePlugin({
52 name: "CopyEmojiMarkdown",
53 description: "Allows you to copy emojis as formatted string (<:blobcatcozy:1026533070955872337>)",
54 tags: ["Emotes", "Utility"],
55 authors: [Devs.HappyEnderman, Devs.Vishnya],
56 settings,
57
58 contextMenus: {
59 "expression-picker"(children, { target }: { target: Target; }) {
60 if (target.dataset.type !== "emoji") return;
61
62 children.push(
63 <Menu.MenuItem
64 id="vc-copy-emoji-markdown"
65 label="Copy Emoji Markdown"
66 action={() => {
67 copyWithToast(
68 getEmojiMarkdown(target, settings.store.copyUnicode),
69 "Success! Copied emoji markdown."
70 );
71 }}
72 />
73 );
74 },
75 },
76});
77