BetterDiscordApp-rauenzi/src/modules/publicServers.js

77 lines
2.6 KiB
JavaScript
Raw Normal View History

2020-03-25 05:19:02 +01:00
import {settingsCookie} from "../0globals";
2020-02-27 08:01:51 +01:00
import BDV2 from "./v2";
import webpackModules from "./webpackModules";
2020-02-27 22:26:23 +01:00
import Utils from "./utils";
2020-03-29 11:17:12 +02:00
import DOM from "./domtools";
2020-02-27 08:01:51 +01:00
2020-03-29 11:17:12 +02:00
import V2C_PublicServers from "../ui/publicservers/publicServers";
import Layer from "../ui/publicservers/layer";
2020-02-27 08:01:51 +01:00
export default new class V2_PublicServers {
constructor() {
this._appendButton = this._appendButton.bind(this);
}
get component() {
2020-03-29 11:17:12 +02:00
return BDV2.react.createElement(Layer, {rootId: "pubslayerroot", id: "pubslayer"}, BDV2.react.createElement(V2C_PublicServers, {rootId: "pubslayerroot"}));
2020-02-27 08:01:51 +01:00
}
get root() {
const _root = document.getElementById("pubslayerroot");
if (!_root) {
if (!this.injectRoot()) return null;
return this.root;
}
return _root;
}
injectRoot() {
2020-03-29 11:17:12 +02:00
const layers = DOM.query(".layers, .layers-3iHuyZ");
if (!layers) return false;
layers.append(DOM.createElement("<div id='pubslayerroot'>"));
2020-02-27 08:01:51 +01:00
return true;
}
render() {
const root = this.root;
if (!root) {
console.log("FAILED TO LOCATE ROOT: .layers");
return;
}
BDV2.reactDom.render(this.component, root);
}
get button() {
2020-03-29 11:17:12 +02:00
const btn = DOM.createElement(`<div id="bd-pub-li" class="${BDV2.guildClasses.listItem}">`);
if (!settingsCookie["bda-gs-1"]) btn.style.display = "none";
const label = DOM.createElement(`<div id="bd-pub-button" class="${"wrapper-25eVIn " + BDV2.guildClasses.circleButtonMask}">public</div>`);
label.addEventListener("click", () => {this.render();});
btn.append(label);
2020-02-27 08:01:51 +01:00
return btn;
}
_appendButton() {
2021-02-02 15:28:13 +01:00
/*if (DOM.query("#bd-pub-li")) return;
2020-02-27 08:01:51 +01:00
const wrapper = BDV2.guildClasses.wrapper.split(" ")[0];
2020-07-17 15:08:55 +02:00
const guilds = DOM.query(`.${wrapper} .scroller-2TZvBN >:first-child`);
2021-02-02 15:28:13 +01:00
if (guilds) DOM.after(guilds, this.button);*/
2020-02-27 08:01:51 +01:00
}
addButton() {
2021-02-02 15:28:13 +01:00
/*if (this.guildPatch) return;
2020-03-30 21:43:34 +02:00
const GuildList = webpackModules.find(m => m.default && m.default.displayName == "NavigableGuilds");
2020-03-31 01:12:35 +02:00
const GuildListOld = webpackModules.findByDisplayName("Guilds");
if (!GuildList && !GuildListOld) Utils.warn("PublicServer", "Can't find GuildList component");
this.guildPatch = Utils.monkeyPatch(GuildList ? GuildList : GuildListOld.prototype, GuildList ? "default" : "render", {after: this._appendButton});
2021-02-02 15:28:13 +01:00
this._appendButton();*/
2020-02-27 08:01:51 +01:00
}
removeButton() {
2021-02-02 15:28:13 +01:00
/*this.guildPatch();
2020-02-27 08:01:51 +01:00
delete this.guildPatch;
2020-07-17 15:08:55 +02:00
const button = DOM.query("#bd-pub-li");
2021-02-02 15:28:13 +01:00
if (button) button.remove();*/
2020-02-27 08:01:51 +01:00
}
2020-07-17 15:08:55 +02:00
};