BetterDiscordApp-rauenzi/renderer/src/builtins/emotes/emotemenu.js

77 lines
3.3 KiB
JavaScript
Raw Normal View History

2020-07-16 07:42:56 +02:00
import Builtin from "../../structs/builtin";
2020-07-24 10:59:16 +02:00
import {Utilities, WebpackModules, React} from "modules";
import EmoteModule from "./emotes";
import EmoteMenuCard from "../../ui/emotemenucard";
import EmoteIcon from "../../ui/emoteicon";
import Category from "./category";
import Favorite from "../../ui/icons/favorite";
import Twitch from "../../ui/icons/twitch";
2020-07-24 10:59:16 +02:00
const EmojiPicker = WebpackModules.find(m => m.type && m.type.displayName == "ExpressionPicker");
2019-05-31 07:53:11 +02:00
export default new class EmoteMenu extends Builtin {
get name() {return "EmoteMenu";}
2019-06-06 06:28:43 +02:00
get collection() {return "emotes";}
get category() {return "general";}
get id() {return "emoteMenu";}
get hideEmojisID() {return "hideEmojiMenu";}
2019-06-06 21:57:25 +02:00
get hideEmojis() {return this.get(this.hideEmojisID);}
2019-05-31 07:53:11 +02:00
getSelected(body) {
if (body[1]) return {id: "stickers", index: 1};
else if (body[2]) return {id: "gif", index: 2};
else if (body[3]) return {id: "emoji", index: 3};
return {id: "bd-emotes", index: 3};
}
2020-07-24 10:59:16 +02:00
enabled() {
this.after(EmojiPicker, "type", (_, __, returnValue) => {
2020-10-08 21:12:57 +02:00
const head = Utilities.getNestedProp(returnValue, "props.children.props.children.props.children.1.props.children.0.props.children.props.children");
const body = Utilities.getNestedProp(returnValue, "props.children.props.children.props.children.1.props.children");
if (!head || !body) return returnValue;
let activePicker = this.getSelected(body);
let isActive = activePicker.id == "bd-emotes";
const tabProps = head[0].props;
if (!isActive && activePicker.id == "emoji" && this.hideEmojis) {
activePicker = {id: "bd-emotes", index: 3};
isActive = true;
}
if (this.hideEmojis) head.splice(head.findIndex(e => e && e.props && e.props.id == "emoji-picker-tab"), 1);
head.push(
React.createElement("div", {
"id": "bd-emotes-tab",
"role": "tab",
"aria-selected": isActive,
"className": tabProps.className,
2020-07-24 10:59:16 +02:00
}, React.createElement(tabProps.children.type, {
viewType: "bd-emotes",
isActive: isActive,
}, "Twitch")
2020-07-24 10:59:16 +02:00
));
if (isActive) {
body[activePicker.index] = React.createElement(EmoteMenuCard, {
type: "twitch",
}, [
React.createElement(Category, {
label: "Favorites",
icon: React.createElement(Favorite, {}),
}, Object.entries(EmoteModule.favorites).map(([emote, url]) => {
return React.createElement(EmoteIcon, {emote, url});
})),
React.createElement(Category, {
label: "Twitch Emotes",
icon: React.createElement(Twitch, {})
}, Object.keys(EmoteModule.getCategory("TwitchGlobal")).map(emote=> {
const url = EmoteModule.getUrl("TwitchGlobal", emote);
return React.createElement(EmoteIcon, {emote, url});
}))
]);
}
});
}
2019-05-31 07:53:11 +02:00
disabled() {
2020-07-24 10:59:16 +02:00
this.unpatchAll();
2019-05-31 07:53:11 +02:00
}
};