add copyStatusURLs (#326)
This commit is contained in:
parent
5b85a3fc7a
commit
4d6c52a9a0
1 changed files with 67 additions and 0 deletions
67
src/equicordplugins/copyStatusUrls/index.ts
Normal file
67
src/equicordplugins/copyStatusUrls/index.ts
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Vencord, a Discord client mod
|
||||
* Copyright (c) 2025 Vendicated and contributors
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { copyToClipboard } from "@utils/clipboard";
|
||||
import { Devs } from "@utils/constants";
|
||||
import definePlugin from "@utils/types";
|
||||
import { User } from "@vencord/discord-types";
|
||||
import { findByCodeLazy } from "@webpack";
|
||||
import { Toasts } from "@webpack/common";
|
||||
|
||||
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");
|
||||
}
|
||||
copyToClipboard(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
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue