new plugin CopyEmojiMarkdown ~ more easily copy emoji formatting (#2266)

Co-authored-by: Happy enderman <66224387+happyendermangit@users.noreply.github.com>
Co-authored-by: vee <vendicated@riseup.net>
This commit is contained in:
vishnyanetchereshnya 2024-06-06 02:40:02 +03:00 committed by GitHub
parent 0aa7bef9fa
commit e5e8b9ba01
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 88 additions and 0 deletions

View file

@ -0,0 +1,5 @@
# CopyEmojiMarkdown
Allows you to copy emojis as formatted string. Custom emojis will be copied as `<:trolley:1024751352028602449>`, default emojis as `🛒`
![](https://github.com/Vendicated/Vencord/assets/45497981/417f345a-7031-4fe7-8e42-e238870cd547)

View file

@ -0,0 +1,75 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants";
import { copyWithToast } from "@utils/misc";
import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy } from "@webpack";
import { Menu } from "@webpack/common";
const { convertNameToSurrogate } = findByPropsLazy("convertNameToSurrogate");
interface Emoji {
type: string;
id: string;
name: string;
}
interface Target {
dataset: Emoji;
firstChild: HTMLImageElement;
}
function getEmojiMarkdown(target: Target, copyUnicode: boolean): string {
const { id: emojiId, name: emojiName } = target.dataset;
if (!emojiId) {
return copyUnicode
? convertNameToSurrogate(emojiName)
: `:${emojiName}:`;
}
const extension = target?.firstChild.src.match(
/https:\/\/cdn\.discordapp\.com\/emojis\/\d+\.(\w+)/
)?.[1];
return `<${extension === "gif" ? "a" : ""}:${emojiName.replace(/~\d+$/, "")}:${emojiId}>`;
}
const settings = definePluginSettings({
copyUnicode: {
type: OptionType.BOOLEAN,
description: "Copy the raw unicode character instead of :name: for default emojis (👽)",
default: true,
},
});
export default definePlugin({
name: "CopyEmojiMarkdown",
description: "Allows you to copy emojis as formatted string (<:blobcatcozy:1026533070955872337>)",
authors: [Devs.HappyEnderman, Devs.Vishnya],
settings,
contextMenus: {
"expression-picker"(children, { target }: { target: Target }) {
if (target.dataset.type !== "emoji") return;
children.push(
<Menu.MenuItem
id="vc-copy-emoji-markdown"
label="Copy Emoji Markdown"
action={() => {
copyWithToast(
getEmojiMarkdown(target, settings.store.copyUnicode),
"Success! Copied emoji markdown."
);
}}
/>
);
},
},
});

View file

@ -442,6 +442,14 @@ export const Devs = /* #__PURE__*/ Object.freeze({
name: "Elvyra", name: "Elvyra",
id: 708275751816003615n, id: 708275751816003615n,
}, },
HappyEnderman: {
name: "Happy enderman",
id: 1083437693347827764n
},
Vishnya: {
name: "Vishnya",
id: 282541644484575233n
},
Inbestigator: { Inbestigator: {
name: "Inbestigator", name: "Inbestigator",
id: 761777382041714690n id: 761777382041714690n