mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-01-09 17:36:23 +00:00
add toggle
This commit is contained in:
parent
0a39788aff
commit
5d008b0708
1 changed files with 29 additions and 3 deletions
|
@ -5,7 +5,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
|
import { isNonNullish } from "@utils/guards";
|
||||||
import definePlugin from "@utils/types";
|
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({
|
export default definePlugin({
|
||||||
name: "YoutubeDescription",
|
name: "YoutubeDescription",
|
||||||
|
@ -15,9 +20,30 @@ export default definePlugin({
|
||||||
{
|
{
|
||||||
find: ".default.Messages.SUPPRESS_ALL_EMBEDS",
|
find: ".default.Messages.SUPPRESS_ALL_EMBEDS",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /case \i\.MessageEmbedTypes\.VIDEO:(case \i\.MessageEmbedTypes\.\i:)*break;default:(\i=this\.renderDescription\(\))\}/,
|
match: /case (\i\.MessageEmbedTypes\.VIDEO):(case \i\.MessageEmbedTypes\.\i:)*break;default:(\i)=(?:(this\.renderDescription)\(\))\}/,
|
||||||
replace: "$1 break; default: $2 }"
|
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>;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue