2019-05-30 17:44:05 +02:00
|
|
|
import WebpackModules from "./webpackmodules";
|
2019-06-23 06:11:50 +02:00
|
|
|
import DiscordModules from "./discordmodules";
|
|
|
|
import Utilities from "./utilities";
|
|
|
|
import Patcher from "./patcher";
|
2019-05-30 07:06:17 +02:00
|
|
|
import BDLogo from "../ui/icons/bdlogo";
|
2019-05-28 23:27:25 +02:00
|
|
|
|
2019-06-24 21:47:24 +02:00
|
|
|
export default new class ComponentPatcher {
|
2019-05-28 20:19:48 +02:00
|
|
|
|
|
|
|
initialize() {
|
2019-06-23 06:11:50 +02:00
|
|
|
Utilities.suppressErrors(this.patchSocial.bind(this), "BD Social Patch")();
|
|
|
|
Utilities.suppressErrors(this.patchGuildPills.bind(this), "BD Guild Pills Patch")();
|
|
|
|
Utilities.suppressErrors(this.patchGuildListItems.bind(this), "BD Guild List Items Patch")();
|
|
|
|
Utilities.suppressErrors(this.patchGuildSeparator.bind(this), "BD Guild Separator Patch")();
|
2019-05-28 20:19:48 +02:00
|
|
|
}
|
|
|
|
|
2019-05-30 07:06:17 +02:00
|
|
|
patchSocial() {
|
|
|
|
if (this.socialPatch) return;
|
2019-06-23 06:11:50 +02:00
|
|
|
const TabBar = WebpackModules.getByDisplayName("TabBar");
|
|
|
|
const Anchor = WebpackModules.getByDisplayName("Anchor");
|
2019-05-30 07:06:17 +02:00
|
|
|
if (!TabBar || !Anchor) return;
|
2019-06-23 06:11:50 +02:00
|
|
|
this.socialPatch = Patcher.after("ThemeHelper", TabBar.prototype, "render", (_, __, returnValue) => {
|
|
|
|
const children = returnValue.props.children;
|
2019-05-30 07:06:17 +02:00
|
|
|
if (!children || !children.length) return;
|
|
|
|
if (children[children.length - 2].type.displayName !== "Separator") return;
|
|
|
|
if (!children[children.length - 1].type.toString().includes("socialLinks")) return;
|
|
|
|
const original = children[children.length - 1].type;
|
|
|
|
const newOne = function() {
|
|
|
|
const returnVal = original(...arguments);
|
2019-06-23 06:11:50 +02:00
|
|
|
returnVal.props.children.push(DiscordModules.React.createElement(Anchor, {className: "bd-social-link", href: "https://github.com/rauenzi/BetterDiscordApp", rel: "author", title: "BandagedBD", target: "_blank"},
|
|
|
|
DiscordModules.React.createElement(BDLogo, {size: "16px", className: "bd-social-logo"})
|
2019-05-30 07:06:17 +02:00
|
|
|
));
|
|
|
|
return returnVal;
|
|
|
|
};
|
|
|
|
children[children.length - 1].type = newOne;
|
2019-06-23 06:11:50 +02:00
|
|
|
});
|
2019-05-28 20:19:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
patchGuildListItems() {
|
|
|
|
if (this.guildListItemsPatch) return;
|
2019-06-23 06:11:50 +02:00
|
|
|
const listItemClass = DiscordModules.GuildClasses.listItem.split(" ")[0];
|
|
|
|
const blobClass = DiscordModules.GuildClasses.blobContainer.split(" ")[0];
|
|
|
|
const reactInstance = Utilities.getReactInstance(document.querySelector(`.${listItemClass} .${blobClass}`).parentElement);
|
2019-05-28 20:19:48 +02:00
|
|
|
const GuildComponent = reactInstance.return.type;
|
|
|
|
if (!GuildComponent) return;
|
2019-06-23 06:11:50 +02:00
|
|
|
this.guildListItemsPatch = Patcher.after("ThemeHelper", GuildComponent.prototype, "render", (thisObject, _, returnValue) => {
|
|
|
|
const guildData = thisObject.props;
|
2019-05-28 20:19:48 +02:00
|
|
|
returnValue.props.className += " bd-guild";
|
|
|
|
if (guildData.unread) returnValue.props.className += " bd-unread";
|
|
|
|
if (guildData.selected) returnValue.props.className += " bd-selected";
|
|
|
|
if (guildData.audio) returnValue.props.className += " bd-audio";
|
|
|
|
if (guildData.video) returnValue.props.className += " bd-video";
|
|
|
|
if (guildData.badge) returnValue.props.className += " bd-badge";
|
|
|
|
if (guildData.animatable) returnValue.props.className += " bd-animatable";
|
|
|
|
return returnValue;
|
2019-06-23 06:11:50 +02:00
|
|
|
});
|
2019-05-28 20:19:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
patchGuildPills() {
|
|
|
|
if (this.guildPillPatch) return;
|
2019-06-23 06:11:50 +02:00
|
|
|
const guildPill = WebpackModules.getModule(m => m.default && !m.default.displayName && m.default.toString && m.default.toString().includes("translate3d"));
|
2019-05-28 20:19:48 +02:00
|
|
|
if (!guildPill) return;
|
2019-06-23 06:11:50 +02:00
|
|
|
this.guildPillPatch = Patcher.after("ThemeHelper", guildPill, "default", (_, args, returnValue) => {
|
|
|
|
const props = args[0];
|
|
|
|
if (props.unread) returnValue.props.className += " bd-unread";
|
|
|
|
if (props.selected) returnValue.props.className += " bd-selected";
|
|
|
|
if (props.hovered) returnValue.props.className += " bd-hovered";
|
|
|
|
return returnValue;
|
|
|
|
});
|
2019-05-28 20:19:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
patchGuildSeparator() {
|
|
|
|
if (this.guildSeparatorPatch) return;
|
2019-06-23 06:11:50 +02:00
|
|
|
const Guilds = WebpackModules.getByDisplayName("Guilds");
|
|
|
|
const guildComponents = WebpackModules.getByProps("renderListItem");
|
2019-05-28 20:19:48 +02:00
|
|
|
if (!guildComponents || !Guilds) return;
|
|
|
|
const GuildSeparator = function() {
|
|
|
|
const returnValue = guildComponents.Separator(...arguments);
|
|
|
|
returnValue.props.className += " bd-guild-separator";
|
|
|
|
return returnValue;
|
|
|
|
};
|
2019-06-23 06:11:50 +02:00
|
|
|
this.guildSeparatorPatch = Patcher.after("ThemeHelper", Guilds.prototype, "render", (_, __, returnValue) => {
|
|
|
|
const Separator = Utilities.findInReactTree(returnValue, m => m.type && !m.type.displayName && typeof(m.type) == "function" && Utilities.isEmpty(m.props));
|
|
|
|
if (!Separator) return;
|
|
|
|
Separator.type = GuildSeparator;
|
|
|
|
});
|
2019-05-28 20:19:48 +02:00
|
|
|
}
|
|
|
|
|
2019-05-28 23:27:25 +02:00
|
|
|
};
|