From c4f992fb1a6cb360d11a02a9c51217d60f03edf6 Mon Sep 17 00:00:00 2001 From: Mirco Wittrien Date: Thu, 20 Oct 2022 12:44:07 +0200 Subject: [PATCH] stuff --- Library/_res/0BDFDB.data.json | 1 + .../TimedLightDarkMode.plugin.js | 108 +++++++++--------- 2 files changed, 53 insertions(+), 56 deletions(-) diff --git a/Library/_res/0BDFDB.data.json b/Library/_res/0BDFDB.data.json index 1098269c53..8cea97e615 100644 --- a/Library/_res/0BDFDB.data.json +++ b/Library/_res/0BDFDB.data.json @@ -420,6 +420,7 @@ "UserPopoutInfo": {"strings": [".hasCustomStatus", ".premiumGuildSince", "openPremiumSettings"]}, "UserProfileModalHeader": {"strings": [".friendToken", ".additionalActionsIcon", "onMessage"]}, "UserSummaryItem": {"protos": ["renderMoreUsers", "renderUsers", "renderIcon"]}, + "UserSettingsAppearance": {"protos": ["renderTheme", "renderDisplayMode", "renderMessageGroupSpacingSlider"]}, "UserThemedBanner": {"strings": [".showPremiumBadgeUpsell", ".isPremiumAtLeast", ".SETTINGS"]}, "UserThemedPopoutBody": {"strings": [".customStatusActivity", ".canDM", ".hidePersonalInformation"]}, "UserThemedPopoutHeader": {"strings": [".avatarPositionPremiumNoBanner", "syncProfileThemeWithUserTheme"]}, diff --git a/Plugins/TimedLightDarkMode/TimedLightDarkMode.plugin.js b/Plugins/TimedLightDarkMode/TimedLightDarkMode.plugin.js index 4c25b67cc0..00d644a683 100644 --- a/Plugins/TimedLightDarkMode/TimedLightDarkMode.plugin.js +++ b/Plugins/TimedLightDarkMode/TimedLightDarkMode.plugin.js @@ -2,7 +2,7 @@ * @name TimedLightDarkMode * @author DevilBro * @authorId 278543574059057154 - * @version 1.1.3 + * @version 1.1.4 * @description Adds a Time Slider to the Appearance Settings * @invite Jx3TjNS * @donate https://www.paypal.me/MircoWittrien @@ -57,12 +57,11 @@ module.exports = (_ => { } } : (([Plugin, BDFDB]) => { var checkInterval, changeTimeout, disableChanging; - var settings = {}, values = {}; return class TimedLightDarkMode extends Plugin { onLoad () { this.defaults = { - settings: { + general: { running: {value: true} }, values: { @@ -71,16 +70,16 @@ module.exports = (_ => { } }; - this.patchedModules = { - after: { - UserSettingsAppearance: "render" - } + this.modulePatches = { + after: [ + "UserSettingsAppearance" + ] }; } onStart () { BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.AppearanceSettingsUtils, "updateTheme", {after: e => { - if (settings.running) { + if (this.settings.general.running) { BDFDB.TimeUtils.clear(changeTimeout); disableChanging = true; changeTimeout = BDFDB.TimeUtils.timeout(_ => { @@ -102,52 +101,49 @@ module.exports = (_ => { processUserSettingsAppearance (e) { let formItem = BDFDB.ReactUtils.findChild(e.returnvalue, {name: "FormItem", props: [["title", BDFDB.LanguageUtils.LanguageStrings.THEME]]}); - if (formItem && formItem.props) { - let slider; - formItem.props.children = [ - formItem.props.children, - BDFDB.ReactUtils.createElement("div", { - className: BDFDB.disCNS._timedlightdarkmodetimersettings + BDFDB.disCN.margintop20, - children: [ - BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, { - type: "Switch", - plugin: this, - keys: ["settings", "running"], - value: settings.running, - label: `${BDFDB.LanguageUtils.LanguageStrings.THEME} Timer`, - tag: BDFDB.LibraryComponents.FormComponents.FormTitle.Tags.H5, - childProps: { - checkedColor: BDFDB.DiscordConstants.Colors.STATUS_GREEN - }, - onChange: (value, instance) => { - this.startInterval(); - if (slider) BDFDB.DOMUtils.toggleClass(slider, BDFDB.disCN.sliderdisabled, !value); - } - }), - BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(`
${[["0%", "00:00"], ["12.5%", "03:00"], ["25%", "06:00"], ["37.5%", "09:00"], ["50%", "12:00"], ["62.5%", "15:00"], ["75%", "18:00"], ["87.5%", "21:00"], ["100%", "24:00"]].map(n => `
${n[1]}
`).join("")}
`), node => { - if (!Node.prototype.isPrototypeOf(node)) return; - slider = node; - this.updateSlider(slider, values); - BDFDB.ListenerUtils.addToChildren(slider, "mousedown", BDFDB.dotCN._timedlightdarkmodetimergrabber, event => this.dragSlider(event.currentTarget)); - BDFDB.ListenerUtils.addToChildren(slider, "mouseenter", BDFDB.dotCN._timedlightdarkmodedategrabber, event => this.showCurrentTime(event.currentTarget)); - }) - ] - }), - BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormDivider, { - className: BDFDB.disCNS.margintop20 + BDFDB.disCN.marginbottom8 - }) - ].flat(10).filter(n => n); - } + if (!formItem || !formItem.props) return; + let slider; + formItem.props.children = [ + formItem.props.children, + BDFDB.ReactUtils.createElement("div", { + className: BDFDB.disCNS._timedlightdarkmodetimersettings + BDFDB.disCN.margintop20, + children: [ + BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, { + type: "Switch", + plugin: this, + keys: ["general", "running"], + value: this.settings.general.running, + label: `${BDFDB.LanguageUtils.LanguageStrings.THEME} Timer`, + tag: BDFDB.LibraryComponents.FormComponents.FormTitle.Tags.H5, + childProps: { + checkedColor: BDFDB.DiscordConstants.Colors.STATUS_GREEN_600 + }, + onChange: (value, instance) => { + this.startInterval(); + if (slider) BDFDB.DOMUtils.toggleClass(slider, BDFDB.disCN.sliderdisabled, !value); + } + }), + BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(`
${[["0%", "00:00"], ["12.5%", "03:00"], ["25%", "06:00"], ["37.5%", "09:00"], ["50%", "12:00"], ["62.5%", "15:00"], ["75%", "18:00"], ["87.5%", "21:00"], ["100%", "24:00"]].map(n => `
${n[1]}
`).join("")}
`), node => { + if (!Node.prototype.isPrototypeOf(node)) return; + slider = node; + this.updateSlider(slider); + BDFDB.ListenerUtils.addToChildren(slider, "mousedown", BDFDB.dotCN._timedlightdarkmodetimergrabber, event => this.dragSlider(event.currentTarget)); + BDFDB.ListenerUtils.addToChildren(slider, "mouseenter", BDFDB.dotCN._timedlightdarkmodedategrabber, event => this.showCurrentTime(event.currentTarget)); + }) + ] + }), + BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormDivider, { + className: BDFDB.disCNS.margintop20 + BDFDB.disCN.marginbottom8 + }) + ].flat(10).filter(n => n); } startInterval () { BDFDB.TimeUtils.clear(checkInterval); - settings = BDFDB.DataUtils.get(this, "settings"); - values = BDFDB.DataUtils.get(this, "values"); disableChanging = false; - if (settings.running) { - let inverted = values.timer1 > values.timer2; - let timer1LOW = this.getTime(values.timer1), timer2LOW = this.getTime(values.timer2); + if (this.settings.general.running) { + let inverted = this.settings.values.timer1 > this.settings.values.timer2; + let timer1LOW = this.getTime(this.settings.values.timer1), timer2LOW = this.getTime(this.settings.values.timer2); let timer1HIGH = this.getHighTime(timer2LOW), timer2HIGH = this.getHighTime(timer1LOW); let check = _ => { if (disableChanging) return; @@ -188,7 +184,7 @@ module.exports = (_ => { BDFDB.DOMUtils.appendLocalStyle("disableTextSelection", `*{user-select: none !important;}`); - let value = values[timer]; + let value = this.settings.values[timer]; let sY = 0; let sHalfW = BDFDB.DOMUtils.getRects(grabber).width/2; let sMinX = BDFDB.DOMUtils.getRects(track).left; @@ -209,19 +205,19 @@ module.exports = (_ => { grabber.style.setProperty("left", value + "%"); tooltipContent.innerText = this.getTime(value, true); tooltip.update(); - values[timer] = value; - this.updateSlider(track.parentNode, values); + this.settings.values[timer] = value; + this.updateSlider(track.parentNode); }; document.addEventListener("mouseup", mouseUp); document.addEventListener("mousemove", mouseMove); } - updateSlider (slider, values) { + updateSlider (slider) { let bar = slider.querySelector(BDFDB.dotCN.sliderbar); let fill = slider.querySelector(BDFDB.dotCN.sliderbarfill); - let inverted = values.timer1 > values.timer2; - fill.style.setProperty("width", (inverted ? (values.timer1 - values.timer2) : (values.timer2 - values.timer1)) + "%"); - fill.style.setProperty("margin-left", (inverted ? values.timer2 : values.timer1) + "%"); + let inverted = this.settings.values.timer1 > this.settings.values.timer2; + fill.style.setProperty("width", (inverted ? (this.settings.values.timer1 - this.settings.values.timer2) : (this.settings.values.timer2 - this.settings.values.timer1)) + "%"); + fill.style.setProperty("margin-left", (inverted ? this.settings.values.timer2 : this.settings.values.timer1) + "%"); fill.style.setProperty("background-color", inverted ? "#66757F" : "#E0C460", "important"); bar.style.setProperty("background-color", inverted ? "#E0C460" : "#66757F", "important"); }