Plugin
CopyStickerLinks
Adds the ability to copy & open Sticker links
1
import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu";2
import { isPluginEnabled } from "@api/PluginManager";3
import ExpressionClonerPlugin from "@plugins/expressionCloner";4
import { Devs } from "@utils/constants";5
import { copyWithToast } from "@utils/discord";6
import definePlugin from "@utils/types";7
import { Message, Sticker } from "@vencord/discord-types";8
import { Menu, React, StickersStore } from "@webpack/common";9
10
const StickerExt = [, "png", "png", "json", "gif"] as const;11
12
type PartialSticker = Pick<Sticker, "id" | "format_type">;13
14
function getUrl(data: PartialSticker): string {15
if (data.format_type === 4)16
return `https:${window.GLOBAL_ENV.MEDIA_PROXY_ENDPOINT}/stickers/${data.id}.gif?size=512&lossless=true`;17
18
return `https:class="ts-cmt">//${window.GLOBAL_ENV.CDN_HOST}/stickers/${data.id}.${StickerExt[data.format_type]}?size=512&lossless=true`;19
}20
21
function buildMenuItem(sticker: PartialSticker, addBottomSeparator: boolean) {22
return (23
<>24
<Menu.MenuGroup>25
<Menu.MenuItem26
id="vc-copy-sticker-link"27
key="vc-copy-sticker-link"28
label="Copy Link"29
action={() => copyWithToast(getUrl(sticker), "Link copied!")}30
/>31
32
<Menu.MenuItem33
id="vc-open-sticker-link"34
key="vc-open-sticker-link"35
label="Open Link"36
action={() => VencordNative.native.openExternal(getUrl(sticker))}37
/>38
</Menu.MenuGroup>39
{addBottomSeparator && <Menu.MenuSeparator />}40
</>41
);42
}43
44
const messageContextMenuPatch: NavContextMenuPatchCallback = (45
children,46
{ favoriteableId, favoriteableType, message }: { favoriteableId: string; favoriteableType: string; message: Message; }47
) => {48
if (!favoriteableId || favoriteableType !== "sticker") return;49
50
const sticker = message.stickerItems.find(s => s.id === favoriteableId);51
if (!sticker?.format_type) return;52
53
const idx = children.findIndex(c => Array.isArray(c) && findGroupChildrenByChildId("vc-copy-sticker-url", c) != null);54
55
children.splice(idx, 0, buildMenuItem(sticker, idx !== -1));56
};57
58
const expressionPickerPatch: NavContextMenuPatchCallback = (children, props: { target: HTMLElement; }) => {59
const id = props?.target?.dataset?.id;60
if (!id) return;61
if (props.target.className?.includes("lottieCanvas")) return;62
63
const sticker = StickersStore.getStickerById(id);64
if (sticker) {65
children.push(buildMenuItem(sticker, isPluginEnabled(ExpressionClonerPlugin.name)));66
}67
};68
69
export default definePlugin({70
name: "CopyStickerLinks",71
description: "Adds the ability to copy & open Sticker links",72
tags: ["Emotes", "Utility"],73
authors: [Devs.Ven, Devs.Byeoon],74
contextMenus: {75
"message": messageContextMenuPatch,76
"expression-picker": expressionPickerPatch77
}78
});79