2018-10-11 10:21:26 +02:00
|
|
|
module.exports = (Plugin, Api, Vendor) => {
|
2019-01-26 22:45:19 +01:00
|
|
|
if (!global.BDFDB || typeof BDFDB != "object") global.BDFDB = {BDv2Api: Api};
|
2018-10-11 10:21:26 +02:00
|
|
|
|
|
|
|
return class extends Plugin {
|
2019-01-26 22:45:19 +01:00
|
|
|
initConstructor () {
|
|
|
|
this.patchModules = {
|
|
|
|
"ChannelTextArea":"componentDidMount",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
onStart () {
|
2019-01-26 22:45:19 +01:00
|
|
|
var libraryScript = document.querySelector('head script[src="https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"]');
|
|
|
|
if (!libraryScript || performance.now() - libraryScript.getAttribute("date") > 600000) {
|
2018-10-11 10:21:26 +02:00
|
|
|
if (libraryScript) libraryScript.remove();
|
|
|
|
libraryScript = document.createElement("script");
|
|
|
|
libraryScript.setAttribute("type", "text/javascript");
|
|
|
|
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js");
|
2019-01-26 22:45:19 +01:00
|
|
|
libraryScript.setAttribute("date", performance.now());
|
|
|
|
libraryScript.addEventListener("load", () => {
|
|
|
|
BDFDB.loaded = true;
|
|
|
|
this.initialize();
|
|
|
|
});
|
2018-10-11 10:21:26 +02:00
|
|
|
document.head.appendChild(libraryScript);
|
|
|
|
}
|
2019-01-26 22:45:19 +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-26 22:45:19 +01:00
|
|
|
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
|
|
|
if (this.started) return true;
|
2018-10-11 10:21:26 +02:00
|
|
|
BDFDB.loadMessage(this);
|
|
|
|
|
2019-01-26 22:45:19 +01:00
|
|
|
BDFDB.WebModules.forceAllUpdates(this);
|
2018-10-11 10:21:26 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
2019-01-24 13:37:08 +01:00
|
|
|
console.error(`%c[${this.name}]%c`, 'color: #3a71c1; font-weight: 700;', '', 'Fatal Error: Could not load BD functions!');
|
2018-10-11 10:21:26 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onStop () {
|
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);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
processChannelTextArea (instance, wrapper) {
|
|
|
|
if (instance.props && instance.props.type) {
|
|
|
|
var textarea = wrapper.querySelector("textarea");
|
|
|
|
if (!textarea) return;
|
|
|
|
BDFDB.addEventListener(this, textarea, "keyup", () => {
|
|
|
|
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
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|