Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CopyEmojiMarkdown: Fix copying animated emojis #3179

Merged
merged 9 commits into from
Feb 4, 2025
9 changes: 6 additions & 3 deletions src/plugins/copyEmojiMarkdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ function getEmojiMarkdown(target: Target, copyUnicode: boolean): string {
: `:${emojiName}:`;
}

const extension = target?.firstChild.src.match(
const imgSrc = target?.firstChild.src;
const url = new URL(imgSrc);
Tomsoz marked this conversation as resolved.
Show resolved Hide resolved
const isAnimated = url.searchParams.get("animated") === "true";
const extension = imgSrc.match(
/https:\/\/cdn\.discordapp\.com\/emojis\/\d+\.(\w+)/
)?.[1];

return `<${extension === "gif" ? "a" : ""}:${emojiName.replace(/~\d+$/, "")}:${emojiId}>`;
return `<${(isAnimated || extension === "gif") ? "a" : ""}:${emojiName.replace(/~\d+$/, "")}:${emojiId}>`;
}

const settings = definePluginSettings({
Expand All @@ -55,7 +58,7 @@ export default definePlugin({
settings,

contextMenus: {
"expression-picker"(children, { target }: { target: Target }) {
"expression-picker"(children, { target }: { target: Target; }) {
if (target.dataset.type !== "emoji") return;

children.push(
Expand Down