Plugin
CopyEmojiMarkdown
Allows you to copy emojis as formatted string (<:blobcatcozy:1026533070955872337>)
1
/*2
* FiveCord โ a Discord client mod3
* Copyright (c) 2025 FiveCord4
* SPDX-License-Identifier: GPL-3.0-or-later5
*/6
7
import { definePluginSettings } from "@api/Settings";8
import { Devs } from "@utils/constants";9
import { copyWithToast } from "@utils/discord";10
import definePlugin, { OptionType } from "@utils/types";11
import { findByPropsLazy } from "@webpack";12
import { Menu } from "@webpack/common";13
14
const { convertNameToSurrogate } = findByPropsLazy("convertNameToSurrogate");15
16
interface Emoji {17
type: string;18
id: string;19
name: string;20
}21
22
interface Target {23
dataset: Emoji;24
firstChild: HTMLImageElement;25
}26
27
function getEmojiMarkdown(target: Target, copyUnicode: boolean): string {28
const { id: emojiId, name: emojiName } = target.dataset;29
30
if (!emojiId) {31
return copyUnicode32
? 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
43
const 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
51
export 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.MenuItem64
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