create plugin

This commit is contained in:
sadan 2024-09-18 23:07:44 -04:00
parent c7e5295da0
commit e392958736
No known key found for this signature in database

View file

@ -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<any> = 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
}
});
}
};
}
});