Plugin

CopyEmojiMarkdown

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

Emotes Utility
index.tsx
Download

Source

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