From da4f7944daaf603d7ef7ff061dad5a11fbbec86a Mon Sep 17 00:00:00 2001 From: Mirco Wittrien Date: Thu, 9 Dec 2021 23:28:54 +0100 Subject: [PATCH] stuff --- Library/0BDFDB.plugin.js | 12 +++--- Plugins/CharCounter/CharCounter.plugin.js | 47 ++++++++++++++++++++--- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/Library/0BDFDB.plugin.js b/Library/0BDFDB.plugin.js index d3081a485a..b4871f6709 100644 --- a/Library/0BDFDB.plugin.js +++ b/Library/0BDFDB.plugin.js @@ -2,7 +2,7 @@ * @name BDFDB * @author DevilBro * @authorId 278543574059057154 - * @version 2.0.0 + * @version 2.0.1 * @description Required Library for DevilBro's Plugins * @invite Jx3TjNS * @donate https://www.paypal.me/MircoWittrien @@ -19,7 +19,7 @@ module.exports = (_ => { "info": { "name": "BDFDB", "author": "DevilBro", - "version": "2.0.0", + "version": "2.0.1", "description": "Required Library for DevilBro's Plugins" }, "rawUrl": `https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js` @@ -4997,6 +4997,7 @@ module.exports = (_ => { else string = input.value || input.textContent || ""; } else string = input.value || input.textContent || ""; + if (this.props.max && this.props.showPercentage && (string.length/this.props.max) * 100 < this.props.showPercentage) return null; let start = input.selectionStart || 0, end = input.selectionEnd || 0, selectlength = end - start, selection = BDFDB.DOMUtils.getSelection(); let select = !selectlength && !selection ? 0 : (selectlength || selection.length); select = !select ? 0 : (select > string.length ? (end || start ? string.length - (string.length - end - start) : string.length) : select); @@ -5079,11 +5080,12 @@ module.exports = (_ => { } render() { let string = this.getCounterString(); - BDFDB.TimeUtils.timeout(_ => {if (string != this.getCounterString()) BDFDB.ReactUtils.forceUpdate(this);}); + if (!string) return null; + BDFDB.TimeUtils.timeout(_ => string != this.getCounterString() && BDFDB.ReactUtils.forceUpdate(this)); return BDFDB.ReactUtils.createElement("div", BDFDB.ObjectUtils.exclude(Object.assign({}, this.props, { className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.charcounter, this.props.className), children: string - }), "parsing", "max", "refClass", "renderPrefix", "renderSuffix")); + }), "parsing", "max", "refClass", "renderPrefix", "renderSuffix", "showPercentage")); } }; @@ -7279,7 +7281,7 @@ module.exports = (_ => { }), "digits", "edges", "max", "min", "markerAmount")); } }; - InternalBDFDB.setDefaultProps(InternalComponents.LibraryComponents.Slider, {hideBubble: false}); + InternalBDFDB.setDefaultProps(InternalComponents.LibraryComponents.Slider, {hideBubble: false, digits: 3}); InternalComponents.LibraryComponents.SvgIcon = reactInitialized && class BDFDB_Icon extends LibraryModules.React.Component { render() { diff --git a/Plugins/CharCounter/CharCounter.plugin.js b/Plugins/CharCounter/CharCounter.plugin.js index 8844d4c030..c40c1e6894 100644 --- a/Plugins/CharCounter/CharCounter.plugin.js +++ b/Plugins/CharCounter/CharCounter.plugin.js @@ -2,7 +2,7 @@ * @name CharCounter * @author DevilBro * @authorId 278543574059057154 - * @version 1.5.6 + * @version 1.5.7 * @description Adds a Character Counter to most Inputs * @invite Jx3TjNS * @donate https://www.paypal.me/MircoWittrien @@ -17,12 +17,12 @@ module.exports = (_ => { "info": { "name": "CharCounter", "author": "DevilBro", - "version": "1.5.6", + "version": "1.5.7", "description": "Adds a Character Counter to most Inputs" }, "changeLog": { - "improved": { - "Threads": "Works flawlessly with Threads now" + "added": { + "Percentage": "Added a Percentage Slider that lets you change at which Percentage the Counter is gonna show up" } } }; @@ -97,6 +97,12 @@ module.exports = (_ => { } }; + this.defaults = { + sliders: { + showPercentage: {value: 0, description: "Only shows Counter after certain % of Max Length is reached"} + } + }; + this.css = ` ${BDFDB.dotCN._charcountercounteradded} { position: relative !important; @@ -157,11 +163,39 @@ module.exports = (_ => { BDFDB.PatchUtils.forceAllUpdates(this); } + getSettingsPanel (collapseStates = {}) { + let settingsPanel; + return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, { + collapseStates: collapseStates, + children: _ => { + let settingsItems = []; + + for (let key in this.defaults.sliders) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, { + type: "Slider", + plugin: this, + keys: ["sliders", key], + basis: "30%", + label: this.defaults.sliders[key].description, + value: this.settings.sliders[key] + })); + + return settingsItems; + } + }); + } + + onSettingsClosed () { + if (this.SettingsUpdated) { + delete this.SettingsUpdated; + BDFDB.PatchUtils.forceAllUpdates(this); + } + } + processChannelTextAreaContainer (e) { let editorContainer = BDFDB.ReactUtils.findChild(e.returnvalue, {name: "ChannelEditorContainer"}); if (editorContainer && editorContainer.props.type && !editorContainer.props.disabled) { if (!BDFDB.ArrayUtils.is(e.returnvalue.props.children)) e.returnvalue.props.children = [e.returnvalue.props.children]; - this.injectCounter(e.returnvalue, e.returnvalue.props.children, editorContainer.props.type, BDFDB.dotCN.textarea, true); + this.injectCounter(e.returnvalue, e.returnvalue.props.children, editorContainer.props.type, BDFDB.dotCN.textarea); } } @@ -183,7 +217,7 @@ module.exports = (_ => { if (formItem) this.injectCounter(formItem, formItem.props.children, "customstatus", BDFDB.dotCN.input); } - injectCounter (parent, children, type, refClass, parsing, premium) { + injectCounter (parent, children, type, refClass, parsing) { if (!children) return; if (parent.props.className) parent.props.className = BDFDB.DOMUtils.formatClassName(parent.props.className, BDFDB.disCN._charcountercounteradded); else parent.props.children = BDFDB.ReactUtils.createElement("div", { @@ -195,6 +229,7 @@ module.exports = (_ => { refClass: refClass, parsing: parsing, max: maxLengths[type] || (BDFDB.LibraryModules.NitroUtils.canUseIncreasedMessageLength(BDFDB.UserUtils.me) ? BDFDB.DiscordConstants.MAX_MESSAGE_LENGTH_PREMIUM : BDFDB.DiscordConstants.MAX_MESSAGE_LENGTH), + showPercentage: this.settings.sliders.showPercentage, onChange: instance => { let node = BDFDB.ReactUtils.findDOMNode(instance); let form = node && BDFDB.DOMUtils.getParent(BDFDB.dotCN.chatform, node);