This commit is contained in:
Mirco Wittrien 2022-02-11 21:27:16 +01:00
parent 461f417780
commit a5d0f0d3cb
2 changed files with 105 additions and 64 deletions

View File

@ -1420,35 +1420,40 @@ module.exports = (_ => {
if (!BDFDB.ArrayUtils.is(plugin.eventListeners)) plugin.eventListeners = [];
let eventCallback = null;
if (selector) {
if (origEventName == "mouseenter" || origEventName == "mouseleave") {
eventCallback = e => {
for (let child of e.path) if (typeof child.matches == "function" && child.matches(selector) && !child[namespace + "BDFDB" + origEventName]) {
child[namespace + "BDFDB" + origEventName] = true;
if (origEventName == "mouseenter") callback(BDFDB.ListenerUtils.copyEvent(e, child));
let mouseOut = e2 => {
if (e2.target.contains(child) || e2.target == child || !child.contains(e2.target)) {
if (origEventName == "mouseleave") callback(BDFDB.ListenerUtils.copyEvent(e, child));
delete child[namespace + "BDFDB" + origEventName];
document.removeEventListener("mouseout", mouseOut);
}
};
document.addEventListener("mouseout", mouseOut);
break;
}
};
}
else {
eventCallback = e => {
for (let child of e.path) if (typeof child.matches == "function" && child.matches(selector)) {
callback(BDFDB.ListenerUtils.copyEvent(e, child));
break;
}
};
}
if (origEventName == "mouseenter" || origEventName == "mouseleave") eventCallback = e => {
for (let child of e.path) if (typeof child.matches == "function" && child.matches(selector) && !child[namespace + "BDFDB" + origEventName]) {
child[namespace + "BDFDB" + origEventName] = true;
if (origEventName == "mouseenter") callback(BDFDB.ListenerUtils.copyEvent(e, child));
let mouseOut = e2 => {
if (e2.target.contains(child) || e2.target == child || !child.contains(e2.target)) {
if (origEventName == "mouseleave") callback(BDFDB.ListenerUtils.copyEvent(e, child));
delete child[namespace + "BDFDB" + origEventName];
document.removeEventListener("mouseout", mouseOut);
}
};
document.addEventListener("mouseout", mouseOut);
break;
}
};
else eventCallback = e => {
for (let child of e.path) if (typeof child.matches == "function" && child.matches(selector)) {
callback(BDFDB.ListenerUtils.copyEvent(e, child));
break;
}
};
}
else eventCallback = e => callback(BDFDB.ListenerUtils.copyEvent(e, ele));
let observer;
if (Node.prototype.isPrototypeOf(ele)) {
observer = new MutationObserver(changes => changes.forEach(change => {
const nodes = Array.from(change.removedNodes);
if (nodes.indexOf(ele) > -1 || nodes.some(n => n.contains(ele))) BDFDB.ListenerUtils.remove(plugin, ele, actions, selector);
}));
observer.observe(document.body, {subtree: true, childList: true});
}
else eventCallback = e => {callback(BDFDB.ListenerUtils.copyEvent(e, ele));};
plugin.eventListeners.push({ele, eventName, origEventName, namespace, selector, eventCallback});
plugin.eventListeners.push({ele, eventName, origEventName, namespace, selector, eventCallback, observer});
ele.addEventListener(eventName, eventCallback, true);
}
};
@ -1459,6 +1464,7 @@ module.exports = (_ => {
while (plugin.eventListeners.length) {
let listener = plugin.eventListeners.pop();
listener.ele.removeEventListener(listener.eventName, listener.eventCallback, true);
if (listener.observer) listener.observer.disconnect();
}
}
else if (Node.prototype.isPrototypeOf(ele) || ele === window) {
@ -1470,6 +1476,7 @@ module.exports = (_ => {
let removedListeners = [];
if (listener.ele == ele && (!eventName || listener.origEventName == eventName) && listener.namespace == namespace && (selector === undefined || listener.selector == selector)) {
listener.ele.removeEventListener(listener.eventName, listener.eventCallback, true);
if (listener.observer) listener.observer.disconnect();
removedListeners.push(listener);
}
if (removedListeners.length) plugin.eventListeners = plugin.eventListeners.filter(listener => !removedListeners.includes(listener));
@ -2106,7 +2113,7 @@ module.exports = (_ => {
const observer = new MutationObserver(changes => changes.forEach(change => {
const nodes = Array.from(change.removedNodes);
if (nodes.indexOf(itemLayer) > -1 || nodes.indexOf(anker) > -1 || nodes.some(n => n.contains(anker))) removeTooltip();
if (nodes.indexOf(itemLayer) > -1 || nodes.indexOf(anker) > -1 || nodes.some(n => n.contains(anker))) removeTooltip();
}));
observer.observe(document.body, {subtree: true, childList: true});
@ -3096,7 +3103,7 @@ module.exports = (_ => {
LibraryModules.ReactDOM.render(component, node);
let observer = new MutationObserver(changes => changes.forEach(change => {
let nodes = Array.from(change.removedNodes);
if (nodes.indexOf(node) > -1 || nodes.some(n => n.contains(node))) {
if (nodes.indexOf(node) > -1 || nodes.some(n => n.contains(node))) {
observer.disconnect();
BDFDB.ReactUtils.unmountComponentAtNode(node);
}

View File

@ -2,7 +2,7 @@
* @name WriteUpperCase
* @author DevilBro
* @authorId 278543574059057154
* @version 1.3.3
* @version 1.3.4
* @description Changes the first Letter of each Sentence in Message Inputs to Uppercase
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
@ -17,8 +17,13 @@ module.exports = (_ => {
"info": {
"name": "WriteUpperCase",
"author": "DevilBro",
"version": "1.3.3",
"version": "1.3.4",
"description": "Changes the first Letter of each Sentence in Message Inputs to Uppercase"
},
"changeLog": {
"added": {
"QuickMessage": "Now also works for the quick message input in the user popout"
}
}
};
@ -69,8 +74,8 @@ module.exports = (_ => {
}
render() {
return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ChannelTextAreaButton, {
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN._writeuppercasequicktogglebutton, channelBlacklist.indexOf(this.props.channelId) == -1 && BDFDB.disCN._writeuppercasequicktogglebuttonenabled, BDFDB.disCN.textareapickerbutton),
iconSVG: `<svg width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="m 3,1.9999999 c -1.662,0 -3,1.115 -3,2.5 V 4.9257811 17.894531 19.5 C 0,20.885 1.338,22 3,22 h 18 c 1.662,0 3,-1.115 3,-2.5 V 17.894531 5.048828 4.4999999 c 0,-1.385 -1.338,-2.5 -3,-2.5 z M 6.460938,6.970703 h 3.355468 l 3.19336,9.703125 h -2.585938 l -0.492187,-1.875 H 6.416016 l -0.507813,1.875 H 3.308594 Z m 10.648437,1.6328125 c 2.631064,0 3.470703,1.5495695 3.470703,3.4062505 v 2.74414 c 0,0.758553 0.03039,1.484092 0.111328,1.919922 h -2.210937 l -0.144531,-0.791016 h -0.04883 c -0.516766,0.629875 -1.323255,0.96875 -2.259765,0.96875 -1.597787,0 -2.550782,-1.162897 -2.550782,-2.421874 0,-2.049961 1.840132,-3.034174 4.632813,-3.017579 v -0.113281 c 0,-0.419489 -0.225079,-1.017578 -1.435547,-1.017578 -0.806808,0 -1.663177,0.274933 -2.179687,0.597656 L 14.042969,9.2968749 c 0.548425,-0.3066383 1.629725,-0.6933594 3.066406,-0.6933594 z m -8.761719,0.609375 -0.34375,0.00195 -1.11914,3.3652345 h 2.576172 z m 9.722656,3.7304685 c -1.232783,0.0048 -2.171874,0.321562 -2.171874,1.244141 0,0.629362 0.420324,0.935547 0.96875,0.935547 0.613531,0 1.114028,-0.401663 1.27539,-0.902344 0.03243,-0.129446 0.04883,-0.27439 0.04883,-0.419922 v -0.857422 c -0.04036,-4.86e-4 -0.08133,-1.53e-4 -0.121094,0 z"/></svg>`,
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN._writeuppercasequicktogglebutton, BDFDB.disCN._writeuppercasequicktogglebuttonenabled, BDFDB.disCN.textareapickerbutton),
iconSVG: channelBlacklist.indexOf(this.props.channelId) == -1 ? `<svg width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="m 3,1.9999999 c -1.662,0 -3,1.115 -3,2.5 V 4.9257811 17.894531 19.5 C 0,20.885 1.338,22 3,22 h 18 c 1.662,0 3,-1.115 3,-2.5 V 17.894531 5.048828 4.4999999 c 0,-1.385 -1.338,-2.5 -3,-2.5 z M 6.460938,6.970703 h 3.355468 l 3.19336,9.703125 h -2.585938 l -0.492187,-1.875 H 6.416016 l -0.507813,1.875 H 3.308594 Z m 10.648437,1.6328125 c 2.631064,0 3.470703,1.5495695 3.470703,3.4062505 v 2.74414 c 0,0.758553 0.03039,1.484092 0.111328,1.919922 h -2.210937 l -0.144531,-0.791016 h -0.04883 c -0.516766,0.629875 -1.323255,0.96875 -2.259765,0.96875 -1.597787,0 -2.550782,-1.162897 -2.550782,-2.421874 0,-2.049961 1.840132,-3.034174 4.632813,-3.017579 v -0.113281 c 0,-0.419489 -0.225079,-1.017578 -1.435547,-1.017578 -0.806808,0 -1.663177,0.274933 -2.179687,0.597656 L 14.042969,9.2968749 c 0.548425,-0.3066383 1.629725,-0.6933594 3.066406,-0.6933594 z m -8.761719,0.609375 -0.34375,0.00195 -1.11914,3.3652345 h 2.576172 z m 9.722656,3.7304685 c -1.232783,0.0048 -2.171874,0.321562 -2.171874,1.244141 0,0.629362 0.420324,0.935547 0.96875,0.935547 0.613531,0 1.114028,-0.401663 1.27539,-0.902344 0.03243,-0.129446 0.04883,-0.27439 0.04883,-0.419922 v -0.857422 c -0.04036,-4.86e-4 -0.08133,-1.53e-4 -0.121094,0 z"/></svg>` : `<svg width='24' height='24' viewBox='0 0 24 24'><path fill='currentColor' d='M 3 2 C 1.338 2 0 3.115 0 4.5 L 0 4.9257812 L 0 17.894531 L 0 19.5 C 0 19.794967 0.064199977 20.075579 0.17578125 20.337891 L 3.8398438 16.673828 L 3.3085938 16.673828 L 6.4609375 6.9707031 L 9.8164062 6.9707031 L 10.738281 9.7753906 L 18.513672 2 L 3 2 z M 23.763672 3.5214844 L 19.972656 7.3125 L 18.498047 8.7871094 C 20.043946 9.2485927 20.580078 10.531086 20.580078 12.009766 L 20.580078 14.753906 C 20.580078 15.512459 20.610468 16.237998 20.691406 16.673828 L 18.480469 16.673828 L 18.335938 15.882812 L 18.287109 15.882812 C 17.770343 16.512687 16.963854 16.851562 16.027344 16.851562 C 14.429557 16.851562 13.476562 15.688664 13.476562 14.429688 C 13.476562 14.179968 13.503633 13.946722 13.556641 13.728516 L 12.416016 14.871094 L 13.009766 16.673828 L 10.613281 16.673828 L 10.267578 17.019531 L 5.8398438 21.447266 L 5.2910156 22 L 21 22 C 22.662 22 24 20.885 24 19.5 L 24 17.894531 L 24 5.0488281 L 24 4.5 C 24 4.1522582 23.916317 3.8218102 23.763672 3.5214844 z M 8.3476562 9.2128906 L 8.0039062 9.2148438 L 6.8847656 12.580078 L 7.9335938 12.580078 L 9.0820312 11.431641 L 8.3476562 9.2128906 z M 16.984375 10.302734 L 15.494141 11.792969 C 16.213559 11.533287 17.097834 11.406098 18.109375 11.412109 L 18.109375 11.298828 C 18.109375 10.919047 17.917537 10.398944 16.984375 10.302734 z M 18.070312 12.943359 C 16.837529 12.948159 15.898438 13.264921 15.898438 14.1875 C 15.898438 14.816862 16.318762 15.123047 16.867188 15.123047 C 17.480718 15.123047 17.981216 14.721384 18.142578 14.220703 C 18.175008 14.091257 18.191406 13.946313 18.191406 13.800781 L 18.191406 12.943359 C 18.151046 12.942873 18.110076 12.943206 18.070312 12.943359 z'/><path d='M 24,1.6933333 22.306667,0 0,22.306667 1.6933333,24 7.28,18.426667 8.92,16.773333 11.133333,14.56 15.986667,9.706667 Z' class='${BDFDB.disCN.accountinfobuttonstrikethrough}' fill='currentColor'/></svg>`,
nativeClass: true,
onClick: _ => {
if (channelBlacklist.indexOf(this.props.channelId) > -1) BDFDB.ArrayUtils.remove(channelBlacklist, this.props.channelId, true);
@ -93,9 +98,10 @@ module.exports = (_ => {
addQuickToggle: {value: false, description: "Adds a quick Toggle to the Message Input"}
},
places: {
changeNormal: {value: true, description: "Normal Message Textarea"},
changeEdit: {value: true, description: "Edit Message Textarea"},
changeForm: {value: true, description: "Upload Message Prompt"}
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"}
}
};
@ -104,13 +110,14 @@ module.exports = (_ => {
ChannelEditorContainer: "render"
},
after: {
ChannelTextAreaButtons: "type"
ChannelTextAreaButtons: "type",
QuickMessage: "default"
}
};
this.css = `
${BDFDB.dotCN._writeuppercasequicktogglebutton + BDFDB.dotCNS._writeuppercasequicktogglebuttonenabled + BDFDB.dotCN.textareaicon} {
color: var(--bdfdb-red) !important;
${BDFDB.dotCNS.userpopoutfooter + BDFDB.dotCNS.flex + BDFDB.dotCN.inputwrapper} {
flex: 1 1 auto;
}
`;
}
@ -167,41 +174,68 @@ module.exports = (_ => {
processChannelEditorContainer (e) {
let type = e.instance.props.type.analyticsName || e.instance.props.type || "";
type = BDFDB.LibraryModules.StringUtils.upperCaseFirstChar(typeof type != "string" ? "" : type);
if (e.instance.props.textValue && e.instance.state.focused && (!type || this.settings.places[type] || !this.defaults.general[type]) && (!this.settings.general.addQuickToggle || channelBlacklist.indexOf(e.instance.props.channel.id) == -1)) {
if (e.instance.props.textValue && e.instance.state.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;
if (string.length && !/<[#@][!&]{0,1}\d+>|@here|@everyone|:[A-z0-9_-]+:|[\uD83C-\uDBFF\uDC00-\uDFFF]+/.test(string)) {
let newString = string, stop = false;
for (let space of spaces) for (let symbol of symbols) if (!stop) {
let reg;
try {reg = new RegExp((symbol == "." ? "(?<!\\.)" : "") + BDFDB.StringUtils.regEscape(symbol + space), "g");}
catch (err) {reg = new RegExp(BDFDB.StringUtils.regEscape(symbol + space), "g");}
let sentences = newString.split(reg);
for (let i in sentences) {
let sentence = sentences[i];
let first = sentence.charAt(0);
if (first === first.toUpperCase() && (sentence.toLowerCase().indexOf("http") == 0 || sentence.toLowerCase().indexOf("s/") == 0)) sentences[i] = sentence.charAt(0).toLowerCase() + sentence.slice(1);
else if (first === first.toLowerCase() && first !== first.toUpperCase() && sentence.toLowerCase().indexOf("http") != 0 && sentence.toLowerCase().indexOf("s/") != 0) sentences[i] = sentence.charAt(0).toUpperCase() + sentence.slice(1);
if (sentence.indexOf("```") > -1) stop = true;
}
newString = sentences.join(symbol + space);
}
if (string != newString) {
e.instance.props.textValue = newString;
if (e.instance.props.richValue) e.instance.props.richValue = BDFDB.SlateUtils.copyRichValue(newString, e.instance.props.richValue);
}
let newString = this.parse(string);
if (string != newString) {
e.instance.props.textValue = newString;
if (e.instance.props.richValue) e.instance.props.richValue = BDFDB.SlateUtils.copyRichValue(newString, e.instance.props.richValue);
}
}
}
processChannelTextAreaButtons (e) {
if (this.settings.general.addQuickToggle && !e.instance.props.disabled) {
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: e.instance.props.type.analyticsName || e.instance.props.type,
type: type,
channelId: e.instance.props.channel.id
}));
}
}
processQuickMessage (e) {
if (!this.settings.places.quickmessage) return;
let input = e.returnvalue.props.inputRef.current;
let channelId = BDFDB.LibraryModules.LastChannelStore.getChannelId();
if (this.settings.general.addQuickToggle) e.returnvalue = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
children: [
e.returnvalue,
BDFDB.ReactUtils.createElement(QuickToogleButtonComponent, {
type: "quickmessage",
channelId: channelId
})
]
});
if (!input) return;
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;
}
});
}
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;
for (let space of spaces) for (let symbol of symbols) if (!stop) {
let reg;
try {reg = new RegExp((symbol == "." ? "(?<!\\.)" : "") + BDFDB.StringUtils.regEscape(symbol + space), "g");}
catch (err) {reg = new RegExp(BDFDB.StringUtils.regEscape(symbol + space), "g");}
let sentences = newString.split(reg);
for (let i in sentences) {
let sentence = sentences[i];
let first = sentence.charAt(0);
if (first === first.toUpperCase() && (sentence.toLowerCase().indexOf("http") == 0 || sentence.toLowerCase().indexOf("s/") == 0)) sentences[i] = sentence.charAt(0).toLowerCase() + sentence.slice(1);
else if (first === first.toLowerCase() && first !== first.toUpperCase() && sentence.toLowerCase().indexOf("http") != 0 && sentence.toLowerCase().indexOf("s/") != 0) sentences[i] = sentence.charAt(0).toUpperCase() + sentence.slice(1);
if (sentence.indexOf("```") > -1) stop = true;
}
newString = sentences.join(symbol + space);
}
return newString;
}
};
})(window.BDFDB_Global.PluginUtils.buildPlugin(config));
})();