Plugin
CopyEmojiMarkdown
Allows you to copy emojis as formatted string (<:blobcatcozy:1026533070955872337>)
1
import { definePluginSettings } from "@api/Settings";2
import { Devs } from "@utils/constants";3
import { copyWithToast } from "@utils/discord";4
import definePlugin, { OptionType } from "@utils/types";5
import { findByPropsLazy } from "@webpack";6
import { Menu } from "@webpack/common";7
8
const { convertNameToSurrogate } = findByPropsLazy("convertNameToSurrogate");9
10
interface Emoji {11
type: string;12
id: string;13
name: string;14
}15
16
interface Target {17
dataset: Emoji;18
firstChild: HTMLImageElement;19
}20
21
function getEmojiMarkdown(target: Target, copyUnicode: boolean): string {22
const { id: emojiId, name: emojiName } = target.dataset;23
24
if (!emojiId) {25
return copyUnicode26
? 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
37
const 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
45
export 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.MenuItem58
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