Equicord/src/equicordplugins/youtubeDescription/index.tsx

51 lines
1.8 KiB
TypeScript
Raw Normal View History

2024-05-09 14:22:27 -04:00
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
2024-06-01 14:32:22 -04:00
import ErrorBoundary from "@components/ErrorBoundary";
2024-05-09 14:22:27 -04:00
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
2024-06-01 14:32:22 -04:00
import { useState } from "@webpack/common";
import { Embed } from "discord-types/general";
interface ToggleableDescriptionProps { embed: Embed, original: () => any; }
2024-05-09 14:22:27 -04:00
export default definePlugin({
name: "YoutubeDescription",
description: "Adds descriptions to youtube video embeds",
authors: [Devs.arHSM],
patches: [
{
2024-06-13 22:00:54 -04:00
find: ".Messages.SUPPRESS_ALL_EMBEDS",
2024-05-09 14:22:27 -04:00
replacement: {
2024-06-21 20:05:37 -04:00
match: /case (\i\.\i\.VIDEO):(case \i\.\i\.\i:)*break;default:(\i)=(?:(this\.renderDescription)\(\))\}/,
2024-06-01 14:32:22 -04:00
replace: "$2 break; case $1: $3 = $self.ToggleableDescriptionWrapper({ embed: this.props.embed, original: $4.bind(this) }); break; default: $3 = $4() }"
2024-05-09 14:22:27 -04:00
}
}
2024-06-01 14:32:22 -04:00
],
ToggleableDescription: ErrorBoundary.wrap(({ embed, original }: ToggleableDescriptionProps) => {
const [isOpen, setOpen] = useState(false);
if (!embed.rawDescription)
return null;
if (embed.rawDescription.length <= 20)
return original();
return (
<div
style={{ cursor: "pointer", marginTop: isOpen ? "0px" : "8px" }}
onClick={() => setOpen(o => !o)}
>
{isOpen
? original()
: embed.rawDescription.substring(0, 20) + "..."}
</div>
);
}),
ToggleableDescriptionWrapper(props: ToggleableDescriptionProps) {
return <this.ToggleableDescription {...props} ></this.ToggleableDescription >;
}
2024-05-09 14:22:27 -04:00
});