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>main
parent
0aa7bef9fa
commit
e5e8b9ba01
@ -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)
|
@ -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."
|
||||
);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
},
|
||||
},
|
||||
});
|
Loading…
Reference in new issue