a lot of UI progress

This commit is contained in:
Zack Rauen 2019-05-28 17:27:25 -04:00
parent 665872a38f
commit 950ab70df4
53 changed files with 9379 additions and 492 deletions

View File

@ -38,6 +38,7 @@
"_bdhash": true,
"ace": false,
"Reflect": false,
"DiscordNative": false
"DiscordNative": false,
"__non_webpack_require__": false
}
}

View File

@ -1,7 +1,9 @@
var settingsPanel, emoteModule, quickEmoteMenu, voiceMode, pluginModule, themeModule, dMode, publicServersModule;
var minSupportedVersion = "0.3.0";
var bbdVersion = "0.2.17";
var mainCore;
var settingsCookie = {};
var bdpluginErrors = [], bdthemeErrors = []; // define for backwards compatibility
var bdConfig = null;
// var settingsPanel, emoteModule, quickEmoteMenu, voiceMode, pluginModule, themeModule, dMode, publicServersModule;
// var minSupportedVersion = "0.3.0";
// var bbdVersion = "0.2.17";
// var mainCore;
// var settingsCookie = {};
// var bdpluginErrors = [], bdthemeErrors = []; // define for backwards compatibility
// var bdConfig = null;
//settingsCookie, bdplugins, bdthemes, pluginCookie, themeCookie, pluginModule, themeModule

6035
js/release.js Normal file

File diff suppressed because it is too large Load Diff

2973
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,7 @@
"description": "Enhances Discord adding functionality and themes.",
"main": "js/main.js",
"scripts": {
"build": "webpack --progress --colors",
"test": "echo \"Error: no test specified\" && exit 1",
"minify": "gulp minify-js && gulp minify-css",
"minify-js": "gulp minify-js",
@ -26,6 +27,11 @@
"gulp": "^4.0.0",
"gulp-babel-minify": "^0.5.0",
"gulp-csso": "^3.0.1",
"gulp-rename": "^1.4.0"
"gulp-rename": "^1.4.0",
"@babel/core": "^7.3.4",
"@babel/preset-env": "^7.3.4",
"@babel/register": "^7.0.0",
"webpack": "^4.29.6",
"webpack-cli": "^3.2.3"
}
}

10
src/data/config.js Normal file
View File

@ -0,0 +1,10 @@
export default {
local: false,
localServer: "//localhost:8080",
minified: true,
version: "0.3.0",
branch: "master",
repo: "rauenzi",
minSupportedVersion: "0.3.0",
bbdVersion: "0.2.17"
};

View File

@ -1,8 +0,0 @@
{
"local": false,
"localServer": "//localhost:8080",
"minified": true,
"version": "0.3.0",
"branch": "master",
"repo": "rauenzi"
}

View File

@ -1,4 +1,4 @@
var settings = {
export default {
"Custom css live update": {id: "bda-css-0", info: "", implemented: true, hidden: true, cat: "core"},
"Custom css auto udpate": {id: "bda-css-1", info: "", implemented: true, hidden: true, cat: "core"},
"BetterDiscord Blue": {id: "bda-gs-b", info: "Replace Discord blue with BD Blue", implemented: false, hidden: false, cat: "core"},

View File

@ -1,4 +1,4 @@
var defaultCookie = {
export default {
"bda-gs-1": true,
"bda-gs-2": false,
"bda-gs-3": false,

View File

@ -1,8 +1,13 @@
import proxyLocalStorage from "./localstorage";
import Core from "./modules/core";
// Perform some setup
proxyLocalStorage();
const loadingIcon = document.createElement("div");
loadingIcon.className = "bd-loaderv2";
loadingIcon.title = "BandagedBD is loading...";
document.body.appendChild(loadingIcon);
document.body.appendChild(loadingIcon);
window.Core = Core;
export default Core;

View File

@ -1,4 +1,8 @@
var BDV2 = new class V2 {
import Settings from "../data/settings";
import BdApi from "./pluginapi";
import BDLogo from "../ui/icons/bdlogo";
export default new class V2 {
constructor() {
this.editorDetached = false;
@ -71,8 +75,8 @@ var BDV2 = new class V2 {
get KeyGenerator() {return this.WebpackModules.find(m => m.toString && /"binary"/.test(m.toString()));}
parseSettings(cat) {
return Object.keys(settings).reduce((arr, key) => {
let setting = settings[key];
return Object.keys(Settings).reduce((arr, key) => {
let setting = Settings[key];
if (setting.cat === cat && setting.implemented && !setting.hidden) {
setting.text = key;
arr.push(setting);
@ -151,4 +155,4 @@ var BDV2 = new class V2 {
}});
}
}
};

View File

@ -120,9 +120,9 @@ var ContentManager = (() => {
if (typeof(filename) === "undefined" || typeof(type) === "undefined") return;
const isPlugin = type === "plugin";
const baseFolder = isPlugin ? this.pluginsFolder : this.themesFolder;
try {require(path.resolve(baseFolder, filename));}
try {__non_webpack_require__(path.resolve(baseFolder, filename));}
catch (error) {return {name: filename, file: filename, message: "Could not be compiled.", error: {message: error.message, stack: error.stack}};}
const content = require(path.resolve(baseFolder, filename));
const content = __non_webpack_require__(path.resolve(baseFolder, filename));
if (isPlugin) {
if (!content.type) return;
try {
@ -143,7 +143,7 @@ var ContentManager = (() => {
const isPlugin = type === "plugin";
const baseFolder = isPlugin ? this.pluginsFolder : this.themesFolder;
try {
delete require.cache[require.resolve(path.resolve(baseFolder, filename))];
delete __non_webpack_require__.cache[__non_webpack_require__.resolve(path.resolve(baseFolder, filename))];
}
catch (err) {return {name: filename, file: filename, message: "Could not be unloaded.", error: {message: err.message, stack: err.stack}};}
}
@ -151,7 +151,7 @@ var ContentManager = (() => {
isLoaded(filename, type) {
const isPlugin = type === "plugin";
const baseFolder = isPlugin ? this.pluginsFolder : this.themesFolder;
try {require.cache[require.resolve(path.resolve(baseFolder, filename))];}
try {__non_webpack_require__.cache[__non_webpack_require__.resolve(path.resolve(baseFolder, filename))];}
catch (err) {return false;}
return true;
}

View File

@ -1,70 +1,83 @@
import Utilties from "./utilities";
import Config from "../data/config";
import Settings from "../data/settingscookie";
import BDV2 from "./bdv2";
import EmoteModule from "./emotes";
import QuickEmoteMenu from "./emotemenu";
import VoiceMode from "./voicemode";
import DevMode from "./devmode";
import PluginModule from "./pluginmanager";
import ThemeModule from "./thememanager";
import DataStore from "./datastore";
import {PublicServers, SettingsPanel} from "ui";
function Core(config) {
window.bdConfig = config;
Object.assign(Config, config);
}
Core.prototype.init = async function() {
if (bdConfig.version < minSupportedVersion) {
this.alert("Not Supported", "BetterDiscord v" + bdConfig.version + " (your version)" + " is not supported by the latest js (" + bbdVersion + ").<br><br> Please download the latest version from <a href='https://github.com/rauenzi/BetterDiscordApp/releases/latest' target='_blank'>GitHub</a>");
if (Config.version < Config.minSupportedVersion) {
this.alert("Not Supported", "BetterDiscord v" + Config.version + " (your version)" + " is not supported by the latest js (" + Config.bbdVersion + ").<br><br> Please download the latest version from <a href='https://github.com/rauenzi/BetterDiscordApp/releases/latest' target='_blank'>GitHub</a>");
return;
}
if (bdConfig.updater.LatestVersion > bdConfig.version) {
if (Config.updater.LatestVersion > Config.version) {
this.alert("Update Available", `
An update for BandagedBD is available (${bdConfig.updater.LatestVersion})! Please Reinstall!<br /><br />
An update for BandagedBD is available (${Config.updater.LatestVersion})! Please Reinstall!<br /><br />
<a href='https://github.com/rauenzi/BetterDiscordApp/releases/latest' target='_blank'>Download Installer</a>
`);
}
Utils.log("Startup", "Initializing Settings");
Utilties.log("Startup", "Initializing Settings");
this.initSettings();
emoteModule = new EmoteModule();
quickEmoteMenu = new QuickEmoteMenu();
Utils.log("Startup", "Initializing EmoteModule");
window.emotePromise = emoteModule.init().then(() => {
emoteModule.initialized = true;
Utils.log("Startup", "Initializing QuickEmoteMenu");
quickEmoteMenu.init();
this.emoteModule = new EmoteModule();
this.quickEmoteMenu = new QuickEmoteMenu();
Utilties.log("Startup", "Initializing EmoteModule");
window.emotePromise = this.emoteModule.init().then(() => {
this.emoteModule.initialized = true;
Utilties.log("Startup", "Initializing QuickEmoteMenu");
this.quickEmoteMenu.init();
});
publicServersModule = new V2_PublicServers();
this.publicServersModule = new PublicServers();
voiceMode = new VoiceMode();
dMode = new devMode();
this.voiceMode = new VoiceMode();
this.dMode = new DevMode();
this.injectExternals();
await this.checkForGuilds();
BDV2.initialize();
Utils.log("Startup", "Updating Settings");
settingsPanel = new V2_SettingsPanel();
settingsPanel.initializeSettings();
Utilties.log("Startup", "Updating Settings");
this.settingsPanel = new SettingsPanel();
this.settingsPanel.initializeSettings();
Utils.log("Startup", "Loading Plugins");
pluginModule = new PluginModule();
pluginModule.loadPlugins();
Utilties.log("Startup", "Loading Plugins");
this.pluginModule = new PluginModule();
const pluginErrors = this.pluginModule.loadPlugins();
Utils.log("Startup", "Loading Themes");
themeModule = new ThemeModule();
themeModule.loadThemes();
Utilties.log("Startup", "Loading Themes");
this.themeModule = new ThemeModule();
const themeErrors = this.themeModule.loadThemes();
$("#customcss").detach().appendTo(document.head);
window.addEventListener("beforeunload", function() {
if (settingsCookie["bda-dc-0"]) document.querySelector(".btn.btn-disconnect").click();
if (Settings["bda-dc-0"]) document.querySelector(".btn.btn-disconnect").click();
});
publicServersModule.initialize();
this.publicServersModule.initialize();
emoteModule.autoCapitalize();
this.emoteModule.autoCapitalize();
Utils.log("Startup", "Removing Loading Icon");
Utilties.log("Startup", "Removing Loading Icon");
document.getElementsByClassName("bd-loaderv2")[0].remove();
Utils.log("Startup", "Initializing Main Observer");
Utilties.log("Startup", "Initializing Main Observer");
this.initObserver();
// Show loading errors
if (settingsCookie["fork-ps-1"]) {
Utils.log("Startup", "Collecting Startup Errors");
this.showContentErrors({plugins: bdpluginErrors, themes: bdthemeErrors});
if (Settings["fork-ps-1"]) {
Utilties.log("Startup", "Collecting Startup Errors");
this.showContentErrors({plugins: pluginErrors, themes: themeErrors});
}
// if (!DataStore.getBDData(bbdVersion)) {
@ -79,7 +92,7 @@ Core.prototype.checkForGuilds = function() {
const wrapper = BDV2.guildClasses.wrapper.split(" ")[0];
const guild = BDV2.guildClasses.listItem.split(" ")[0];
const blob = BDV2.guildClasses.blobContainer.split(" ")[0];
if (document.querySelectorAll(`.${wrapper} .${guild} .${blob}`).length > 0) return resolve(bdConfig.deferLoaded = true);
if (document.querySelectorAll(`.${wrapper} .${guild} .${blob}`).length > 0) return resolve(Config.deferLoaded = true);
setTimeout(checkForGuilds, 100);
};
$(document).ready(function () {
@ -89,34 +102,28 @@ Core.prototype.checkForGuilds = function() {
};
Core.prototype.injectExternals = async function() {
await Utils.injectJs("https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.9/ace.js");
if (require.original) window.require = require.original;
await Utilties.injectJs("https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.9/ace.js");
// if (require.original) window.require = require.original;
};
Core.prototype.initSettings = function () {
DataStore.initialize();
if (!DataStore.getSettingGroup("settings")) {
settingsCookie = defaultCookie;
this.saveSettings();
}
else {
this.loadSettings();
$("<style id=\"customcss\">").text(atob(DataStore.getBDData("bdcustomcss"))).appendTo(document.head);
for (var setting in defaultCookie) {
if (settingsCookie[setting] == undefined) {
settingsCookie[setting] = defaultCookie[setting];
this.saveSettings();
}
}
if (!DataStore.getSettingGroup("settings")) return this.saveSettings();
const savedSettings = this.loadSettings();
$("<style id=\"customcss\">").text(atob(DataStore.getBDData("bdcustomcss"))).appendTo(document.head);
for (const setting in savedSettings) {
if (savedSettings[setting] !== undefined) Settings[setting] = savedSettings[setting];
}
this.saveSettings();
};
Core.prototype.saveSettings = function () {
DataStore.setSettingGroup("settings", settingsCookie);
DataStore.setSettingGroup("settings", Settings);
};
Core.prototype.loadSettings = function () {
settingsCookie = DataStore.getSettingGroup("settings");
Settings = DataStore.getSettingGroup("settings");
};
Core.prototype.initObserver = function () {
@ -124,7 +131,7 @@ Core.prototype.initObserver = function () {
for (let i = 0, mlen = mutations.length; i < mlen; i++) {
let mutation = mutations[i];
if (typeof pluginModule !== "undefined") pluginModule.rawObserver(mutation);
if (typeof pluginModule !== "undefined") this.pluginModule.rawObserver(mutation);
// if there was nothing added, skip
if (!mutation.addedNodes.length || !(mutation.addedNodes[0] instanceof Element)) continue;
@ -137,12 +144,12 @@ Core.prototype.initObserver = function () {
if (node.getElementsByClassName("socialLinks-3jqNFy").length) {
node.setAttribute("layer-id", "user-settings");
node.setAttribute("id", "user-settings");
if (!document.getElementById("bd-settings-sidebar")) settingsPanel.renderSidebar();
if (!document.getElementById("bd-settings-sidebar")) this.settingsPanel.renderSidebar();
}
}
// Emoji Picker
if (node.classList.contains("popout-3sVMXz") && !node.classList.contains("popoutLeft-30WmrD") && node.getElementsByClassName("emojiPicker-3m1S-j").length) quickEmoteMenu.obsCallback(node);
if (node.classList.contains("popout-3sVMXz") && !node.classList.contains("popoutLeft-30WmrD") && node.getElementsByClassName("emojiPicker-3m1S-j").length) this.quickEmoteMenu.obsCallback(node);
}
});
@ -158,7 +165,7 @@ Core.prototype.inject24Hour = function() {
const twelveHour = new RegExp(`([0-9]{1,2}):([0-9]{1,2})\\s(AM|PM)`);
const convert = (data) => {
if (!settingsCookie["bda-gs-6"]) return;
if (!Settings["bda-gs-6"]) return;
const matched = data.returnValue.match(twelveHour);
if (!matched || matched.length !== 4) return;
if (matched[3] === "AM") return data.returnValue = data.returnValue.replace(matched[0], `${matched[1] === "12" ? "00" : matched[1].padStart(2, "0")}:${matched[2]}`);
@ -166,17 +173,17 @@ Core.prototype.inject24Hour = function() {
};
const cancelCozy = Utils.monkeyPatch(BDV2.TimeFormatter, "calendarFormat", {after: convert}); // Called in Cozy mode
const cancelCompact = Utils.monkeyPatch(BDV2.TimeFormatter, "dateFormat", {after: convert}); // Called in Compact mode
const cancelCozy = Utilties.monkeyPatch(BDV2.TimeFormatter, "calendarFormat", {after: convert}); // Called in Cozy mode
const cancelCompact = Utilties.monkeyPatch(BDV2.TimeFormatter, "dateFormat", {after: convert}); // Called in Compact mode
this.cancel24Hour = () => {cancelCozy(); cancelCompact();}; // Cancel both
};
Core.prototype.injectColoredText = function() {
if (this.cancelColoredText) return;
this.cancelColoredText = Utils.monkeyPatch(BDV2.MessageContentComponent.prototype, "render", {after: (data) => {
if (!settingsCookie["bda-gs-7"]) return;
Utils.monkeyPatch(data.returnValue.props, "children", {silent: true, after: ({returnValue}) => {
this.cancelColoredText = Utilties.monkeyPatch(BDV2.MessageContentComponent.prototype, "render", {after: (data) => {
if (!Settings["bda-gs-7"]) return;
Utilties.monkeyPatch(data.returnValue.props, "children", {silent: true, after: ({returnValue}) => {
const markup = returnValue.props.children[1];
const roleColor = data.thisObject.props.message.colorString;
if (markup && roleColor) markup.props.style = {color: roleColor};
@ -268,7 +275,7 @@ Core.prototype.showContentErrors = function({plugins: pluginErrors = [], themes:
if (err.error) {
error.find("a").on("click", (e) => {
e.preventDefault();
Utils.err("ContentManager", `Error details for ${err.name ? err.name : err.file}.`, err.error);
Utilties.err("ContentManager", `Error details for ${err.name ? err.name : err.file}.`, err.error);
});
}
}
@ -307,7 +314,7 @@ Core.prototype.showContentErrors = function({plugins: pluginErrors = [], themes:
* @param {number} options.timeout Adjusts the time (in ms) the toast should be shown for before disappearing automatically. Default: 3000
*/
Core.prototype.showToast = function(content, options = {}) {
if (!bdConfig.deferLoaded) return;
if (!Config.deferLoaded) return;
if (!document.querySelector(".bd-toasts")) {
let toastWrapper = document.createElement("div");
toastWrapper.classList.add("bd-toasts");
@ -331,4 +338,7 @@ Core.prototype.showToast = function(content, options = {}) {
if (!document.querySelectorAll(".bd-toasts .bd-toast").length) document.querySelector(".bd-toasts").remove();
}, 300);
}, timeout);
};
};
export default Core;

View File

@ -1,4 +1,5 @@
const Config = require("../data/config.json");
import Config from "../data/config";
import BdApi from "./pluginapi";
const fs = require("fs");
const path = require("path");
const releaseChannel = DiscordNative.globals.releaseChannel;
@ -12,10 +13,10 @@ export default class DataStore {
initialize() {
try {
if (!fs.existsSync(this.BDFile)) fs.writeFileSync(this.BDFile, JSON.stringify(this.data, null, 4));
const data = require(this.BDFile);
const data = __non_webpack_require__(this.BDFile);
if (data.hasOwnProperty("settings")) this.data = data;
if (!fs.existsSync(this.settingsFile)) return;
let settings = require(this.settingsFile);
let settings = __non_webpack_require__(this.settingsFile);
fs.unlinkSync(this.settingsFile);
if (settings.hasOwnProperty("settings")) settings = Object.assign({stable: {}, canary: {}, ptb: {}}, {[releaseChannel]: settings});
else settings = Object.assign({stable: {}, canary: {}, ptb: {}}, settings);

View File

@ -1,3 +1,5 @@
import BDV2 from "./bdv2";
function devMode() {}
devMode.prototype.enable = function(selectorMode) {
@ -77,4 +79,6 @@ devMode.prototype.getSelector = function(element) {
$(window).off("keydown.bdDevmode");
$(document).off("contextmenu.bdDevmode");
$(document).off("contextmenu.bdDevModeCtx");
};
};
export default devMode;

View File

@ -1,3 +1,7 @@
import Settings from "../data/settingscookie";
import DataStore from "./datastore";
import Utilities from "./utilities";
function QuickEmoteMenu() {
}
@ -74,8 +78,8 @@ QuickEmoteMenu.prototype.favContext = function(e, em) {
e.stopPropagation();
$(this).remove();
delete quickEmoteMenu.favoriteEmotes[$(this).data("emoteid")];
quickEmoteMenu.updateFavorites();
delete this.favoriteEmotes[$(this).data("emoteid")];
this.updateFavorites();
return false;
});
return false;
@ -118,22 +122,22 @@ QuickEmoteMenu.prototype.switchQem = function(id) {
emoteIcon.off();
emoteIcon.on("click", function () {
var emote = $(this).attr("title");
var ta = Utils.getTextArea();
Utils.insertText(ta[0], ta.val().slice(-1) == " " ? ta.val() + emote : ta.val() + " " + emote);
var ta = Utilities.getTextArea();
Utilities.insertText(ta[0], ta.val().slice(-1) == " " ? ta.val() + emote : ta.val() + " " + emote);
});
};
QuickEmoteMenu.prototype.obsCallback = function (elem) {
if (!this.initialized) return;
var e = $(elem);
if (!settingsCookie["bda-es-9"]) {
if (!Settings["bda-es-9"]) {
e.addClass("bda-qme-hidden");
}
else {
e.removeClass("bda-qme-hidden");
}
if (!settingsCookie["bda-es-0"]) return;
if (!Settings["bda-es-0"]) return;
e.prepend(this.qmeHeader);
e.append(this.teContainer);
@ -176,4 +180,6 @@ QuickEmoteMenu.prototype.updateFavorites = function () {
$("#bda-qem-favourite-container").replaceWith(faContainer);
DataStore.setBDData("bdfavemotes", btoa(JSON.stringify(this.favoriteEmotes)));
};
};
export default QuickEmoteMenu;

View File

@ -1,3 +1,11 @@
import Config from "../data/config";
import Settings from "../data/settingscookie";
import Utilities from "./utilities";
import BDV2 from "./bdv2";
import BDEmote from "../ui/emote";
import BdApi from "./pluginapi";
import DataStore from "./datastore";
window.emotesFfz = {};
window.emotesBTTV = {};
window.emotesBTTV2 = {};
@ -25,7 +33,7 @@ function EmoteModule() {
get: function() {
const cats = [];
for (const current in window.bdEmoteSettingIDs) {
if (settingsCookie[window.bdEmoteSettingIDs[current]]) cats.push(current);
if (Settings[window.bdEmoteSettingIDs[current]]) cats.push(current);
}
return cats;
}
@ -89,8 +97,8 @@ EmoteModule.prototype.init = async function () {
while (!BDV2.MessageContentComponent) await new Promise(resolve => setTimeout(resolve, 100));
if (this.cancelEmoteRender) return;
this.cancelEmoteRender = Utils.monkeyPatch(BDV2.MessageContentComponent.prototype, "render", {after: ({returnValue}) => {
Utils.monkeyPatch(returnValue.props, "children", {silent: true, after: ({returnValue}) => {
this.cancelEmoteRender = Utilities.monkeyPatch(BDV2.MessageContentComponent.prototype, "render", {after: ({returnValue}) => {
Utilities.monkeyPatch(returnValue.props, "children", {silent: true, after: ({returnValue}) => {
if (this.categories.length == 0) return;
const markup = returnValue.props.children[1];
if (!markup.props.children) return;
@ -109,7 +117,7 @@ EmoteModule.prototype.init = async function () {
let emoteOverride = emoteModifier.slice(0);
if (emoteName.length < 4 || bemotes.includes(emoteName)) continue;
if (!this.modifiers.includes(emoteModifier) || !settingsCookie["bda-es-8"]) emoteModifier = "";
if (!this.modifiers.includes(emoteModifier) || !Settings["bda-es-8"]) emoteModifier = "";
if (!this.overrides.includes(emoteOverride)) emoteOverride = "";
else emoteModifier = emoteOverride;
@ -126,8 +134,8 @@ EmoteModule.prototype.init = async function () {
if (window.bdEmotes.FrankerFaceZ[emoteName]) current = "FrankerFaceZ";
}
if (!window.bdEmotes[current][emoteName] || !settingsCookie[window.bdEmoteSettingIDs[current]]) continue;
const results = nodes[n].match(new RegExp(`([\\s]|^)${Utils.escape(emoteModifier ? emoteName + ":" + emoteModifier : emoteName)}([\\s]|$)`));
if (!window.bdEmotes[current][emoteName] || !Settings[window.bdEmoteSettingIDs[current]]) continue;
const results = nodes[n].match(new RegExp(`([\\s]|^)${Utilities.escape(emoteModifier ? emoteName + ":" + emoteModifier : emoteName)}([\\s]|$)`));
if (!results) continue;
const pre = nodes[n].substring(0, results.index + results[1].length);
const post = nodes[n].substring(results.index + results[0].length - results[2].length);
@ -165,7 +173,7 @@ EmoteModule.prototype.disable = function() {
EmoteModule.prototype.clearEmoteData = async function() {
let _fs = require("fs");
let emoteFile = "emote_data.json";
let file = bdConfig.dataPath + emoteFile;
let file = Config.dataPath + emoteFile;
let exists = _fs.existsSync(file);
if (exists) _fs.unlinkSync(file);
DataStore.setBDData("emoteCacheDate", (new Date()).toJSON());
@ -191,7 +199,7 @@ EmoteModule.prototype.isCacheValid = function() {
const cacheDate = new Date(DataStore.getBDData("emoteCacheDate") || null);
const currentDate = new Date();
const daysBetween = Math.round(Math.abs((currentDate.getTime() - cacheDate.getTime()) / (24 * 60 * 60 * 1000)));
if (daysBetween > bdConfig.cache.days) {
if (daysBetween > Config.cache.days) {
DataStore.setBDData("emoteCacheDate", currentDate.toJSON());
return false;
}
@ -201,22 +209,22 @@ EmoteModule.prototype.isCacheValid = function() {
EmoteModule.prototype.loadEmoteData = async function(emoteInfo) {
const _fs = require("fs");
const emoteFile = "emote_data.json";
const file = bdConfig.dataPath + emoteFile;
const file = Config.dataPath + emoteFile;
const exists = _fs.existsSync(file);
if (exists && this.isCacheValid()) {
if (settingsCookie["fork-ps-2"]) mainCore.showToast("Loading emotes from cache.", {type: "info"});
Utils.log("Emotes", "Loading emotes from local cache.");
if (Settings["fork-ps-2"]) BdApi.showToast("Loading emotes from cache.", {type: "info"});
Utilities.log("Emotes", "Loading emotes from local cache.");
const data = await new Promise(resolve => {
_fs.readFile(file, "utf8", (err, data) => {
Utils.log("Emotes", "Emotes loaded from cache.");
Utilities.log("Emotes", "Emotes loaded from cache.");
if (err) data = {};
resolve(data);
});
});
let isValid = Utils.testJSON(data);
let isValid = Utilities.testJSON(data);
if (isValid) window.bdEmotes = JSON.parse(data);
for (const e in emoteInfo) {
@ -224,16 +232,16 @@ EmoteModule.prototype.loadEmoteData = async function(emoteInfo) {
}
if (isValid) {
if (settingsCookie["fork-ps-2"]) mainCore.showToast("Emotes successfully loaded.", {type: "success"});
if (Settings["fork-ps-2"]) BdApi.showToast("Emotes successfully loaded.", {type: "success"});
return;
}
Utils.log("Emotes", "Cache was corrupt, downloading...");
Utilities.log("Emotes", "Cache was corrupt, downloading...");
_fs.unlinkSync(file);
}
if (!settingsCookie["fork-es-3"]) return;
if (settingsCookie["fork-ps-2"]) mainCore.showToast("Downloading emotes in the background do not reload.", {type: "info"});
if (!Settings["fork-es-3"]) return;
if (Settings["fork-ps-2"]) BdApi.showToast("Downloading emotes in the background do not reload.", {type: "info"});
for (let e in emoteInfo) {
await new Promise(r => setTimeout(r, 1000));
@ -241,10 +249,10 @@ EmoteModule.prototype.loadEmoteData = async function(emoteInfo) {
window.bdEmotes[emoteInfo[e].variable] = data;
}
if (settingsCookie["fork-ps-2"]) mainCore.showToast("All emotes successfully downloaded.", {type: "success"});
if (Settings["fork-ps-2"]) BdApi.showToast("All emotes successfully downloaded.", {type: "success"});
try { _fs.writeFileSync(file, JSON.stringify(window.bdEmotes), "utf8"); }
catch (err) { Utils.err("Emotes", "Could not save emote data.", err); }
catch (err) { Utilities.err("Emotes", "Could not save emote data.", err); }
};
EmoteModule.prototype.downloadEmotes = function(emoteMeta) {
@ -254,12 +262,12 @@ EmoteModule.prototype.downloadEmotes = function(emoteMeta) {
timeout: emoteMeta.timeout ? emoteMeta.timeout : 5000
};
Utils.log("Emotes", `Downloading: ${emoteMeta.variable} (${emoteMeta.url})`);
Utilities.log("Emotes", `Downloading: ${emoteMeta.variable} (${emoteMeta.url})`);
return new Promise((resolve, reject) => {
request(options, (error, response, body) => {
if (error) {
Utils.err("Emotes", "Could not download " + emoteMeta.variable, error);
Utilities.err("Emotes", "Could not download " + emoteMeta.variable, error);
if (emoteMeta.backup) {
emoteMeta.url = emoteMeta.backup;
emoteMeta.backup = null;
@ -274,7 +282,7 @@ EmoteModule.prototype.downloadEmotes = function(emoteMeta) {
parsedData = JSON.parse(body);
}
catch (err) {
Utils.err("Emotes", "Could not download " + emoteMeta.variable, err);
Utilities.err("Emotes", "Could not download " + emoteMeta.variable, err);
if (emoteMeta.backup) {
emoteMeta.url = emoteMeta.backup;
emoteMeta.backup = null;
@ -293,7 +301,7 @@ EmoteModule.prototype.downloadEmotes = function(emoteMeta) {
parsedData[emote] = emoteMeta.getEmoteURL(parsedData[emote]);
}
resolve(parsedData);
Utils.log("Emotes", "Downloaded: " + emoteMeta.variable);
Utilities.log("Emotes", "Downloaded: " + emoteMeta.variable);
});
});
};
@ -309,7 +317,7 @@ EmoteModule.prototype.getBlacklist = function () {
var bemotes = [];
EmoteModule.prototype.autoCapitalize = function () {
if (!settingsCookie["bda-es-4"] || this.autoCapitalizeActive) return;
if (!Settings["bda-es-4"] || this.autoCapitalizeActive) return;
$("body").on("keyup.bdac change.bdac paste.bdac", $(".channelTextArea-1LDbYG textarea:first"), () => {
var text = $(".channelTextArea-1LDbYG textarea:first").val();
if (text == undefined) return;
@ -319,7 +327,7 @@ EmoteModule.prototype.autoCapitalize = function () {
if (lastWord == "danSgame") return;
var ret = this.capitalize(lastWord.toLowerCase());
if (ret !== null && ret !== undefined) {
Utils.insertText(Utils.getTextArea()[0], text.replace(lastWord, ret));
Utilities.insertText(Utilities.getTextArea()[0], text.replace(lastWord, ret));
}
}
});
@ -338,4 +346,6 @@ EmoteModule.prototype.capitalize = function (value) {
EmoteModule.prototype.disableAutoCapitalize = function() {
this.autoCapitalizeActive = false;
$("body").off(".bdac");
};
};
export default EmoteModule;

9
src/modules/modules.js Normal file
View File

@ -0,0 +1,9 @@
import BDV2 from "./bdv2";
import Utilities from "./utilities";
import BdApi from "./pluginapi";
import ClassNormalizer from "./classnormalizer";
import ContentManager from "./contentmanager";
import Emitter from "./emitter";
import DataStore from "./datastore";
export {BDV2, Utilities, BdApi, ClassNormalizer, ContentManager, Emitter, DataStore};

View File

@ -1,4 +1,9 @@
var BdApi = {
import Config from "../data/config";
import Utilities from "./utilities";
import BDV2 from "./bdv2";
import DataStore from "./datastore";
const BdApi = {
get React() { return BDV2.react; },
get ReactDOM() { return BDV2.reactDom; },
get WindowConfigFile() {
@ -14,17 +19,17 @@ var BdApi = {
};
BdApi.getAllWindowPreferences = function() {
if ((bdConfig.os !== "win32" && bdConfig.os !== "darwin") || !this.WindowConfigFile) return {}; // Tempfix until new injection on other platforms
return require(this.WindowConfigFile);
if ((Config.os !== "win32" && Config.os !== "darwin") || !this.WindowConfigFile) return {}; // Tempfix until new injection on other platforms
return __non_webpack_require__(this.WindowConfigFile);
};
BdApi.getWindowPreference = function(key) {
if ((bdConfig.os !== "win32" && bdConfig.os !== "darwin") || !this.WindowConfigFile) return undefined; // Tempfix until new injection on other platforms
if ((Config.os !== "win32" && Config.os !== "darwin") || !this.WindowConfigFile) return undefined; // Tempfix until new injection on other platforms
return this.getAllWindowPreferences()[key];
};
BdApi.setWindowPreference = function(key, value) {
if ((bdConfig.os !== "win32" && bdConfig.os !== "darwin") || !this.WindowConfigFile) return; // Tempfix until new injection on other platforms
if ((Config.os !== "win32" && Config.os !== "darwin") || !this.WindowConfigFile) return; // Tempfix until new injection on other platforms
const fs = require("fs");
const prefs = this.getAllWindowPreferences();
prefs[key] = value;
@ -36,26 +41,26 @@ BdApi.setWindowPreference = function(key, value) {
//id = id of element
//css = custom css
BdApi.injectCSS = function (id, css) {
$("head").append($("<style>", {id: Utils.escapeID(id), text: css}));
$("head").append($("<style>", {id: Utilities.escapeID(id), text: css}));
};
//Clear css/remove any element
//id = id of element
BdApi.clearCSS = function (id) {
$("#" + Utils.escapeID(id)).remove();
$("#" + Utilities.escapeID(id)).remove();
};
//Inject CSS to document head
//id = id of element
//css = custom css
BdApi.linkJS = function (id, url) {
$("head").append($("<script>", {id: Utils.escapeID(id), src: url, type: "text/javascript"}));
$("head").append($("<script>", {id: Utilities.escapeID(id), src: url, type: "text/javascript"}));
};
//Clear css/remove any element
//id = id of element
BdApi.unlinkJS = function (id) {
$("#" + Utils.escapeID(id)).remove();
$("#" + Utilities.escapeID(id)).remove();
};
//Get another plugin
@ -70,13 +75,13 @@ BdApi.getPlugin = function (name) {
var betterDiscordIPC = require("electron").ipcRenderer;
//Get ipc for reason
BdApi.getIpc = function () {
Utils.warn("Deprecation Notice", "BetterDiscord's IPC has been deprecated and may be removed in future versions.");
Utilities.warn("Deprecation Notice", "BetterDiscord's IPC has been deprecated and may be removed in future versions.");
return betterDiscordIPC;
};
//Get BetterDiscord Core
BdApi.getCore = function () {
return mainCore;
return window.mainCore;
};
/**
@ -87,7 +92,7 @@ BdApi.getCore = function () {
BdApi.alert = function (title, content) {
const ModalStack = BdApi.findModuleByProps("push", "update", "pop", "popWithKey");
const AlertModal = BdApi.findModuleByPrototypes("handleCancel", "handleSubmit", "handleMinorConfirm");
if (!ModalStack || !AlertModal) return mainCore.alert(title, content);
if (!ModalStack || !AlertModal) return window.mainCore.alert(title, content);
ModalStack.push(function(props) {
return BdApi.React.createElement(AlertModal, Object.assign({
@ -112,7 +117,7 @@ BdApi.showConfirmationModal = function (title, content, options = {}) {
const ModalStack = BdApi.findModuleByProps("push", "update", "pop", "popWithKey");
const TextElement = BdApi.findModuleByProps("Sizes", "Weights");
const ConfirmationModal = BdApi.findModule(m => m.defaultProps && m.key && m.key() == "confirm-modal");
if (!ModalStack || !ConfirmationModal || !TextElement) return mainCore.alert(title, content);
if (!ModalStack || !ConfirmationModal || !TextElement) return window.mainCore.alert(title, content);
const {onConfirm, onCancel, confirmText, cancelText, danger = false} = options;
if (typeof(content) == "string") content = TextElement({color: TextElement.Colors.PRIMARY, children: [content]});
@ -135,7 +140,7 @@ BdApi.showConfirmationModal = function (title, content, options = {}) {
//Show toast alert
BdApi.showToast = function(content, options = {}) {
mainCore.showToast(content, options);
window.mainCore.showToast(content, options);
};
// Finds module
@ -189,35 +194,35 @@ BdApi.deleteData = function(pluginName, key) {
// Patches other functions
BdApi.monkeyPatch = function(what, methodName, options) {
return Utils.monkeyPatch(what, methodName, options);
return Utilities.monkeyPatch(what, methodName, options);
};
// Event when element is removed
BdApi.onRemoved = function(node, callback) {
return Utils.onRemoved(node, callback);
return Utilities.onRemoved(node, callback);
};
// Wraps function in try..catch
BdApi.suppressErrors = function(method, message) {
return Utils.suppressErrors(method, message);
return Utilities.suppressErrors(method, message);
};
// Tests for valid JSON
BdApi.testJSON = function(data) {
return Utils.testJSON(data);
return Utilities.testJSON(data);
};
BdApi.isPluginEnabled = function(name) {
return !!pluginCookie[name];
};
// BdApi.isPluginEnabled = function(name) {
// return !!pluginCookie[name];
// };
BdApi.isThemeEnabled = function(name) {
return !!themeCookie[name];
};
// BdApi.isThemeEnabled = function(name) {
// return !!themeCookie[name];
// };
BdApi.isSettingEnabled = function(id) {
return !!settingsCookie[id];
};
// BdApi.isSettingEnabled = function(id) {
// return !!settingsCookie[id];
// };
// Gets data
BdApi.getBDData = function(key) {
@ -227,4 +232,6 @@ BdApi.getBDData = function(key) {
// Sets data
BdApi.setBDData = function(key, data) {
return DataStore.setBDData(key, data);
};
};
export default BdApi;

View File

@ -6,7 +6,7 @@ function PluginModule() {
PluginModule.prototype.loadPlugins = function () {
this.loadPluginData();
bdpluginErrors = ContentManager.loadPlugins();
const errors = ContentManager.loadPlugins();
var plugins = Object.keys(bdplugins);
for (var i = 0; i < plugins.length; i++) {
var plugin, name;
@ -19,7 +19,7 @@ PluginModule.prototype.loadPlugins = function () {
catch (err) {
pluginCookie[name] = false;
Utils.err("Plugins", name + " could not be loaded.", err);
bdpluginErrors.push({name: name, file: bdplugins[plugins[i]].filename, message: "load() could not be fired.", error: {message: err.message, stack: err.stack}});
errors.push({name: name, file: bdplugins[plugins[i]].filename, message: "load() could not be fired.", error: {message: err.message, stack: err.stack}});
continue;
}
@ -33,7 +33,7 @@ PluginModule.prototype.loadPlugins = function () {
catch (err) {
pluginCookie[name] = false;
Utils.err("Plugins", name + " could not be started.", err);
bdpluginErrors.push({name: name, file: bdplugins[plugins[i]].filename, message: "start() could not be fired.", error: {message: err.message, stack: err.stack}});
errors.push({name: name, file: bdplugins[plugins[i]].filename, message: "start() could not be fired.", error: {message: err.message, stack: err.stack}});
}
}
}
@ -41,6 +41,7 @@ PluginModule.prototype.loadPlugins = function () {
require("electron").remote.getCurrentWebContents().on("did-navigate-in-page", this.channelSwitch.bind(this));
// if (settingsCookie["fork-ps-5"]) ContentManager.watchContent("plugin");
return errors;
};
PluginModule.prototype.startPlugin = function(plugin, reload = false) {
@ -188,4 +189,6 @@ PluginModule.prototype.rawObserver = function(e) {
catch (err) { Utils.err("Plugins", "Unable to fire observer for " + plugin.getName() + ".", err); }
}
}
};
};
export default PluginModule;

View File

@ -6,7 +6,7 @@ function ThemeModule() {
ThemeModule.prototype.loadThemes = function () {
this.loadThemeData();
bdthemeErrors = ContentManager.loadThemes();
const errors = ContentManager.loadThemes();
var themes = Object.keys(bdthemes);
for (var i = 0; i < themes.length; i++) {
@ -18,6 +18,7 @@ ThemeModule.prototype.loadThemes = function () {
if (!bdthemes[theme]) delete themeCookie[theme];
}
this.saveThemeData();
return errors;
// if (settingsCookie["fork-ps-5"]) ContentManager.watchContent("theme");
};
@ -101,4 +102,6 @@ ThemeModule.prototype.loadThemeData = function() {
ThemeModule.prototype.saveThemeData = function () {
DataStore.setSettingGroup("themes", themeCookie);
};
};
export default ThemeModule;

View File

@ -1,21 +1,19 @@
function VoiceMode() {
export default class {
enable() {
$(".scroller.guild-channels ul").first().css("display", "none");
$(".scroller.guild-channels header").first().css("display", "none");
$(".app.flex-vertical, .app-2rEoOp").first().css("overflow", "hidden");
$(".chat-3bRxxu").first().css("visibility", "hidden").css("min-width", "0px");
$(".flex-vertical.channels-wrap").first().css("flex-grow", "100000");
$(".guild-header .btn.btn-hamburger").first().css("visibility", "hidden");
}
}
VoiceMode.prototype.enable = function () {
$(".scroller.guild-channels ul").first().css("display", "none");
$(".scroller.guild-channels header").first().css("display", "none");
$(".app.flex-vertical, .app-2rEoOp").first().css("overflow", "hidden");
$(".chat-3bRxxu").first().css("visibility", "hidden").css("min-width", "0px");
$(".flex-vertical.channels-wrap").first().css("flex-grow", "100000");
$(".guild-header .btn.btn-hamburger").first().css("visibility", "hidden");
};
VoiceMode.prototype.disable = function () {
$(".scroller.guild-channels ul").first().css("display", "");
$(".scroller.guild-channels header").first().css("display", "");
$(".app.flex-vertical, .app-2rEoOp").first().css("overflow", "");
$(".chat-3bRxxu").first().css("visibility", "").css("min-width", "");
$(".flex-vertical.channels-wrap").first().css("flex-grow", "");
$(".guild-header .btn.btn-hamburger").first().css("visibility", "");
};
disable() {
$(".scroller.guild-channels ul").first().css("display", "");
$(".scroller.guild-channels header").first().css("display", "");
$(".app.flex-vertical, .app-2rEoOp").first().css("overflow", "");
$(".chat-3bRxxu").first().css("visibility", "").css("min-width", "");
$(".flex-vertical.channels-wrap").first().css("flex-grow", "");
$(".guild-header .btn.btn-hamburger").first().css("visibility", "");
}
}

View File

@ -1,3 +1,8 @@
import Settings from "../../data/settingscookie";
import {BDV2, DataStore} from "modules";
import Checkbox from "../settings/checkbox";
export default class V2C_CssEditorDetached extends BDV2.reactComponent {
constructor(props) {
@ -19,7 +24,7 @@ export default class V2C_CssEditorDetached extends BDV2.reactComponent {
this.editor.setShowPrintMargin(false);
this.editor.setFontSize(14);
this.editor.on("change", () => {
if (!settingsCookie["bda-css-0"]) return;
if (!Settings["bda-css-0"]) return;
this.saveCss();
this.updateCss();
});
@ -92,7 +97,7 @@ export default class V2C_CssEditorDetached extends BDV2.reactComponent {
BDV2.react.createElement(
"ul",
{className: "checkbox-group"},
BDV2.react.createElement(V2Components.Checkbox, {id: "live-update", text: "Live Update", onChange: self.onChange, checked: settingsCookie["bda-css-0"]})
BDV2.react.createElement(Checkbox, {id: "live-update", text: "Live Update", onChange: self.onChange, checked: Settings["bda-css-0"]})
),
BDV2.react.createElement(
"div",
@ -132,8 +137,8 @@ export default class V2C_CssEditorDetached extends BDV2.reactComponent {
onChange(id, checked) {
switch (id) {
case "live-update":
settingsCookie["bda-css-0"] = checked;
mainCore.saveSettings();
Settings["bda-css-0"] = checked;
window.mainCore.saveSettings();
break;
}
}

View File

@ -1,3 +1,10 @@
import Settings from "../../data/settingscookie";
import {BDV2, DataStore} from "modules";
import EditorDetached from "./detached";
import Checkbox from "../settings/checkbox";
import SettingsTitle from "../settings/title";
export default class V2C_CssEditor extends BDV2.reactComponent {
constructor(props) {
@ -6,7 +13,7 @@ export default class V2C_CssEditor extends BDV2.reactComponent {
self.props.lines = 0;
self.setInitialState();
self.attach = self.attach.bind(self);
self.detachedEditor = BDV2.react.createElement(V2C_CssEditorDetached, {attach: self.attach});
self.detachedEditor = BDV2.react.createElement(EditorDetached, {attach: self.attach});
self.onClick = self.onClick.bind(self);
self.updateCss = self.updateCss.bind(self);
self.saveCss = self.saveCss.bind(self);
@ -27,7 +34,7 @@ export default class V2C_CssEditor extends BDV2.reactComponent {
this.editor.setShowPrintMargin(false);
this.editor.setFontSize(14);
this.editor.on("change", () => {
if (!settingsCookie["bda-css-0"]) return;
if (!Settings["bda-css-0"]) return;
this.saveCss();
this.updateCss();
});
@ -83,7 +90,7 @@ export default class V2C_CssEditor extends BDV2.reactComponent {
detached && BDV2.react.createElement(
"div",
{id: "editor-detached"},
BDV2.react.createElement(V2Components.SettingsTitle, {text: "Custom CSS Editor"}),
BDV2.react.createElement(SettingsTitle, {text: "Custom CSS Editor"}),
BDV2.react.createElement(
"h3",
null,
@ -100,7 +107,7 @@ export default class V2C_CssEditor extends BDV2.reactComponent {
!detached && BDV2.react.createElement(
"div",
null,
BDV2.react.createElement(V2Components.SettingsTitle, {text: "Custom CSS Editor"}),
BDV2.react.createElement(SettingsTitle, {text: "Custom CSS Editor"}),
BDV2.react.createElement("div", {className: "editor-wrapper"},
BDV2.react.createElement("div", {id: "bd-customcss-editor", className: "editor", ref: "editor"}, self.css)
),
@ -110,7 +117,7 @@ export default class V2C_CssEditor extends BDV2.reactComponent {
BDV2.react.createElement(
"ul",
{className: "checkbox-group"},
BDV2.react.createElement(V2Components.Checkbox, {id: "live-update", text: "Live Update", onChange: this.onChange, checked: settingsCookie["bda-css-0"]})
BDV2.react.createElement(Checkbox, {id: "live-update", text: "Live Update", onChange: this.onChange, checked: Settings["bda-css-0"]})
),
BDV2.react.createElement(
"div",
@ -172,8 +179,8 @@ export default class V2C_CssEditor extends BDV2.reactComponent {
onChange(id, checked) {
switch (id) {
case "live-update":
settingsCookie["bda-css-0"] = checked;
mainCore.saveSettings();
Settings["bda-css-0"] = checked;
window.mainCore.saveSettings();
break;
}
}

View File

@ -1,8 +1,11 @@
import Settings from "../data/settingscookie";
import {BDV2} from "modules";
export default class BDEmote extends BDV2.reactComponent {
constructor(props) {
super(props);
const isFav = quickEmoteMenu && quickEmoteMenu.favoriteEmotes && quickEmoteMenu.favoriteEmotes[this.label] ? true : false;
const isFav = window.mainCore.quickEmoteMenu && window.mainCore.quickEmoteMenu.favoriteEmotes && window.mainCore.quickEmoteMenu.favoriteEmotes[this.label] ? true : false;
this.state = {
shouldAnimate: !this.animateOnHover,
isFavorite: isFav
@ -14,7 +17,7 @@ export default class BDEmote extends BDV2.reactComponent {
}
get animateOnHover() {
return settingsCookie["fork-es-2"];
return Settings["fork-es-2"];
}
get label() {
@ -27,8 +30,8 @@ export default class BDEmote extends BDV2.reactComponent {
onMouseEnter() {
if (!this.state.shouldAnimate && this.animateOnHover) this.setState({shouldAnimate: true});
if (!this.state.isFavorite && quickEmoteMenu.favoriteEmotes[this.label]) this.setState({isFavorite: true});
else if (this.state.isFavorite && !quickEmoteMenu.favoriteEmotes[this.label]) this.setState({isFavorite: false});
if (!this.state.isFavorite && window.mainCore.quickEmoteMenu.favoriteEmotes[this.label]) this.setState({isFavorite: true});
else if (this.state.isFavorite && !window.mainCore.quickEmoteMenu.favoriteEmotes[this.label]) this.setState({isFavorite: false});
}
onMouseLeave() {
@ -67,11 +70,11 @@ export default class BDEmote extends BDV2.reactComponent {
e.preventDefault();
e.stopPropagation();
if (this.state.isFavorite) {
delete quickEmoteMenu.favoriteEmotes[this.label];
quickEmoteMenu.updateFavorites();
delete window.mainCore.quickEmoteMenu.favoriteEmotes[this.label];
window.mainCore.quickEmoteMenu.updateFavorites();
}
else {
quickEmoteMenu.favorite(this.label, this.props.url);
window.mainCore.quickEmoteMenu.favorite(this.label, this.props.url);
}
this.setState({isFavorite: !this.state.isFavorite});
}

View File

@ -1,3 +1,5 @@
import {BDV2} from "modules";
export default class BDLogo extends BDV2.reactComponent {
render() {
return BDV2.react.createElement(

View File

@ -1,3 +1,5 @@
import {BDV2} from "modules";
export default class V2C_XSvg extends BDV2.reactComponent {
constructor(props) {
super(props);

View File

@ -1,3 +1,5 @@
import {BDV2} from "modules";
export default class V2C_ReloadIcon extends BDV2.reactComponent {
constructor(props) {
super(props);

View File

@ -1,3 +1,5 @@
import {BDV2} from "modules";
export default class V2C_Layer extends BDV2.reactComponent {
constructor(props) {

View File

@ -1,3 +1,5 @@
import {BDV2} from "modules";
export default class V2C_List extends BDV2.reactComponent {
constructor(props) {
super(props);

View File

@ -1,3 +1,5 @@
import {BDV2} from "modules";
export default class V2C_ServerCard extends BDV2.reactComponent {
constructor(props) {
super(props);

View File

@ -1,3 +1,10 @@
import {BDV2} from "modules";
import SidebarView from "../sidebarview";
import Tools from "../settings/exitbutton";
import TabBar from "../settings/tabbar";
import SettingsTitle from "../settings/title";
import ServerCard from "./card";
export default class V2C_PublicServers extends BDV2.reactComponent {
constructor(props) {
@ -49,7 +56,7 @@ export default class V2C_PublicServers extends BDV2.reactComponent {
let servers = data.results.reduce((arr, server) => {
server.joined = false;
arr.push(server);
// arr.push(<V2Components.ServerCard server={server} join={self.join}/>);
// arr.push(<ServerCard server={server} join={self.join}/>);
return arr;
}, []);
@ -162,7 +169,7 @@ export default class V2C_PublicServers extends BDV2.reactComponent {
};
let guildList = this.SortedGuildStore.guildPositions;
let defaultList = this.AvatarDefaults.DEFAULT_AVATARS;
return BDV2.react.createElement(V2Components.ServerCard, {server: server, pinned: true, join: this.join, guildList: guildList, fallback: defaultList[Math.floor(Math.random() * 5)]});
return BDV2.react.createElement(ServerCard, {server: server, pinned: true, join: this.join, guildList: guildList, fallback: defaultList[Math.floor(Math.random() * 5)]});
}
get endPoint() {
@ -230,7 +237,7 @@ export default class V2C_PublicServers extends BDV2.reactComponent {
}
render() {
return BDV2.react.createElement(V2Components.SidebarView, {ref: "sbv", children: this.component});
return BDV2.react.createElement(SidebarView, {ref: "sbv", children: this.component});
}
get component() {
@ -242,7 +249,7 @@ export default class V2C_PublicServers extends BDV2.reactComponent {
component: this.content
},
tools: {
component: BDV2.react.createElement(V2Components.Tools, {key: "pt", ref: "tools", onClick: this.close})
component: BDV2.react.createElement(Tools, {key: "pt", ref: "tools", onClick: this.close})
}
};
}
@ -259,14 +266,14 @@ export default class V2C_PublicServers extends BDV2.reactComponent {
{className: "ui-tab-bar-header", style: {fontSize: "16px"}},
"Public Servers"
),
BDV2.react.createElement(V2Components.TabBar.Separator, null),
BDV2.react.createElement(TabBar.Separator, null),
this.searchInput,
BDV2.react.createElement(V2Components.TabBar.Separator, null),
BDV2.react.createElement(V2Components.TabBar.Header, {text: "Categories"}),
BDV2.react.createElement(TabBar.Separator, null),
BDV2.react.createElement(TabBar.Header, {text: "Categories"}),
this.categoryButtons.map((value, index) => {
return BDV2.react.createElement(V2Components.TabBar.Item, {id: index, onClick: this.changeCategory, key: index, text: value, selected: this.state.selectedCategory === index});
return BDV2.react.createElement(TabBar.Item, {id: index, onClick: this.changeCategory, key: index, text: value, selected: this.state.selectedCategory === index});
}),
BDV2.react.createElement(V2Components.TabBar.Separator, null),
BDV2.react.createElement(TabBar.Separator, null),
this.footer,
this.connection
)
@ -329,10 +336,10 @@ export default class V2C_PublicServers extends BDV2.reactComponent {
return [BDV2.react.createElement(
"div",
{ref: "content", key: "pc", className: "contentColumn-2hrIYH contentColumnDefault-1VQkGM content-column default"},
BDV2.react.createElement(V2Components.SettingsTitle, {text: self.state.title}),
BDV2.react.createElement(SettingsTitle, {text: self.state.title}),
self.bdServer,
self.state.servers.map((server) => {
return BDV2.react.createElement(V2Components.ServerCard, {key: server.identifier, server: server, join: self.join, guildList: guildList, fallback: defaultList[Math.floor(Math.random() * 5)]});
return BDV2.react.createElement(ServerCard, {key: server.identifier, server: server, join: self.join, guildList: guildList, fallback: defaultList[Math.floor(Math.random() * 5)]});
}),
self.state.next && BDV2.react.createElement(
"button",
@ -345,13 +352,13 @@ export default class V2C_PublicServers extends BDV2.reactComponent {
self.state.loading ? "Loading" : "Load More"
)
),
self.state.servers.length > 0 && BDV2.react.createElement(V2Components.SettingsTitle, {text: self.state.title})
self.state.servers.length > 0 && BDV2.react.createElement(SettingsTitle, {text: self.state.title})
)];
}
get notConnected() {
let self = this;
//return BDV2.react.createElement(V2Components.SettingsTitle, { text: self.state.title });
//return BDV2.react.createElement(SettingsTitle, { text: self.state.title });
return [BDV2.react.createElement(
"div",
{key: "ncc", ref: "content", className: "contentColumn-2hrIYH contentColumnDefault-1VQkGM content-column default"},
@ -402,7 +409,7 @@ export default class V2C_PublicServers extends BDV2.reactComponent {
return BDV2.react.createElement(
"span",
null,
BDV2.react.createElement(V2Components.TabBar.Separator, null),
BDV2.react.createElement(TabBar.Separator, null),
BDV2.react.createElement(
"span",
{style: {color: "#b9bbbe", fontSize: "10px", marginLeft: "10px"}},

View File

@ -1,9 +1,14 @@
import Settings from "../../data/settingscookie";
import {BDV2} from "modules";
import Layer from "../layer";
import Menu from "./menu";
export default class V2_PublicServers {
constructor() {}
get component() {
return BDV2.react.createElement(V2Components.Layer, {rootId: "pubslayerroot", id: "pubslayer", children: BDV2.react.createElement(V2C_PublicServers, {rootId: "pubslayerroot"})});
return BDV2.react.createElement(Layer, {rootId: "pubslayerroot", id: "pubslayer", children: BDV2.react.createElement(Menu, {rootId: "pubslayerroot"})});
}
get root() {
@ -37,7 +42,7 @@ export default class V2_PublicServers {
let btn = $("<div/>", {
"class": BDV2.guildClasses.listItem,
"id": "bd-pub-li",
"style": settingsCookie["bda-gs-1"] ? "" : "display: none;"
"style": Settings["bda-gs-1"] ? "" : "display: none;"
}).append($("<div/>", {
"class": "wrapper-25eVIn " + BDV2.guildClasses.circleButtonMask,
"text": "public",

View File

@ -1,3 +1,5 @@
import {BDV2} from "modules";
export default class V2C_Scroller extends BDV2.reactComponent {
constructor(props) {

View File

@ -1,3 +1,5 @@
import {BDV2} from "modules";
export default class V2C_Checkbox extends BDV2.reactComponent {
constructor(props) {
super(props);

View File

@ -1,3 +1,5 @@
import {BDV2} from "modules";
export default class V2C_ContentColumn extends BDV2.reactComponent {
constructor(props) {
super(props);

View File

@ -1,3 +1,6 @@
import {BDV2} from "modules";
import CloseButton from "../icons/close";
export default class V2C_Tools extends BDV2.reactComponent {
constructor(props) {
@ -11,7 +14,7 @@ export default class V2C_Tools extends BDV2.reactComponent {
BDV2.react.createElement("div", {className: "container-1sFeqf"},
BDV2.react.createElement("div",
{className: "btn-close closeButton-1tv5uR", onClick: this.onClick},
BDV2.react.createElement(V2Components.XSvg, null)
BDV2.react.createElement(CloseButton, null)
),
BDV2.react.createElement(
"div",

View File

@ -1,3 +1,8 @@
import Settings from "../../data/settingscookie";
import {BDV2} from "modules";
import SettingsTitle from "./title";
import Switch from "./switch";
export default class V2C_SettingsPanel extends BDV2.reactComponent {
constructor(props) {
@ -9,10 +14,10 @@ export default class V2C_SettingsPanel extends BDV2.reactComponent {
return BDV2.react.createElement(
"div",
{className: "contentColumn-2hrIYH contentColumnDefault-1VQkGM content-column default"},
BDV2.react.createElement(V2Components.SettingsTitle, {text: this.props.title}),
BDV2.react.createElement(SettingsTitle, {text: this.props.title}),
this.props.button && BDV2.react.createElement("button", {key: "title-button", className: "bd-pfbtn", onClick: this.props.button.onClick}, this.props.button.title),
settings.map(setting => {
return BDV2.react.createElement(V2Components.Switch, {id: setting.id, key: setting.id, data: setting, checked: settingsCookie[setting.id], onChange: (id, checked) => {
return BDV2.react.createElement(Switch, {id: setting.id, key: setting.id, data: setting, checked: Settings[setting.id], onChange: (id, checked) => {
this.props.onChange(id, checked);
}});
})

View File

@ -1,3 +1,8 @@
import Settings from "../../data/settingscookie";
import {BDV2, Utilities} from "modules";
import CloseButton from "../icons/close";
import ReloadIcon from "../icons/reload";
export default class V2C_PluginCard extends BDV2.reactComponent {
constructor(props) {
@ -40,7 +45,7 @@ export default class V2C_PluginCard extends BDV2.reactComponent {
this.refs.settingspanel.appendChild(this.settingsPanel);
}
if (!settingsCookie["fork-ps-3"]) return;
if (!Settings["fork-ps-3"]) return;
var isHidden = (container, element) => {
let cTop = container.scrollTop;
@ -63,7 +68,7 @@ export default class V2C_PluginCard extends BDV2.reactComponent {
reload() {
const plugin = this.props.plugin.getName();
pluginModule.reloadPlugin(plugin);
window.mainCore.pluginModule.reloadPlugin(plugin);
this.props.plugin = bdplugins[plugin].plugin;
this.onReload(this.props.plugin.getName());
}
@ -84,14 +89,14 @@ export default class V2C_PluginCard extends BDV2.reactComponent {
if (this.state.settings) {
try { self.settingsPanel = plugin.getSettingsPanel(); }
catch (err) { Utils.err("Plugins", "Unable to get settings panel for " + plugin.getName() + ".", err); }
catch (err) { Utilities.err("Plugins", "Unable to get settings panel for " + plugin.getName() + ".", err); }
return BDV2.react.createElement("li", {className: "settings-open ui-switch-item"},
BDV2.react.createElement("div", {style: {"float": "right", "cursor": "pointer"}, onClick: () => {
this.refs.settingspanel.innerHTML = "";
self.setState({settings: false});
}},
BDV2.react.createElement(V2Components.XSvg, null)
BDV2.react.createElement(CloseButton, null)
),
typeof self.settingsPanel === "object" && BDV2.react.createElement("div", {id: `plugin-settings-${name}`, className: "plugin-settings", ref: "settingspanel"}),
typeof self.settingsPanel !== "object" && BDV2.react.createElement("div", {id: `plugin-settings-${name}`, className: "plugin-settings", ref: "settingspanel", dangerouslySetInnerHTML: {__html: self.settingsPanel}})
@ -108,7 +113,7 @@ export default class V2C_PluginCard extends BDV2.reactComponent {
BDV2.react.createElement("span", {className: "bda-author"}, author)
),
BDV2.react.createElement("div", {className: "bda-controls"},
!settingsCookie["fork-ps-5"] && BDV2.react.createElement(V2Components.TooltipWrap(V2Components.ReloadIcon, {color: "black", side: "top", text: "Reload"}), {className: "bd-reload-card", onClick: this.reload}),
!Settings["fork-ps-5"] && BDV2.react.createElement(ReloadIcon, {className: "bd-reload-card", onClick: this.reload}),
BDV2.react.createElement("label", {className: "ui-switch-wrapper ui-flex-child", style: {flex: "0 0 auto"}},
BDV2.react.createElement("input", {checked: this.state.checked, onChange: this.onChange, className: "ui-switch-checkbox", type: "checkbox"}),
BDV2.react.createElement("div", {className: this.state.checked ? "ui-switch checked" : "ui-switch"})
@ -131,7 +136,7 @@ export default class V2C_PluginCard extends BDV2.reactComponent {
onChange() {
this.setState({checked: !this.state.checked});
pluginModule.togglePlugin(this.props.plugin.getName());
window.mainCore.pluginModule.togglePlugin(this.props.plugin.getName());
}
showSettings() {

View File

@ -1,3 +1,6 @@
import {BDV2} from "modules";
import SettingsGroup from "./settingsgroup";
export default class V2C_SectionedSettingsPanel extends BDV2.reactComponent {
constructor(props) {
@ -8,7 +11,7 @@ export default class V2C_SectionedSettingsPanel extends BDV2.reactComponent {
return BDV2.react.createElement(
"div", {className: "contentColumn-2hrIYH contentColumnDefault-1VQkGM content-column default"},
this.props.sections.map(section => {
return BDV2.react.createElement(V2Components.SettingsGroup, Object.assign({}, section, this.props.onChange));
return BDV2.react.createElement(SettingsGroup, Object.assign({}, section, this.props.onChange));
})
);
}

View File

@ -1,3 +1,19 @@
import SettingsInfo from "../../data/settings";
import Settings from "../../data/settingscookie";
import {BDV2, Utilities, BdApi, ClassNormalizer, ContentManager, Emitter} from "modules";
import Sidebar from "./sidebar";
import Scroller from "../scroller";
import List from "../list";
import ContentColumn from "./contentcolumn";
import SectionedSettingsPanel from "./sectionedsettings";
import Tools from "./exitbutton";
import SettingsPanel from "./panel";
import PluginCard from "./plugincard";
import ThemeCard from "./themecard";
import ReloadIcon from "../icons/reload";
import CssEditor from "../customcss/editor";
export default class V2_SettingsPanel {
constructor() {
@ -5,7 +21,7 @@ export default class V2_SettingsPanel {
self.sideBarOnClick = self.sideBarOnClick.bind(self);
self.onChange = self.onChange.bind(self);
self.updateSettings = this.updateSettings.bind(self);
self.sidebar = new V2_SettingsPanel_Sidebar(self.sideBarOnClick);
self.sidebar = new Sidebar(self.sideBarOnClick);
}
get root() {
@ -25,7 +41,7 @@ export default class V2_SettingsPanel {
});
$(".layer-3QrUeG .standardSidebarView-3F1I7i, .layer-3QrUeG .ui-standard-sidebar-view").append(root);
Utils.onRemoved(root[0], () => {
Utilities.onRemoved(root[0], () => {
BDV2.reactDom.unmountComponentAtNode(root[0]);
});
return true;
@ -42,8 +58,8 @@ export default class V2_SettingsPanel {
return this.getSettings("emote");
}
getSettings(category) {
return Object.keys(settings).reduce((arr, key) => {
let setting = settings[key];
return Object.keys(SettingsInfo).reduce((arr, key) => {
let setting = SettingsInfo[key];
if (setting.cat === category && setting.implemented && !setting.hidden) {
setting.text = key;
arr.push(setting);
@ -82,7 +98,7 @@ export default class V2_SettingsPanel {
}
updateSettings(id, enabled) {
settingsCookie[id] = enabled;
Settings[id] = enabled;
if (id == "bda-es-0") {
if (enabled) $("#twitchcord-button-container").show();
@ -110,8 +126,8 @@ export default class V2_SettingsPanel {
}
if (id == "bda-gs-4") {
if (enabled) voiceMode.enable();
else voiceMode.disable();
if (enabled) window.mainCore.voiceMode.enable();
else window.mainCore.voiceMode.disable();
}
if (id == "bda-gs-5") {
@ -119,16 +135,16 @@ export default class V2_SettingsPanel {
else $("#app-mount").removeClass("bda-dark");
}
if (enabled && id == "bda-gs-6") mainCore.inject24Hour();
if (enabled && id == "bda-gs-6") window.mainCore.inject24Hour();
if (id == "bda-gs-7") {
if (enabled) mainCore.injectColoredText();
else mainCore.removeColoredText();
if (enabled) window.mainCore.injectColoredText();
else window.mainCore.removeColoredText();
}
if (id == "bda-es-4") {
if (enabled) emoteModule.autoCapitalize();
else emoteModule.disableAutoCapitalize();
if (enabled) window.mainCore.emoteModule.autoCapitalize();
else window.mainCore.emoteModule.disableAutoCapitalize();
}
if (id == "fork-ps-4") {
@ -160,34 +176,34 @@ export default class V2_SettingsPanel {
if (id == "bda-gs-8") {
if (enabled) dMode.enable(settingsCookie["fork-dm-1"]);
else dMode.disable();
if (enabled) window.mainCore.dMode.enable(Settings["fork-dm-1"]);
else window.mainCore.dMode.disable();
}
mainCore.saveSettings();
window.mainCore.saveSettings();
}
initializeSettings() {
if (settingsCookie["bda-es-0"]) $("#twitchcord-button-container").show();
// if (settingsCookie["bda-gs-b"]) $("body").addClass("bd-blue");
if (settingsCookie["bda-gs-2"]) $("body").addClass("bd-minimal");
if (settingsCookie["bda-gs-3"]) $("body").addClass("bd-minimal-chan");
if (settingsCookie["bda-gs-1"]) $("#bd-pub-li").show();
if (settingsCookie["bda-gs-4"]) voiceMode.enable();
if (settingsCookie["bda-gs-5"]) $("#app-mount").addClass("bda-dark");
if (settingsCookie["bda-gs-6"]) mainCore.inject24Hour();
if (settingsCookie["bda-gs-7"]) mainCore.injectColoredText();
if (settingsCookie["bda-es-4"]) emoteModule.autoCapitalize();
if (settingsCookie["fork-ps-4"]) ClassNormalizer.start();
if (Settings["bda-es-0"]) $("#twitchcord-button-container").show();
// if (Settings["bda-gs-b"]) $("body").addClass("bd-blue");
if (Settings["bda-gs-2"]) $("body").addClass("bd-minimal");
if (Settings["bda-gs-3"]) $("body").addClass("bd-minimal-chan");
if (Settings["bda-gs-1"]) $("#bd-pub-li").show();
if (Settings["bda-gs-4"]) window.mainCore.voiceMode.enable();
if (Settings["bda-gs-5"]) $("#app-mount").addClass("bda-dark");
if (Settings["bda-gs-6"]) window.mainCore.inject24Hour();
if (Settings["bda-gs-7"]) window.mainCore.injectColoredText();
if (Settings["bda-es-4"]) window.mainCore.emoteModule.autoCapitalize();
if (Settings["fork-ps-4"]) ClassNormalizer.start();
if (settingsCookie["fork-ps-5"]) {
if (Settings["fork-ps-5"]) {
ContentManager.watchContent("plugin");
ContentManager.watchContent("theme");
}
if (settingsCookie["bda-gs-8"]) dMode.enable(settingsCookie["fork-dm-1"]);
if (Settings["bda-gs-8"]) window.mainCore.dMode.enable(Settings["fork-dm-1"]);
mainCore.saveSettings();
window.mainCore.saveSettings();
}
renderSidebar() {
@ -201,25 +217,25 @@ export default class V2_SettingsPanel {
}
get coreComponent() {
return BDV2.react.createElement(V2Components.Scroller, {contentColumn: true, fade: true, dark: true, children: [
BDV2.react.createElement(V2Components.SectionedSettingsPanel, {key: "cspanel", onChange: this.onChange, sections: this.coreSettings}),
BDV2.react.createElement(V2Components.Tools, {key: "tools"})
return BDV2.react.createElement(Scroller, {contentColumn: true, fade: true, dark: true, children: [
BDV2.react.createElement(SectionedSettingsPanel, {key: "cspanel", onChange: this.onChange, sections: this.coreSettings}),
BDV2.react.createElement(Tools, {key: "tools"})
]});
}
get emoteComponent() {
return BDV2.react.createElement(V2Components.Scroller, {
return BDV2.react.createElement(Scroller, {
contentColumn: true, fade: true, dark: true, children: [
BDV2.react.createElement(V2Components.SettingsPanel, {key: "espanel", title: "Emote Settings", onChange: this.onChange, settings: this.emoteSettings, button: {
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(); }
onClick: () => { window.mainCore.emoteModule.clearEmoteData(); window.mainCore.emoteModule.init(); window.mainCore.quickEmoteMenu.init(); }
}}),
BDV2.react.createElement(V2Components.Tools, {key: "tools"})
BDV2.react.createElement(Tools, {key: "tools"})
]});
}
get customCssComponent() {
return BDV2.react.createElement(V2Components.Scroller, {contentColumn: true, fade: true, dark: true, children: [BDV2.react.createElement(V2Components.CssEditor, {key: "csseditor"}), BDV2.react.createElement(V2Components.Tools, {key: "tools"})]});
return BDV2.react.createElement(Scroller, {contentColumn: true, fade: true, dark: true, children: [BDV2.react.createElement(CssEditor, {key: "csseditor"}), BDV2.react.createElement(Tools, {key: "tools"})]});
}
contentComponent(type) {
@ -233,15 +249,15 @@ export default class V2_SettingsPanel {
}
componentDidMount() {
BDEvents.on(`${prefix}-reloaded`, this.onChange);
BDEvents.on(`${prefix}-loaded`, this.onChange);
BDEvents.on(`${prefix}-unloaded`, this.onChange);
Emitter.on(`${prefix}-reloaded`, this.onChange);
Emitter.on(`${prefix}-loaded`, this.onChange);
Emitter.on(`${prefix}-unloaded`, this.onChange);
}
componentWillUnmount() {
BDEvents.off(`${prefix}-reloaded`, this.onChange);
BDEvents.off(`${prefix}-loaded`, this.onChange);
BDEvents.off(`${prefix}-unloaded`, this.onChange);
Emitter.off(`${prefix}-reloaded`, this.onChange);
Emitter.off(`${prefix}-loaded`, this.onChange);
Emitter.off(`${prefix}-unloaded`, this.onChange);
}
onChange() {
@ -255,30 +271,30 @@ export default class V2_SettingsPanel {
get pluginsComponent() {
let plugins = Object.keys(bdplugins).sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase())).reduce((arr, key) => {
arr.push(BDV2.react.createElement(V2Components.PluginCard, {key: key, plugin: bdplugins[key].plugin}));return arr;
arr.push(BDV2.react.createElement(PluginCard, {key: key, plugin: bdplugins[key].plugin}));return arr;
}, []);
let list = BDV2.react.createElement(V2Components.List, {key: "plugin-list", className: "bda-slist", children: plugins});
let refreshIcon = !settingsCookie["fork-ps-5"] && BDV2.react.createElement(V2Components.TooltipWrap(V2Components.ReloadIcon, {color: "black", side: "top", text: "Reload Plugin List"}), {className: "bd-reload-header", size: "18px", onClick: async () => {
pluginModule.updatePluginList();
let list = BDV2.react.createElement(List, {key: "plugin-list", className: "bda-slist", children: plugins});
let refreshIcon = !Settings["fork-ps-5"] && BDV2.react.createElement(ReloadIcon, {className: "bd-reload-header", size: "18px", onClick: async () => {
window.mainCore.pluginModule.updatePluginList();
this.sideBarOnClick("plugins");
}});
let pfBtn = BDV2.react.createElement("button", {key: "folder-button", className: "bd-pfbtn", onClick: () => { require("electron").shell.openItem(ContentManager.pluginsFolder); }}, "Open Plugin Folder");
let contentColumn = BDV2.react.createElement(V2Components.ContentColumn, {key: "pcolumn", title: "Plugins", children: [refreshIcon, pfBtn, list]});
return BDV2.react.createElement(V2Components.Scroller, {contentColumn: true, fade: true, dark: true, children: [contentColumn, BDV2.react.createElement(V2Components.Tools, {key: "tools"})]});
let contentColumn = BDV2.react.createElement(ContentColumn, {key: "pcolumn", title: "Plugins", children: [refreshIcon, pfBtn, list]});
return BDV2.react.createElement(Scroller, {contentColumn: true, fade: true, dark: true, children: [contentColumn, BDV2.react.createElement(Tools, {key: "tools"})]});
}
get themesComponent() {
let themes = Object.keys(bdthemes).sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase())).reduce((arr, key) => {
arr.push(BDV2.react.createElement(V2Components.ThemeCard, {key: key, theme: bdthemes[key]}));return arr;
arr.push(BDV2.react.createElement(ThemeCard, {key: key, theme: bdthemes[key]}));return arr;
}, []);
let list = BDV2.react.createElement(V2Components.List, {key: "theme-list", className: "bda-slist", children: themes});
let refreshIcon = !settingsCookie["fork-ps-5"] && BDV2.react.createElement(V2Components.TooltipWrap(V2Components.ReloadIcon, {color: "black", side: "top", text: "Reload Theme List"}), {className: "bd-reload-header", size: "18px", onClick: async () => {
themeModule.updateThemeList();
let list = BDV2.react.createElement(List, {key: "theme-list", className: "bda-slist", children: themes});
let refreshIcon = !Settings["fork-ps-5"] && BDV2.react.createElement(ReloadIcon, {className: "bd-reload-header", size: "18px", onClick: async () => {
window.mainCore.themeModule.updateThemeList();
this.sideBarOnClick("themes");
}});
let tfBtn = BDV2.react.createElement("button", {key: "folder-button", className: "bd-pfbtn", onClick: () => { require("electron").shell.openItem(ContentManager.themesFolder); }}, "Open Theme Folder");
let contentColumn = BDV2.react.createElement(V2Components.ContentColumn, {key: "tcolumn", title: "Themes", children: [refreshIcon, tfBtn, list]});
return BDV2.react.createElement(V2Components.Scroller, {contentColumn: true, fade: true, dark: true, children: [contentColumn, BDV2.react.createElement(V2Components.Tools, {key: "tools"})]});
let contentColumn = BDV2.react.createElement(ContentColumn, {key: "tcolumn", title: "Themes", children: [refreshIcon, tfBtn, list]});
return BDV2.react.createElement(Scroller, {contentColumn: true, fade: true, dark: true, children: [contentColumn, BDV2.react.createElement(Tools, {key: "tools"})]});
}
renderCoreSettings() {

View File

@ -1,3 +1,8 @@
import Settings from "../../data/settingscookie";
import {BDV2} from "modules";
import SettingsTitle from "./title";
import Switch from "./switch";
export default class V2C_SettingsGroup extends BDV2.reactComponent {
constructor(props) {
@ -7,10 +12,10 @@ export default class V2C_SettingsGroup extends BDV2.reactComponent {
render() {
const {title, settings, button} = this.props;
const buttonComponent = button ? BDV2.react.createElement("button", {key: "title-button", className: "bd-pfbtn", onClick: button.onClick}, button.title) : null;
return [BDV2.react.createElement(V2Components.SettingsTitle, {text: title}),
return [BDV2.react.createElement(SettingsTitle, {text: title}),
buttonComponent,
settings.map(setting => {
return BDV2.react.createElement(V2Components.Switch, {id: setting.id, key: setting.id, data: setting, checked: settingsCookie[setting.id], onChange: (id, checked) => {
return BDV2.react.createElement(Switch, {id: setting.id, key: setting.id, data: setting, checked: Settings[setting.id], onChange: (id, checked) => {
this.props.onChange(id, checked);
}});
})];

View File

@ -1,3 +1,8 @@
import Config from "../../data/config";
import {BDV2, Utilities} from "modules";
import SideBar from "./sidebarmenu";
export default class V2_SettingsPanel_Sidebar {
constructor(onClick) {
@ -12,11 +17,11 @@ export default class V2_SettingsPanel_Sidebar {
return BDV2.react.createElement(
"span",
null,
BDV2.react.createElement(V2Components.SideBar, {onClick: this.onClick, headerText: "Bandaged BD", items: this.items}),
BDV2.react.createElement(SideBar, {onClick: this.onClick, headerText: "Bandaged BD", items: this.items}),
BDV2.react.createElement(
"div",
{style: {fontSize: "12px", fontWeight: "600", color: "#72767d", padding: "2px 10px"}},
`BD v${bdConfig.version} by `,
`BD v${Config.version} by `,
BDV2.react.createElement(
"a",
{href: "https://github.com/Jiiks/", target: "_blank"},
@ -26,7 +31,7 @@ export default class V2_SettingsPanel_Sidebar {
BDV2.react.createElement(
"div",
{style: {fontSize: "12px", fontWeight: "600", color: "#72767d", padding: "2px 10px"}},
`BBD v${bbdVersion} by `,
`BBD v${Config.bbdVersion} by `,
BDV2.react.createElement(
"a",
{href: "https://github.com/rauenzi/", target: "_blank"},
@ -59,7 +64,7 @@ export default class V2_SettingsPanel_Sidebar {
return;
}
BDV2.reactDom.render(this.component, root);
Utils.onRemoved(root, () => {
Utilities.onRemoved(root, () => {
BDV2.reactDom.unmountComponentAtNode(root);
});
}

View File

@ -1,3 +1,6 @@
import {BDV2} from "modules";
import TabBar from "./tabbar";
export default class V2C_SideBar extends BDV2.reactComponent {
constructor(props) {
@ -38,11 +41,11 @@ export default class V2C_SideBar extends BDV2.reactComponent {
return BDV2.react.createElement(
"div",
null,
BDV2.react.createElement(V2Components.TabBar.Separator, null),
BDV2.react.createElement(V2Components.TabBar.Header, {text: headerText}),
BDV2.react.createElement(TabBar.Separator, null),
BDV2.react.createElement(TabBar.Header, {text: headerText}),
items.map(item => {
let {id, text} = item;
return BDV2.react.createElement(V2Components.TabBar.Item, {key: id, selected: selected === id, text: text, id: id, onClick: self.onClick});
return BDV2.react.createElement(TabBar.Item, {key: id, selected: selected === id, text: text, id: id, onClick: self.onClick});
})
);
}

View File

@ -1,3 +1,5 @@
import {BDV2} from "modules";
export default class V2C_Switch extends BDV2.reactComponent {
constructor(props) {

View File

@ -1,3 +1,5 @@
import {BDV2} from "modules";
class V2C_TabBarItem extends BDV2.reactComponent {
constructor(props) {

View File

@ -1,3 +1,7 @@
import Settings from "../../data/settingscookie";
import {BDV2} from "modules";
import ReloadIcon from "../icons/reload";
export default class V2C_ThemeCard extends BDV2.reactComponent {
constructor(props) {
@ -29,9 +33,9 @@ export default class V2C_ThemeCard extends BDV2.reactComponent {
reload() {
const theme = this.props.theme.name;
const error = themeModule.reloadTheme(theme);
if (error) mainCore.showToast(`Could not reload ${bdthemes[theme].name}. Check console for details.`, {type: "error"});
else mainCore.showToast(`${bdthemes[theme].name} v${bdthemes[theme].version} has been reloaded.`, {type: "success"});
const error = window.mainCore.themeModule.reloadTheme(theme);
if (error) window.mainCore.showToast(`Could not reload ${bdthemes[theme].name}. Check console for details.`, {type: "error"});
else window.mainCore.showToast(`${bdthemes[theme].name} v${bdthemes[theme].version} has been reloaded.`, {type: "success"});
// this.setState(this.state);
this.props.theme = bdthemes[theme];
this.onReload(this.props.theme.name);
@ -56,7 +60,7 @@ export default class V2C_ThemeCard extends BDV2.reactComponent {
BDV2.react.createElement("span", {className: "bda-author"}, author)
),
BDV2.react.createElement("div", {className: "bda-controls"},
!settingsCookie["fork-ps-5"] && BDV2.react.createElement(V2Components.TooltipWrap(V2Components.ReloadIcon, {color: "black", side: "top", text: "Reload"}), {className: "bd-reload-card", onClick: this.reload}),
!Settings["fork-ps-5"] && BDV2.react.createElement(ReloadIcon, {className: "bd-reload-card", onClick: this.reload}),
BDV2.react.createElement("label", {className: "ui-switch-wrapper ui-flex-child", style: {flex: "0 0 auto"}},
BDV2.react.createElement("input", {checked: this.state.checked, onChange: this.onChange, className: "ui-switch-checkbox", type: "checkbox"}),
BDV2.react.createElement("div", {className: this.state.checked ? "ui-switch checked" : "ui-switch"})
@ -78,6 +82,6 @@ export default class V2C_ThemeCard extends BDV2.reactComponent {
onChange() {
this.setState({checked: !this.state.checked});
themeModule.toggleTheme(this.props.theme.name);
window.mainCore.themeModule.toggleTheme(this.props.theme.name);
}
}

View File

@ -1,3 +1,5 @@
import {BDV2} from "modules";
export default class V2C_SettingsTitle extends BDV2.reactComponent {
constructor(props) {
super(props);

View File

@ -1,3 +1,6 @@
import {BDV2} from "modules";
import Scroller from "./scroller";
export default class V2C_SidebarView extends BDV2.reactComponent {
constructor(props) {
@ -12,7 +15,7 @@ export default class V2C_SidebarView extends BDV2.reactComponent {
BDV2.react.createElement(
"div",
{className: "sidebarRegion-VFTUkN sidebar-region"},
BDV2.react.createElement(V2Components.Scroller, {key: "sidebarScroller", ref: "sidebarScroller", sidebar: true, fade: sidebar.fade || true, dark: sidebar.dark || true, children: sidebar.component})
BDV2.react.createElement(Scroller, {key: "sidebarScroller", ref: "sidebarScroller", sidebar: true, fade: sidebar.fade || true, dark: sidebar.dark || true, children: sidebar.component})
),
BDV2.react.createElement("div", {className: "contentRegion-3nDuYy content-region"},
BDV2.react.createElement("div", {className: "contentTransitionWrap-3hqOEW content-transition-wrap"},

View File

@ -1,61 +0,0 @@
export default function TooltipWrap(Component, options) {
const {style = "black", side = "top", text = ""} = options;
const id = BDV2.KeyGenerator();
return class extends BDV2.reactComponent {
constructor(props) {
super(props);
this.onMouseEnter = this.onMouseEnter.bind(this);
this.onMouseLeave = this.onMouseLeave.bind(this);
}
componentDidMount() {
this.node = BDV2.reactDom.findDOMNode(this);
this.node.addEventListener("mouseenter", this.onMouseEnter);
this.node.addEventListener("mouseleave", this.onMouseLeave);
}
componentWillUnmount() {
this.node.removeEventListener("mouseenter", this.onMouseEnter);
this.node.removeEventListener("mouseleave", this.onMouseLeave);
}
onMouseEnter() {
const {left, top, width, height} = this.node.getBoundingClientRect();
BDV2.Tooltips.show(id, {
position: side,
text: text,
color: style,
targetWidth: width,
targetHeight: height,
windowWidth: Utils.screenWidth,
windowHeight: Utils.screenHeight,
x: left,
y: top
});
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
const nodes = Array.from(mutation.removedNodes);
const directMatch = nodes.indexOf(this.node) > -1;
const parentMatch = nodes.some(parent => parent.contains(this.node));
if (directMatch || parentMatch) {
this.onMouseLeave();
observer.disconnect();
}
});
});
observer.observe(document.body, {subtree: true, childList: true});
}
onMouseLeave() {
BDV2.Tooltips.hide(id);
}
render() {
return BDV2.react.createElement(Component, this.props);
}
};
}

4
src/ui/ui.js Normal file
View File

@ -0,0 +1,4 @@
import SettingsPanel from "./settings/settings";
import PublicServers from "./publicservers/publicservers";
export {SettingsPanel, PublicServers};

32
webpack.config.js Normal file
View File

@ -0,0 +1,32 @@
const path = require("path");
const webpack = require("webpack");
module.exports = env => {
return {
mode: "development",
target: "node",
devtool: "none",
entry: "./src/index.js",
output: {
filename: "release.js",
path: path.resolve(__dirname, "js"),
library: "Core",
libraryTarget: "var",
libraryExport: "default"
},
externals: {
electron: `require("electron")`,
fs: `require("fs")`,
path: `require("path")`,
request: `require("request")`
},
resolve: {
extensions: [".js"],
modules: [
path.resolve("src", "modules"),
path.resolve("src", "structs"),
path.resolve("src", "ui")
]
}
};
};