/** * @name WriteUpperCase * @author DevilBro * @authorId 278543574059057154 * @version 1.3.8 * @description Changes the first Letter of each Sentence in Message Inputs to Uppercase * @invite Jx3TjNS * @donate https://www.paypal.me/MircoWittrien * @patreon https://www.patreon.com/MircoWittrien * @website https://mwittrien.github.io/ * @source https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/WriteUpperCase/ * @updateUrl https://mwittrien.github.io/BetterDiscordAddons/Plugins/WriteUpperCase/WriteUpperCase.plugin.js */ module.exports = (_ => { const changeLog = { }; return !window.BDFDB_Global || (!window.BDFDB_Global.loaded && !window.BDFDB_Global.started) ? class { constructor (meta) {for (let key in meta) this[key] = meta[key];} getName () {return this.name;} getAuthor () {return this.author;} getVersion () {return this.version;} getDescription () {return `The Library Plugin needed for ${this.name} is missing. Open the Plugin Settings to download it. \n\n${this.description}`;} downloadLibrary () { BdApi.Net.fetch("https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js").then(r => { if (!r || r.status != 200) throw new Error(); else return r.text(); }).then(b => { if (!b) throw new Error(); else return require("fs").writeFile(require("path").join(BdApi.Plugins.folder, "0BDFDB.plugin.js"), b, _ => BdApi.showToast("Finished downloading BDFDB Library", {type: "success"})); }).catch(error => { BdApi.alert("Error", "Could not download BDFDB Library Plugin. Try again later or download it manually from GitHub: https://mwittrien.github.io/downloader/?library"); }); } load () { if (!window.BDFDB_Global || !Array.isArray(window.BDFDB_Global.pluginQueue)) window.BDFDB_Global = Object.assign({}, window.BDFDB_Global, {pluginQueue: []}); if (!window.BDFDB_Global.downloadModal) { window.BDFDB_Global.downloadModal = true; BdApi.showConfirmationModal("Library Missing", `The Library Plugin needed for ${this.name} is missing. Please click "Download Now" to install it.`, { confirmText: "Download Now", cancelText: "Cancel", onCancel: _ => {delete window.BDFDB_Global.downloadModal;}, onConfirm: _ => { delete window.BDFDB_Global.downloadModal; this.downloadLibrary(); } }); } if (!window.BDFDB_Global.pluginQueue.includes(this.name)) window.BDFDB_Global.pluginQueue.push(this.name); } start () {this.load();} stop () {} getSettingsPanel () { let template = document.createElement("template"); template.innerHTML = `
The Library Plugin needed for ${this.name} is missing.\nPlease click Download Now to install it.
`; template.content.firstElementChild.querySelector("a").addEventListener("click", this.downloadLibrary); return template.content.firstElementChild; } } : (([Plugin, BDFDB]) => { const QuickToogleButtonComponent = class TranslateButton extends BdApi.React.Component { componentDidMount() { toggleButtons[this.props.type] = this; } componentWillUnmount() { delete toggleButtons[this.props.type]; } render() { return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ChannelTextAreaButton, { className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN._writeuppercasequicktogglebutton, BDFDB.disCN._writeuppercasequicktogglebuttonenabled, BDFDB.disCN.textareapickerbutton), iconSVG: channelBlacklist.indexOf(this.props.channelId) == -1 ? `` : ``, nativeClass: true, onClick: _ => { if (channelBlacklist.indexOf(this.props.channelId) > -1) BDFDB.ArrayUtils.remove(channelBlacklist, this.props.channelId, true); else channelBlacklist.push(this.props.channelId); for (let type in toggleButtons) BDFDB.ReactUtils.forceUpdate(toggleButtons[type]); } }); } }; const symbols = [".", "!", "¡", "?", "¿"], spaces = ["\n", "\r", "\t", " "]; const channelBlacklist = []; const toggleButtons = {}; return class WriteUpperCase extends Plugin { onLoad () { this.defaults = { general: { addQuickToggle: {value: false, description: "Adds a quick Toggle to the Message Input"} }, places: { normal: {value: true, description: "Normal Message Textarea"}, edit: {value: true, description: "Edit Message Textarea"}, form: {value: true, description: "Upload Message Prompt"}, quickmessage: {value: true, description: "Quick Message Textarea UserPopout"} } }; this.modulePatches = { before: [ "ChannelTextAreaEditor", "TextInput" ], after: [ "ChannelTextAreaButtons", "TextInput" ] }; this.css = ` ${BDFDB.dotCNS.userpopoutmessageinputcontainer + BDFDB.dotCNS.flex + BDFDB.dotCN.inputwrapper} { flex: 1 1 auto; } `; } onStart () { BDFDB.PatchUtils.forceAllUpdates(this); } onStop () { 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.general) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, { type: "Switch", plugin: this, keys: ["general", key], label: this.defaults.general[key].description, value: this.settings.general[key] })); settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelList, { title: "Automatically transform in:", children: Object.keys(this.defaults.places).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, { type: "Switch", plugin: this, keys: ["places", key], label: this.defaults.places[key].description, value: this.settings.places[key] })) })); return settingsItems; } }); } onSettingsClosed () { if (this.SettingsUpdated) { delete this.SettingsUpdated; BDFDB.PatchUtils.forceAllUpdates(this); } } processChannelTextAreaEditor (e) { let type = e.instance.props.type.analyticsName || e.instance.props.type || ""; if (e.instance.props.textValue && e.instance.props.focused && (!type || this.settings.places[type] || !this.defaults.places[type]) && (!this.settings.general.addQuickToggle || channelBlacklist.indexOf(e.instance.props.channel.id) == -1)) { let string = e.instance.props.textValue; let newString = this.parse(string); if (string != newString) { let selection = document.getSelection(); let container = selection.anchorNode && BDFDB.DOMUtils.getParent("[contenteditable]", selection.anchorNode.parentElement); if (container && Array.from(container.children).findIndex(n => n && n.contains(selection.anchorNode)) == (container.childElementCount - 1)) { selection.modify("extend", "backward", "paragraphboundary"); if (selection.toString().length == selection.anchorNode.textContent.length) { e.instance.props.textValue = newString; if (e.instance.props.richValue) e.instance.props.richValue = BDFDB.SlateUtils.toRichValue(newString); } selection.collapseToEnd(); } } } } processChannelTextAreaButtons (e) { let type = e.instance.props.type.analyticsName || e.instance.props.type || ""; if ((!type || this.settings.places[type] || !this.defaults.places[type]) && this.settings.general.addQuickToggle && !e.instance.props.disabled) { e.returnvalue.props.children.unshift(BDFDB.ReactUtils.createElement(QuickToogleButtonComponent, { type: type, channelId: e.instance.props.channel.id })); } } processTextInput (e) { if (!this.settings.places.quickmessage || !e.instance.props.className || e.instance.props.className.indexOf(BDFDB.disCN.userpopoutmessageinputcontainer) == -1) return; let channelId = BDFDB.LibraryStores.SelectedChannelStore.getChannelId(); if (!e.returnvalue) { let input = e.instance.props.inputRef.current; if (input) BDFDB.ListenerUtils.add(this, input, "keyup", event => { if (this.settings.places.quickmessage && (!this.settings.general.addQuickToggle || channelBlacklist.indexOf(channelId) == -1)) { let string = input.value; let newString = this.parse(string); if (string != newString) input.value = newString; } }); } else { if (this.settings.general.addQuickToggle) e.returnvalue = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, { children: [ BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex.Child, { children: e.returnvalue }), BDFDB.ReactUtils.createElement(QuickToogleButtonComponent, { type: "quickmessage", channelId: channelId }) ] }); } } parse (string) { if (!string.length || /<[#@][!&]{0,1}\d+>|@here|@everyone|:[A-z0-9_-]+:|[\uD83C-\uDBFF\uDC00-\uDFFF]+/.test(string)) return string; let newString = string, stop = false; let language = BDFDB.LanguageUtils.getLanguage().id; for (let space of spaces) for (let symbol of symbols) if (!stop) { let reg; try {reg = new RegExp((symbol == "." ? "(? -1) stop = true; } newString = sentences.join(symbol + space); } return newString; } }; })(window.BDFDB_Global.PluginUtils.buildPlugin(changeLog)); })();