From 2fe66e5c36e0c70a6f291b4445ee0006af777bb2 Mon Sep 17 00:00:00 2001 From: Mirco Wittrien Date: Sat, 21 Nov 2020 19:59:21 +0100 Subject: [PATCH] stuff --- Library/_res/BDFDB.data.json | 6 +- .../TimedLightDarkMode.plugin.js | 92 +++++++++++-------- 2 files changed, 57 insertions(+), 41 deletions(-) diff --git a/Library/_res/BDFDB.data.json b/Library/_res/BDFDB.data.json index 31bb321488..adc541c1a9 100644 --- a/Library/_res/BDFDB.data.json +++ b/Library/_res/BDFDB.data.json @@ -226,7 +226,7 @@ "UserHook": {"class": "auditloguserhook"}, "UserPopout": {"class": "userpopout"}, "UserProfile": {"class": "userprofile"}, - "UserSettingsAppearance": {"class": "radiogroup"}, + "UserSettingsAppearance": {"class": "usersettingsappearancepreview"}, "V2C_ContentColumn": {"class": "settingswindowcontentcolumn", "special": [{"path": "return.stateNode.props.title", "value": ["PLUGINS", "THEMES"]}]} }, "LoadedInComponents": { @@ -1074,6 +1074,7 @@ "UserInfo": {"props": ["userInfo", "discordTag"]}, "UserPopout": {"props": ["userPopout", "headerPlaying"]}, "UserProfile": {"props": ["topSectionNormal", "tabBarContainer"]}, + "UserSettingsAppearancePreview": {"props": ["preview", "firstMessage"]}, "UserSummaryItem": {"props": ["avatarContainerMasked", "container"]}, "Video": {"props": ["video", "fullScreen"]}, "VoiceChannel": {"props": ["avatarSpeaking", "voiceUser"]}, @@ -1784,6 +1785,9 @@ "guilds": ["AppBase", "guilds"], "guildseparator": ["GuildsItems", "guildSeparator"], "guildserror": ["GuildsItems", "guildsError"], + "usersettingsappearancepreview": ["UserSettingsAppearancePreview", "preview"], + "usersettingsappearancepreviewcompact": ["UserSettingsAppearancePreview", "compactpreview"], + "usersettingsappearancepreviewfirst": ["UserSettingsAppearancePreview", "firstMessage"], "guildsettingsbannedcard": ["GuildSettingsBanned", "bannedUser"], "guildsettingsbanneddiscrim": ["GuildSettingsBanned", "discrim"], "guildsettingsbannedusername": ["GuildSettingsBanned", "username"], diff --git a/Plugins/TimedLightDarkMode/TimedLightDarkMode.plugin.js b/Plugins/TimedLightDarkMode/TimedLightDarkMode.plugin.js index c455872a55..2c27bd335d 100644 --- a/Plugins/TimedLightDarkMode/TimedLightDarkMode.plugin.js +++ b/Plugins/TimedLightDarkMode/TimedLightDarkMode.plugin.js @@ -14,8 +14,13 @@ module.exports = (_ => { "info": { "name": "TimedLightDarkMode", "author": "DevilBro", - "version": "1.0.8", + "version": "1.0.9", "description": "Allow you to automatically change light/dark mode depending on the time of day - Slider is added to the 'Appearance' settings" + }, + "changeLog": { + "fixed": { + "Works again": "Yes" + } } }; @@ -64,12 +69,12 @@ module.exports = (_ => { this.patchedModules = { after: { - RadioGroup: "componentDidMount" + UserSettingsAppearance: "render" } }; } - onStart() { + onStart() { BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.SettingsUtils, "updateLocalSettings", {after: e => { if (BDFDB.ObjectUtils.is(e.methodArguments[0]) && e.methodArguments[0].theme) { BDFDB.TimeUtils.clear(changeTimeout); @@ -91,34 +96,41 @@ module.exports = (_ => { BDFDB.DOMUtils.remove(BDFDB.dotCN._timedlightdarkmodetimersettings); } - processRadioGroup (e) { - if (e.instance.props && Array.isArray(e.instance.props.options) && e.instance.props.options[0] && (e.instance.props.options[0].value == "light" || e.instance.props.options[0].value == "dark") && e.instance.props.options[1] && (e.instance.props.options[1].value == "light" || e.instance.props.options[1].value == "dark") && e.node.parentElement.firstElementChild.innerText && e.node.parentElement.firstElementChild.innerText.toUpperCase() == BDFDB.LanguageUtils.LanguageStrings.THEME.toUpperCase()) { - let slider, settingsBox = BDFDB.DOMUtils.create(`
`); - BDFDB.ReactUtils.render(BDFDB.ReactUtils.createElement(BDFDB.ReactUtils.Fragment, { - 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, - onChange: (value, instance) => { - this.startInterval(); - if (slider) BDFDB.DOMUtils.toggleClass(slider, BDFDB.disCN.sliderdisabled, !value); - } - }), - BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(`
00: 00
03: 00
06: 00
09: 00
12: 00
15: 00
18: 00
21: 00
24: 00
`), node => { - if (Node.prototype.isPrototypeOf(node)) { - 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);}); - } - }) - ] - }), settingsBox); - e.node.parentElement.appendChild(settingsBox); + 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(`
00:00
03:00
06:00
09:00
12:00
15:00
18:00
21:00
24:00
`), node => { + if (Node.prototype.isPrototypeOf(node)) { + 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);}); + } + }) + ] + }) + ].flat(10).filter(n => n); } } @@ -176,15 +188,15 @@ module.exports = (_ => { let sMaxX = sMinX + BDFDB.DOMUtils.getRects(track).width; let tooltip = BDFDB.TooltipUtils.create(grabber, this.getTime(value, true), {color: "grey", perssist: true}); let tooltipContent = tooltip.querySelector(BDFDB.dotCN.tooltipcontent); - let mouseup = _ => { - document.removeEventListener("mouseup", mouseup); - document.removeEventListener("mousemove", mousemove); + let mouseUp = _ => { + document.removeEventListener("mouseup", mouseUp); + document.removeEventListener("mousemove", mouseMove); BDFDB.DOMUtils.removeLocalStyle("disableTextSelection"); BDFDB.DataUtils.save(value, this, "values", timer); BDFDB.DOMUtils.remove(tooltip); this.startInterval(); }; - let mousemove = e => { + let mouseMove = e => { sY = e.clientX > sMaxX ? sMaxX - sHalfW : (e.clientX < sMinX ? sMinX - sHalfW : e.clientX - sHalfW); value = BDFDB.NumberUtils.mapRange([sMinX - sHalfW, sMaxX - sHalfW], [0, 100], sY); input.value = value; @@ -194,8 +206,8 @@ module.exports = (_ => { values[timer] = value; this.updateSlider(track.parentNode, values); }; - document.addEventListener("mouseup", mouseup); - document.addEventListener("mousemove", mousemove); + document.addEventListener("mouseup", mouseUp); + document.addEventListener("mousemove", mouseMove); } updateSlider (slider, values) { @@ -212,13 +224,13 @@ module.exports = (_ => { let time = BDFDB.NumberUtils.mapRange([0, 100], [0, 1440], percent)/60; let hours = Math.floor(time); let minutes = Math.floor((time - hours) * 60); - return stringify ? (hours > 9 ? hours : ("0" + hours)) + ":" + (minutes > 9 ? minutes : ("0" + minutes)) : [hours,minutes]; + return stringify ? (hours > 9 ? hours : ("0" + hours)) + ":" + (minutes > 9 ? minutes : ("0" + minutes)) : [hours, minutes]; } getPercent (time) { if (!time) return 0; - let hours = Array.isArray(time) ? time[0] : (typeof time == "object" && typeof time.getHours == "function" ? time.getHours() : 0); - let minutes = Array.isArray(time) ? time[1] : (typeof time == "object" && typeof time.getMinutes == "function" ? time.getMinutes() : 0); + let hours = Array.isArray(time) ? time[0] : (typeof time == "object" && typeof time.getHours == "function" ? time.getHours() :0); + let minutes = Array.isArray(time) ? time[1] : (typeof time == "object" && typeof time.getMinutes == "function" ? time.getMinutes() :0); return BDFDB.NumberUtils.mapRange([0, 1440], [0, 100], (hours * 60) + minutes); }