2019-09-20 22:32:52 +02:00
|
|
|
//META{"name":"WriteUpperCase","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/WriteUpperCase","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/WriteUpperCase/WriteUpperCase.plugin.js"}*//
|
2018-10-11 10:21:26 +02:00
|
|
|
|
|
|
|
class WriteUpperCase {
|
|
|
|
getName () {return "WriteUpperCase";}
|
|
|
|
|
2019-09-11 12:14:43 +02:00
|
|
|
getVersion () {return "1.2.1";}
|
2018-10-11 10:21:26 +02:00
|
|
|
|
|
|
|
getAuthor () {return "DevilBro";}
|
|
|
|
|
2019-01-17 23:48:29 +01:00
|
|
|
getDescription () {return "Change input to uppercase.";}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2019-09-04 12:34:02 +02:00
|
|
|
constructor () {
|
2019-09-11 12:14:43 +02:00
|
|
|
this.changelog = {
|
|
|
|
"fixed":[["Light Theme Update","Fixed bugs for the Light Theme Update, which broke 99% of my plugins"]]
|
|
|
|
};
|
|
|
|
|
2019-01-17 23:48:29 +01:00
|
|
|
this.patchModules = {
|
|
|
|
"ChannelTextArea":"componentDidMount",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
load () {}
|
|
|
|
|
|
|
|
start () {
|
2019-02-04 09:13:15 +01:00
|
|
|
if (!global.BDFDB) global.BDFDB = {myPlugins:{}};
|
|
|
|
if (global.BDFDB && global.BDFDB.myPlugins && typeof global.BDFDB.myPlugins == "object") global.BDFDB.myPlugins[this.getName()] = this;
|
2019-05-26 13:55:26 +02:00
|
|
|
var libraryScript = document.querySelector('head script#BDFDBLibraryScript');
|
|
|
|
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
2018-10-11 10:21:26 +02:00
|
|
|
if (libraryScript) libraryScript.remove();
|
|
|
|
libraryScript = document.createElement("script");
|
2019-05-26 13:55:26 +02:00
|
|
|
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
2018-10-11 10:21:26 +02:00
|
|
|
libraryScript.setAttribute("type", "text/javascript");
|
2019-10-18 10:56:41 +02:00
|
|
|
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
2019-01-17 23:48:29 +01:00
|
|
|
libraryScript.setAttribute("date", performance.now());
|
2019-05-26 13:55:26 +02:00
|
|
|
libraryScript.addEventListener("load", () => {this.initialize();});
|
2018-10-11 10:21:26 +02:00
|
|
|
document.head.appendChild(libraryScript);
|
|
|
|
}
|
2019-01-17 23:48:29 +01:00
|
|
|
else if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
2018-10-11 10:21:26 +02:00
|
|
|
this.startTimeout = setTimeout(() => {this.initialize();}, 30000);
|
|
|
|
}
|
|
|
|
|
|
|
|
initialize () {
|
2019-01-17 23:48:29 +01:00
|
|
|
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
2019-01-22 11:05:54 +01:00
|
|
|
if (this.started) return;
|
2018-10-11 10:21:26 +02:00
|
|
|
BDFDB.loadMessage(this);
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2018-12-28 14:36:04 +01:00
|
|
|
BDFDB.WebModules.forceAllUpdates(this);
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-02-12 21:56:34 +01:00
|
|
|
console.error(`%c[${this.getName()}]%c`, 'color: #3a71c1; font-weight: 700;', '', 'Fatal Error: Could not load BD functions!');
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stop () {
|
2019-01-26 22:45:19 +01:00
|
|
|
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
2018-10-11 10:21:26 +02:00
|
|
|
BDFDB.unloadMessage(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
// begin of own functions
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2019-09-11 12:14:43 +02:00
|
|
|
processChannelTextArea (instance, wrapper, returnvalue) {
|
2019-01-17 23:48:29 +01:00
|
|
|
if (instance.props && instance.props.type) {
|
|
|
|
var textarea = wrapper.querySelector("textarea");
|
|
|
|
if (!textarea) return;
|
|
|
|
BDFDB.addEventListener(this, textarea, "keyup", () => {
|
2018-12-26 22:35:33 +01:00
|
|
|
clearTimeout(textarea.WriteUpperCaseTimeout);
|
|
|
|
textarea.WriteUpperCaseTimeout = setTimeout(() => {
|
|
|
|
let string = textarea.value;
|
|
|
|
if (string.length > 0) {
|
|
|
|
let newstring = string;
|
|
|
|
let first = string.charAt(0);
|
|
|
|
let position = textarea.selectionStart;
|
|
|
|
if (first === first.toUpperCase() && (string.toLowerCase().indexOf("http") == 0 || string.toLowerCase().indexOf("s/") == 0)) newstring = string.charAt(0).toLowerCase() + string.slice(1);
|
|
|
|
else if (first === first.toLowerCase() && first !== first.toUpperCase() && string.toLowerCase().indexOf("http") != 0 && string.toLowerCase().indexOf("s/") != 0) newstring = string.charAt(0).toUpperCase() + string.slice(1);
|
|
|
|
if (string != newstring) {
|
|
|
|
textarea.focus();
|
|
|
|
textarea.selectionStart = 0;
|
|
|
|
textarea.selectionEnd = textarea.value.length;
|
|
|
|
document.execCommand("insertText", false, newstring);
|
|
|
|
textarea.selectionStart = position;
|
|
|
|
textarea.selectionEnd = position;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},1);
|
2018-10-11 10:21:26 +02:00
|
|
|
});
|
2019-01-17 23:48:29 +01:00
|
|
|
}
|
2018-12-26 22:35:33 +01:00
|
|
|
}
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|