2020-03-25 05:19:02 +01:00
|
|
|
import {settings, settingsCookie, bdplugins, bdthemes} from "../0globals";
|
2020-02-27 08:01:51 +01:00
|
|
|
import DataStore from "./dataStore";
|
|
|
|
import V2_SettingsPanel_Sidebar from "./settingsPanelSidebar";
|
|
|
|
import Utils from "./utils";
|
|
|
|
import BDV2 from "./v2";
|
|
|
|
import ContentManager from "./contentManager";
|
|
|
|
import BDEvents from "./bdEvents";
|
|
|
|
import coloredText from "./coloredText";
|
2020-02-27 22:26:23 +01:00
|
|
|
import tfHour from "./24hour";
|
2020-03-28 03:44:59 +01:00
|
|
|
import reactDevTools from "./reactDevTools";
|
2020-03-29 11:17:12 +02:00
|
|
|
import DOM from "./domtools";
|
2020-02-27 08:01:51 +01:00
|
|
|
|
|
|
|
import publicServersModule from "./publicServers";
|
|
|
|
import voiceMode from "./voiceMode";
|
|
|
|
import emoteModule from "./emoteModule";
|
|
|
|
import ClassNormalizer from "./classNormalizer";
|
|
|
|
import dMode from "./devMode";
|
|
|
|
import quickEmoteMenu from "./quickEmoteMenu";
|
|
|
|
|
2020-03-25 05:19:02 +01:00
|
|
|
import Tools from "../ui/tools";
|
|
|
|
import Scroller from "../ui/scroller";
|
|
|
|
import SectionedSettingsPanel from "../ui/sectionedSettingsPanel";
|
|
|
|
import SettingsPanel from "../ui/settingsPanel";
|
|
|
|
import CssEditor from "../ui/cssEditor";
|
2020-03-25 23:45:48 +01:00
|
|
|
import CardList from "../ui/addonlist";
|
|
|
|
|
2020-02-27 08:01:51 +01:00
|
|
|
export default new class V2_SettingsPanel {
|
|
|
|
|
|
|
|
constructor() {
|
2020-03-29 11:17:12 +02:00
|
|
|
this.sideBarOnClick = this.sideBarOnClick.bind(this);
|
|
|
|
this.onChange = this.onChange.bind(this);
|
|
|
|
this.updateSettings = this.updateSettings.bind(this);
|
|
|
|
this.sidebar = new V2_SettingsPanel_Sidebar(this.sideBarOnClick);
|
2020-03-29 21:43:42 +02:00
|
|
|
// this.buildPluginProps = this.buildPluginProps.bind(this);
|
|
|
|
// this.buildThemeProps = this.buildThemeProps.bind(this);
|
2020-03-29 11:17:12 +02:00
|
|
|
this.showOriginal = this.showOriginal.bind(this);
|
2020-02-27 08:01:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
get root() {
|
2020-03-29 11:17:12 +02:00
|
|
|
const _root = DOM.query("#bd-settingspane-container");
|
|
|
|
if (!_root) {
|
2020-02-27 08:01:51 +01:00
|
|
|
if (!this.injectRoot()) return null;
|
|
|
|
return this.root;
|
|
|
|
}
|
2020-03-29 11:17:12 +02:00
|
|
|
return _root;
|
2020-02-27 08:01:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
injectRoot() {
|
2020-03-29 11:17:12 +02:00
|
|
|
const sidebar = DOM.query(".layer-3QrUeG .standardSidebarView-3F1I7i, .layer-3QrUeG .ui-standard-sidebar-view");
|
|
|
|
if (!sidebar) return false;
|
|
|
|
const root = DOM.createElement(`<div id="bd-settingspane-container" class="contentRegion-3nDuYy content-region">`);
|
|
|
|
sidebar.append(root);
|
2020-02-27 08:01:51 +01:00
|
|
|
|
2020-03-29 11:17:12 +02:00
|
|
|
Utils.onRemoved(root, () => {
|
|
|
|
BDV2.reactDom.unmountComponentAtNode(root);
|
2020-02-27 08:01:51 +01:00
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
get coreSettings() {
|
|
|
|
const settings = this.getSettings("core");
|
|
|
|
const categories = [...new Set(settings.map(s => s.category))];
|
|
|
|
const sections = categories.map(c => {return {title: c, settings: settings.filter(s => s.category == c)};});
|
|
|
|
return sections;
|
|
|
|
}
|
|
|
|
|
|
|
|
get emoteSettings() {
|
|
|
|
return this.getSettings("emote");
|
|
|
|
}
|
|
|
|
getSettings(category) {
|
|
|
|
return Object.keys(settings).reduce((arr, key) => {
|
|
|
|
const setting = settings[key];
|
|
|
|
if (setting.cat === category && setting.implemented && !setting.hidden) {
|
2020-03-21 05:27:56 +01:00
|
|
|
setting.text = key;
|
|
|
|
arr.push(setting);
|
2020-02-27 08:01:51 +01:00
|
|
|
}
|
|
|
|
return arr;
|
|
|
|
}, []);
|
|
|
|
}
|
|
|
|
|
|
|
|
sideBarOnClick(id) {
|
2020-03-29 11:17:12 +02:00
|
|
|
const contentRegion = DOM.query(".contentRegion-3nDuYy, .content-region");
|
|
|
|
contentRegion.style.display = "none";
|
|
|
|
this.root.style.display = "";
|
2020-02-27 08:01:51 +01:00
|
|
|
switch (id) {
|
|
|
|
case "core":
|
2020-03-29 11:17:12 +02:00
|
|
|
this.renderCoreSettings();
|
2020-02-27 08:01:51 +01:00
|
|
|
break;
|
|
|
|
case "emotes":
|
2020-03-29 11:17:12 +02:00
|
|
|
this.renderEmoteSettings();
|
2020-02-27 08:01:51 +01:00
|
|
|
break;
|
|
|
|
case "customcss":
|
2020-03-29 11:17:12 +02:00
|
|
|
this.renderCustomCssEditor();
|
2020-02-27 08:01:51 +01:00
|
|
|
break;
|
|
|
|
case "plugins":
|
|
|
|
case "themes":
|
2020-03-29 21:43:42 +02:00
|
|
|
this.renderAddonPane(id);
|
2020-02-27 08:01:51 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onClick() {}
|
|
|
|
|
|
|
|
onChange(id, checked) {
|
|
|
|
this.updateSettings(id, checked);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateSettings(id, enabled) {
|
|
|
|
settingsCookie[id] = enabled;
|
|
|
|
|
|
|
|
if (id == "bda-gs-2") {
|
2020-03-29 11:17:12 +02:00
|
|
|
if (enabled) DOM.addClass(document.body, "bd-minimal");
|
|
|
|
else DOM.removeClass(document.body, "bd-minimal");
|
2020-02-27 08:01:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (id == "bda-gs-3") {
|
2020-03-29 11:17:12 +02:00
|
|
|
if (enabled) DOM.addClass(document.body, "bd-minimal-chan");
|
|
|
|
else DOM.removeClass(document.body, "bd-minimal-chan");
|
2020-02-27 08:01:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (id == "bda-gs-1") {
|
|
|
|
if (enabled) publicServersModule.addButton();
|
|
|
|
else publicServersModule.removeButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (id == "bda-gs-4") {
|
2020-03-29 11:17:12 +02:00
|
|
|
if (enabled) voiceMode.start();
|
|
|
|
else voiceMode.stop();
|
2020-02-27 08:01:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (id == "bda-gs-5") {
|
2020-03-29 11:17:12 +02:00
|
|
|
if (enabled) DOM.addClass(DOM.query("#app-mount"), "bda-dark");
|
|
|
|
else DOM.removeClass(DOM.query("#app-mount"), "bda-dark");
|
2020-02-27 08:01:51 +01:00
|
|
|
}
|
|
|
|
|
2020-02-27 22:26:23 +01:00
|
|
|
if (enabled && id == "bda-gs-6") tfHour.inject24Hour();
|
2020-02-27 08:01:51 +01:00
|
|
|
|
|
|
|
if (id == "bda-gs-7") {
|
|
|
|
if (enabled) coloredText.injectColoredText();
|
|
|
|
else coloredText.removeColoredText();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (id == "fork-ps-4") {
|
|
|
|
if (enabled) ClassNormalizer.start();
|
|
|
|
else ClassNormalizer.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (id == "fork-ps-5") {
|
|
|
|
if (enabled) {
|
|
|
|
ContentManager.watchContent("plugin");
|
|
|
|
ContentManager.watchContent("theme");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ContentManager.unwatchContent("plugin");
|
|
|
|
ContentManager.unwatchContent("theme");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (id == "fork-wp-1") {
|
2020-03-28 04:31:28 +01:00
|
|
|
Utils.setWindowPreference("transparent", enabled);
|
|
|
|
if (enabled) Utils.setWindowPreference("backgroundColor", null);
|
|
|
|
else Utils.setWindowPreference("backgroundColor", "#2f3136");
|
2020-02-27 08:01:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (id == "bda-gs-8") {
|
2020-03-29 11:17:12 +02:00
|
|
|
if (enabled) dMode.startDebugListener();
|
|
|
|
else dMode.stopDebugListener();
|
2020-02-27 08:01:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (id == "fork-dm-1") {
|
2020-03-29 11:17:12 +02:00
|
|
|
if (enabled) dMode.startCopySelector();
|
|
|
|
else dMode.stopCopySelector();
|
2020-02-27 08:01:51 +01:00
|
|
|
}
|
|
|
|
|
2020-03-28 03:44:59 +01:00
|
|
|
if (id === "reactDevTools") {
|
|
|
|
if (enabled) reactDevTools.start();
|
|
|
|
else reactDevTools.stop();
|
|
|
|
}
|
|
|
|
|
2020-02-27 08:01:51 +01:00
|
|
|
this.saveSettings();
|
|
|
|
}
|
|
|
|
|
2020-02-27 22:26:23 +01:00
|
|
|
async initializeSettings() {
|
2020-04-26 06:10:15 +02:00
|
|
|
if (settingsCookie.reactDevTools) reactDevTools.start();
|
2020-03-29 11:17:12 +02:00
|
|
|
if (settingsCookie["bda-gs-2"]) DOM.addClass(document.body, "bd-minimal");
|
|
|
|
if (settingsCookie["bda-gs-3"]) DOM.addClass(document.body, "bd-minimal-chan");
|
2020-02-27 08:01:51 +01:00
|
|
|
if (settingsCookie["bda-gs-1"]) publicServersModule.addButton();
|
2020-03-29 11:17:12 +02:00
|
|
|
if (settingsCookie["bda-gs-4"]) voiceMode.start();
|
|
|
|
if (settingsCookie["bda-gs-5"]) DOM.addClass(DOM.query("#app-mount"), "bda-dark");
|
2020-02-27 22:26:23 +01:00
|
|
|
if (settingsCookie["bda-gs-6"]) tfHour.inject24Hour();
|
2020-02-27 08:01:51 +01:00
|
|
|
if (settingsCookie["bda-gs-7"]) coloredText.injectColoredText();
|
|
|
|
if (settingsCookie["fork-ps-4"]) ClassNormalizer.start();
|
|
|
|
|
|
|
|
if (settingsCookie["fork-ps-5"]) {
|
|
|
|
ContentManager.watchContent("plugin");
|
|
|
|
ContentManager.watchContent("theme");
|
|
|
|
}
|
|
|
|
|
2020-03-29 11:17:12 +02:00
|
|
|
if (settingsCookie["bda-gs-8"]) dMode.startDebugListener();
|
|
|
|
if (settingsCookie["fork-dm-1"]) dMode.startCopySelector();
|
2020-02-27 08:01:51 +01:00
|
|
|
|
|
|
|
this.saveSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
saveSettings() {
|
|
|
|
DataStore.setSettingGroup("settings", settingsCookie);
|
|
|
|
}
|
2020-02-27 22:26:23 +01:00
|
|
|
|
2020-02-27 08:01:51 +01:00
|
|
|
loadSettings() {
|
|
|
|
Object.assign(settingsCookie, DataStore.getSettingGroup("settings"));
|
|
|
|
}
|
|
|
|
|
2020-03-29 11:17:12 +02:00
|
|
|
showOriginal() {
|
|
|
|
BDV2.reactDom.unmountComponentAtNode(this.root);
|
|
|
|
this.root.style.display = "none";
|
|
|
|
DOM.query(".contentRegion-3nDuYy, .content-region").style.display = "";
|
|
|
|
}
|
|
|
|
|
2020-02-27 08:01:51 +01:00
|
|
|
renderSidebar() {
|
2020-03-29 11:17:12 +02:00
|
|
|
const tabs = document.querySelectorAll("[class*='side-'] > [class*='item-']");
|
|
|
|
for (const element of tabs) {
|
|
|
|
element.removeEventListener("click", this.showOriginal);
|
|
|
|
element.addEventListener("click", this.showOriginal);
|
|
|
|
}
|
|
|
|
this.sidebar.render();
|
2020-02-27 08:01:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
get coreComponent() {
|
2020-03-28 03:44:59 +01:00
|
|
|
return BDV2.react.createElement(Scroller, {contentColumn: true, fade: true, dark: true},
|
2020-02-27 08:01:51 +01:00
|
|
|
BDV2.react.createElement(SectionedSettingsPanel, {key: "cspanel", onChange: this.onChange, sections: this.coreSettings}),
|
|
|
|
BDV2.react.createElement(Tools, {key: "tools"})
|
2020-03-28 03:44:59 +01:00
|
|
|
);
|
2020-02-27 08:01:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
get emoteComponent() {
|
|
|
|
return BDV2.react.createElement(Scroller, {
|
2020-03-28 03:44:59 +01:00
|
|
|
contentColumn: true, fade: true, dark: true},
|
2020-02-27 08:01:51 +01:00
|
|
|
BDV2.react.createElement(SettingsPanel, {key: "espanel", title: "Emote Settings", onChange: this.onChange, settings: this.emoteSettings, button: {
|
|
|
|
title: "Clear Emote Cache",
|
|
|
|
onClick: () => { emoteModule.clearEmoteData(); emoteModule.init(); quickEmoteMenu.init(); }
|
|
|
|
}}),
|
|
|
|
BDV2.react.createElement(Tools, {key: "tools"})
|
2020-03-28 03:44:59 +01:00
|
|
|
);
|
2020-02-27 08:01:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
get customCssComponent() {
|
2020-03-28 03:44:59 +01:00
|
|
|
return BDV2.react.createElement(Scroller, {contentColumn: true, fade: true, dark: true},
|
|
|
|
BDV2.react.createElement(CssEditor, {key: "csseditor"}),
|
|
|
|
BDV2.react.createElement(Tools, {key: "tools"})
|
|
|
|
);
|
2020-02-27 08:01:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
renderCoreSettings() {
|
|
|
|
const root = this.root;
|
2020-03-29 21:43:42 +02:00
|
|
|
if (!root) return Utils.err("SettingsPanel", "FAILED TO LOCATE ROOT: .layer-3QrUeG .standardSidebarView-3F1I7i");
|
2020-02-27 08:01:51 +01:00
|
|
|
BDV2.reactDom.render(this.coreComponent, root);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderEmoteSettings() {
|
|
|
|
const root = this.root;
|
2020-03-29 21:43:42 +02:00
|
|
|
if (!root) return Utils.err("SettingsPanel", "FAILED TO LOCATE ROOT: .layer-3QrUeG .standardSidebarView-3F1I7i");
|
2020-02-27 08:01:51 +01:00
|
|
|
BDV2.reactDom.render(this.emoteComponent, root);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderCustomCssEditor() {
|
|
|
|
const root = this.root;
|
2020-03-29 21:43:42 +02:00
|
|
|
if (!root) return Utils.err("SettingsPanel", "FAILED TO LOCATE ROOT: .layer-3QrUeG .standardSidebarView-3F1I7i");
|
2020-02-27 08:01:51 +01:00
|
|
|
BDV2.reactDom.render(this.customCssComponent, root);
|
|
|
|
}
|
|
|
|
|
2020-03-29 21:43:42 +02:00
|
|
|
// renderAddonPane(type) {
|
|
|
|
// const root = this.root;
|
|
|
|
// if (!root) return Utils.err("SettingsPanel", "FAILED TO LOCATE ROOT: .layer-3QrUeG .standardSidebarView-3F1I7i");
|
|
|
|
// BDV2.reactDom.render(this.contentComponent(type), root);
|
|
|
|
// }
|
|
|
|
|
|
|
|
renderAddonPane(type) {
|
|
|
|
if (!this.root) return Utils.err("SettingsPanel", "FAILED TO LOCATE ROOT: .layer-3QrUeG .standardSidebarView-3F1I7i");
|
|
|
|
// I know this shouldn't be here, but when it isn't,
|
|
|
|
// React refuses to change the button when going
|
|
|
|
// between plugins and themes page... something
|
|
|
|
// to debug later.
|
|
|
|
class ContentList extends BDV2.react.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.prefix = this.props.type.replace("s", "");
|
|
|
|
this.onChange = this.onChange.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
BDEvents.on(`${this.prefix}-reloaded`, this.onChange);
|
|
|
|
BDEvents.on(`${this.prefix}-loaded`, this.onChange);
|
|
|
|
BDEvents.on(`${this.prefix}-unloaded`, this.onChange);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
BDEvents.off(`${this.prefix}-reloaded`, this.onChange);
|
|
|
|
BDEvents.off(`${this.prefix}-loaded`, this.onChange);
|
|
|
|
BDEvents.off(`${this.prefix}-unloaded`, this.onChange);
|
|
|
|
}
|
|
|
|
|
|
|
|
onChange() {
|
|
|
|
this.props.onChange(this.props.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {return this.props.children;}
|
2020-02-27 08:01:51 +01:00
|
|
|
}
|
2020-03-29 21:43:42 +02:00
|
|
|
const list = type === "plugins" ? Object.values(bdplugins) : Object.values(bdthemes);
|
|
|
|
return BDV2.reactDom.render(BDV2.react.createElement(ContentList, {type, onChange: this.sideBarOnClick}, BDV2.react.createElement(CardList, {type, list})), this.root);
|
2020-02-27 08:01:51 +01:00
|
|
|
}
|
|
|
|
};
|