2020-04-23 22:01:48 +02:00
|
|
|
import {Config} from "data";
|
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() {
|
2020-04-23 22:01:48 +02:00
|
|
|
if (this.socialPatch) return;
|
|
|
|
// const TabBar = WebpackModules.getByDisplayName("TabBar");
|
|
|
|
// const Anchor = WebpackModules.getByDisplayName("Anchor");
|
|
|
|
// if (!TabBar || !Anchor) return;
|
|
|
|
// this.socialPatch = Patcher.after("ThemeHelper", TabBar.prototype, "render", (_, __, returnValue) => {
|
|
|
|
// const children = returnValue.props.children;
|
|
|
|
// 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);
|
|
|
|
// 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"})
|
|
|
|
// ));
|
|
|
|
// return returnVal;
|
|
|
|
// };
|
|
|
|
// children[children.length - 1].type = newOne;
|
|
|
|
// });
|
|
|
|
|
2019-05-30 07:06:17 +02:00
|
|
|
if (this.socialPatch) return;
|
2019-06-23 06:11:50 +02:00
|
|
|
const TabBar = WebpackModules.getByDisplayName("TabBar");
|
|
|
|
const Anchor = WebpackModules.getByDisplayName("Anchor");
|
2020-04-23 22:01:48 +02:00
|
|
|
if (!TabBar) return;
|
|
|
|
this.socialPatch = Patcher.after("ComponentPatcher", TabBar.prototype, "render", (thisObject, args, returnValue) => {
|
2019-06-23 06:11:50 +02:00
|
|
|
const children = returnValue.props.children;
|
2020-04-23 22:01:48 +02:00
|
|
|
if (!children || !children.length || children.length < 3) return;
|
|
|
|
if (children[children.length - 3].type.displayName !== "Separator") return;
|
|
|
|
if (!children[children.length - 2].type.toString().includes("socialLinks")) return;
|
|
|
|
if (Anchor) {
|
|
|
|
const original = children[children.length - 2].type;
|
|
|
|
const newOne = function() {
|
|
|
|
const returnVal = original(...arguments);
|
|
|
|
returnVal.props.children.push(
|
|
|
|
// DiscordModules.React.createElement(TooltipWrap, {color: "black", side: "top", text: "BandagedBD"},
|
|
|
|
DiscordModules.React.createElement(Anchor, {className: "bd-social-link", href: "https://github.com/rauenzi/BetterDiscordApp", title: "BandagedBD", target: "_blank"},
|
|
|
|
DiscordModules.React.createElement(BDLogo, {size: "16px", className: "bd-social-logo"})
|
|
|
|
)
|
|
|
|
// )
|
|
|
|
);
|
|
|
|
return returnVal;
|
|
|
|
};
|
|
|
|
children[children.length - 2].type = newOne;
|
|
|
|
}
|
|
|
|
|
|
|
|
const injector = DiscordModules.React.createElement("div", {className: "colorMuted-HdFt4q size12-3cLvbJ"}, `Injector ${Config.version}`);
|
|
|
|
const versionHash = `(${Config.hash ? Config.hash.substring(0, 7) : Config.branch})`;
|
|
|
|
const additional = DiscordModules.React.createElement("div", {className: "colorMuted-HdFt4q size12-3cLvbJ"}, `BBD ${Config.bbdVersion} `, DiscordModules.React.createElement("span", {className: "versionHash-2gXjIB da-versionHash"}, versionHash));
|
|
|
|
|
|
|
|
|
|
|
|
const originalVersions = children[children.length - 1].type;
|
|
|
|
children[children.length - 1].type = function() {
|
|
|
|
const returnVal = originalVersions(...arguments);
|
|
|
|
returnVal.props.children.splice(returnVal.props.children.length - 1, 0, injector);
|
|
|
|
returnVal.props.children.splice(1, 0, additional);
|
2019-05-30 07:06:17 +02:00
|
|
|
return returnVal;
|
|
|
|
};
|
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) => {
|
2020-02-28 01:00:12 +01:00
|
|
|
if (!returnValue || !thisObject) return;
|
2019-06-23 06:11:50 +02:00
|
|
|
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
|
|
|
};
|