diff --git a/src/plugins/copyStatusUrls/index.ts b/src/plugins/copyStatusUrls/index.ts new file mode 100644 index 000000000..8ba99abde --- /dev/null +++ b/src/plugins/copyStatusUrls/index.ts @@ -0,0 +1,66 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { Devs } from "@utils/constants"; +import definePlugin from "@utils/types"; +import { findByCodeLazy } from "@webpack"; +import { Clipboard, Toasts } from "@webpack/common"; +import { User } from "discord-types/general"; + +interface MakeContextMenuProps { + user: User, + activity: any +} + +// This is an API call if the result is not cached +// i looked for an hour and did not find a better way to do this +const getMetadataFromApi: (activity: any, userId: string) => Promise = findByCodeLazy("null/undefined"); + +export default definePlugin({ + name: "CopyStatusUrls", + description: "Copy the users status url when you right-click it", + authors: [Devs.sadan], + patches: [ + { + find: "?\"PRESS_WATCH_ON_CRUNCHYROLL_BUTTON\"", + replacement: { + match: /(?=onClick)(?=.*index:(\i))/, + replace: "onContextMenu: $self.makeContextMenu(arguments[0], $1)," + } + } + ], + + makeContextMenu(props: MakeContextMenuProps, index: number) { + return async () => { + try { + const { button_urls } = await getMetadataFromApi(props.activity, props.user.id); + if (!button_urls[index]) { + throw new Error("button_urls does not contain index"); + } + Clipboard.copy(button_urls[index]); + Toasts.show({ + id: Toasts.genId(), + message: "Copied URL", + type: Toasts.Type.SUCCESS, + options: { + position: Toasts.Position.TOP + } + }); + } catch (e) { + console.error(e); + Toasts.show({ + id: Toasts.genId(), + message: "Error copying URL, check console for more info", + type: Toasts.Type.FAILURE, + options: { + position: Toasts.Position.TOP + } + }); + } + }; + } +}); +