BetterDiscordApp-rauenzi/src/modules/bdv2.js

104 lines
5.4 KiB
JavaScript
Raw Normal View History

2019-05-30 17:44:05 +02:00
import WebpackModules from "./webpackmodules";
2019-05-28 23:27:25 +02:00
import BdApi from "./pluginapi";
2019-05-30 07:06:17 +02:00
import BDLogo from "../ui/icons/bdlogo";
2019-05-28 23:27:25 +02:00
export default new class V2 {
2019-05-28 20:19:48 +02:00
constructor() {
this.editorDetached = false;
}
initialize() {
2019-05-30 07:06:17 +02:00
BdApi.suppressErrors(this.patchSocial.bind(this), "BD Social Patch")();
2019-05-28 20:19:48 +02:00
BdApi.suppressErrors(this.patchGuildPills.bind(this), "BD Guild Pills Patch")();
BdApi.suppressErrors(this.patchGuildListItems.bind(this), "BD Guild List Items Patch")();
BdApi.suppressErrors(this.patchGuildSeparator.bind(this), "BD Guild Separator Patch")();
}
2019-05-30 07:06:17 +02:00
get messageClasses() {return WebpackModules.getByProps("message", "containerCozy");}
2019-05-28 20:19:48 +02:00
get guildClasses() {
2019-05-30 07:06:17 +02:00
const guildsWrapper = WebpackModules.getByProps("wrapper", "unreadMentionsBar");
const guilds = WebpackModules.getByProps("guildsError", "selected");
const pill = WebpackModules.getByProps("blobContainer");
2019-05-28 20:19:48 +02:00
return Object.assign({}, guildsWrapper, guilds, pill);
}
2019-05-30 07:06:17 +02:00
get MessageContentComponent() {return WebpackModules.getModule(m => m.defaultProps && m.defaultProps.hasOwnProperty("disableButtons"));}
get TimeFormatter() {return WebpackModules.getByProps("dateFormat");}
get TooltipWrapper() {return WebpackModules.getByDisplayName("TooltipDeprecated");}
get NativeModule() {return WebpackModules.getByProps("setBadge");}
get Tooltips() {return WebpackModules.getModule(m => m.hide && m.show && !m.search && !m.submit && !m.search && !m.activateRagingDemon && !m.dismiss);}
get KeyGenerator() {return WebpackModules.getModule(m => m.toString && /"binary"/.test(m.toString()));}
2019-05-28 20:19:48 +02:00
2019-05-30 07:06:17 +02:00
patchSocial() {
if (this.socialPatch) return;
const TabBar = BdApi.findModule(m => m.displayName == "TabBar");
const Anchor = BdApi.findModule(m => m.displayName == "Anchor");
if (!TabBar || !Anchor) return;
this.socialPatch = BdApi.monkeyPatch(TabBar.prototype, "render", {after: (data) => {
const children = data.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(BdApi.React.createElement(Anchor, {className: "bd-social-link", href: "https://github.com/rauenzi/BetterDiscordApp", rel: "author", title: "BandagedBD", target: "_blank"},
BdApi.React.createElement(BDLogo, {size: "16px", className: "bd-social-logo"})
));
return returnVal;
};
children[children.length - 1].type = newOne;
}});
2019-05-28 20:19:48 +02:00
}
patchGuildListItems() {
if (this.guildListItemsPatch) return;
const listItemClass = this.guildClasses.listItem.split(" ")[0];
const blobClass = this.guildClasses.blobContainer.split(" ")[0];
const reactInstance = BdApi.getInternalInstance(document.querySelector(`.${listItemClass} .${blobClass}`).parentElement);
const GuildComponent = reactInstance.return.type;
if (!GuildComponent) return;
this.guildListItemsPatch = BdApi.monkeyPatch(GuildComponent.prototype, "render", {after: (data) => {
const returnValue = data.returnValue;
const guildData = data.thisObject.props;
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;
}});
}
patchGuildPills() {
if (this.guildPillPatch) return;
const guildPill = BdApi.findModule(m => m.default && m.default.toString && m.default.toString().includes("translate3d"));
if (!guildPill) return;
this.guildPillPatch = BdApi.monkeyPatch(guildPill, "default", {after: (data) => {
const props = data.methodArguments[0];
if (props.unread) data.returnValue.props.className += " bd-unread";
if (props.selected) data.returnValue.props.className += " bd-selected";
if (props.hovered) data.returnValue.props.className += " bd-hovered";
return data.returnValue;
}});
}
patchGuildSeparator() {
if (this.guildSeparatorPatch) return;
const Guilds = BdApi.findModuleByDisplayName("Guilds");
const guildComponents = BdApi.findModuleByProps("renderListItem");
if (!guildComponents || !Guilds) return;
const GuildSeparator = function() {
const returnValue = guildComponents.Separator(...arguments);
returnValue.props.className += " bd-guild-separator";
return returnValue;
};
this.guildSeparatorPatch = BdApi.monkeyPatch(Guilds.prototype, "render", {after: (data) => {
data.returnValue.props.children[1].props.children[3].type = GuildSeparator;
}});
}
2019-05-28 23:27:25 +02:00
};