From 4784b13c8621251d31938e3e4ead82fdec1045d3 Mon Sep 17 00:00:00 2001 From: Zack Rauen Date: Tue, 21 Aug 2018 01:50:54 -0400 Subject: [PATCH] proper color mixing, support light theme --- client/src/builtin/ColoredText.js | 12 ++++++++---- client/src/modules/webpackmodules.js | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/client/src/builtin/ColoredText.js b/client/src/builtin/ColoredText.js index 82423661..ff1e8aa0 100644 --- a/client/src/builtin/ColoredText.js +++ b/client/src/builtin/ColoredText.js @@ -11,7 +11,7 @@ import BuiltinModule from './BuiltinModule'; import { Utils } from 'common'; -import { Settings, Patcher, MonkeyPatch, WebpackModules, ReactComponents } from 'modules'; +import { Settings, Patcher, MonkeyPatch, WebpackModules, ReactComponents, DiscordApi } from 'modules'; export default new class ColoredText extends BuiltinModule { @@ -34,7 +34,7 @@ export default new class ColoredText extends BuiltinModule { } get intensity() { - return 1 - this.intensitySetting.value / 100; + return 100 - this.intensitySetting.value; } _intensityUpdated() { @@ -50,10 +50,14 @@ export default new class ColoredText extends BuiltinModule { } injectColoredText(thisObject, args, returnValue) { - const ColorShader = WebpackModules.getModuleByName('ColorShader'); + const TinyColor = WebpackModules.getModuleByName('TinyColor'); const markup = Utils.findInReactTree(returnValue, m => m && m.props && m.props.className && m.props.className.includes('da-markup')); const roleColor = thisObject.props.message.colorString; - if (markup && roleColor) markup.props.style = {color: ColorShader.lighten(roleColor, this.intensity)}; + if (markup && roleColor) markup.props.style = {color: TinyColor.mix(roleColor, this.defaultColor, this.intensity)}; + } + + get defaultColor() { + return DiscordApi.UserSettings.theme == 'light' ? '#747f8d' : '#dcddde'; } disabled(e) { diff --git a/client/src/modules/webpackmodules.js b/client/src/modules/webpackmodules.js index 1867805e..ff87b9a4 100644 --- a/client/src/modules/webpackmodules.js +++ b/client/src/modules/webpackmodules.js @@ -74,6 +74,7 @@ const KnownModules = { Permissions: Filters.byProperties(['getHighestRole']), ColorConverter: Filters.byProperties(['hex2int']), ColorShader: Filters.byProperties(['darken']), + TinyColor: Filters.byPrototypeFields(['toRgb']), ClassResolver: Filters.byProperties(['getClass']), ButtonData: Filters.byProperties(['ButtonSizes']), IconNames: Filters.byProperties(['IconNames']),