add toggle

This commit is contained in:
Han Seung Min - 한승민 2024-05-11 06:12:23 +09:00
parent 0a39788aff
commit 5d008b0708
No known key found for this signature in database
GPG key ID: 9F3C237B3396AC97

View file

@ -5,7 +5,12 @@
*/
import { Devs } from "@utils/constants";
import { isNonNullish } from "@utils/guards";
import definePlugin from "@utils/types";
import { useState } from "@webpack/common";
import { Embed } from "discord-types/general";
interface ToggleableDescriptionProps { embed: Embed, original: () => any; }
export default definePlugin({
name: "YoutubeDescription",
@ -15,9 +20,30 @@ export default definePlugin({
{
find: ".default.Messages.SUPPRESS_ALL_EMBEDS",
replacement: {
match: /case \i\.MessageEmbedTypes\.VIDEO:(case \i\.MessageEmbedTypes\.\i:)*break;default:(\i=this\.renderDescription\(\))\}/,
replace: "$1 break; default: $2 }"
match: /case (\i\.MessageEmbedTypes\.VIDEO):(case \i\.MessageEmbedTypes\.\i:)*break;default:(\i)=(?:(this\.renderDescription)\(\))\}/,
replace: "$2 break; case $1: $3 = $self.ToggleableDescriptionWrapper({ embed: this.props.embed, original: $4.bind(this) }); break; default: $3 = $4() }"
}
}
]
],
ToggleableDescription({ embed, original }: ToggleableDescriptionProps) {
const [isOpen, setOpen] = useState(false);
console.warn(embed);
return !isNonNullish(embed.rawDescription)
? null
: embed.rawDescription.length > 20
? <div
style={{ cursor: "pointer", marginTop: isOpen ? "0px" : "8px" }}
onClick={() => setOpen(o => !o)}
>
{isOpen
? original()
: embed.rawDescription.substring(0, 20) + "..."}
</div>
: original();
},
ToggleableDescriptionWrapper(props: ToggleableDescriptionProps) {
return <this.ToggleableDescription {...props}></this.ToggleableDescription>;
}
});