mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-01-09 17:36:23 +00:00
create plugin
This commit is contained in:
parent
c7e5295da0
commit
e392958736
1 changed files with 66 additions and 0 deletions
66
src/plugins/copyStatusUrls/index.ts
Normal file
66
src/plugins/copyStatusUrls/index.ts
Normal 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
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue