plugin
This commit is contained in:
parent
3eead33b6a
commit
8889ed1e36
|
@ -5623,11 +5623,10 @@ var BDFDB = {myPlugins: BDFDB && BDFDB.myPlugins || {}, cleanUps: BDFDB && BDFDB
|
|||
render() {
|
||||
let props = Object.assign({}, this.props, {
|
||||
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.charcounter, this.props.className),
|
||||
color: LibraryComponents.TextElement.Colors.PRIMARY,
|
||||
children: this.getCounterString()
|
||||
});
|
||||
BDFDB.ObjectUtils.delete(props, "parsing", "max", "refClass");
|
||||
return BDFDB.ReactUtils.createElement(LibraryComponents.TextElement, props);
|
||||
return BDFDB.ReactUtils.createElement("div", props);
|
||||
}
|
||||
}: LibraryComponents.CharCounter;
|
||||
|
||||
|
@ -6694,6 +6693,10 @@ var BDFDB = {myPlugins: BDFDB && BDFDB.myPlugins || {}, cleanUps: BDFDB && BDFDB
|
|||
opacity: 1;
|
||||
}
|
||||
|
||||
${BDFDB.dotCN.charcounter} {
|
||||
color: var(--channels-default);
|
||||
}
|
||||
|
||||
${BDFDB.dotCN.inputnumberwrapper} {
|
||||
position: relative;
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -3,7 +3,7 @@
|
|||
class CharCounter {
|
||||
getName () {return "CharCounter";}
|
||||
|
||||
getVersion () {return "1.3.6";}
|
||||
getVersion () {return "1.3.7";}
|
||||
|
||||
getAuthor () {return "DevilBro";}
|
||||
|
||||
|
@ -11,14 +11,13 @@ class CharCounter {
|
|||
|
||||
constructor () {
|
||||
this.changelog = {
|
||||
"fixed":[["Light Theme Update","Fixed bugs for the Light Theme Update, which broke 99% of my plugins"]]
|
||||
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
||||
};
|
||||
|
||||
this.patchModules = {
|
||||
"ChannelTextArea":"componentDidMount",
|
||||
"UserPopout":"componentDidMount",
|
||||
"UserProfile":"componentDidMount",
|
||||
"ChangeNickname":"componentDidMount"
|
||||
"ChannelTextArea":"render",
|
||||
"Note":"render",
|
||||
"ChangeNickname":"render"
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -33,54 +32,46 @@ class CharCounter {
|
|||
}
|
||||
|
||||
this.css = `
|
||||
${BDFDB.dotCN.themelight} #charcounter {
|
||||
color: #747f8d;
|
||||
opacity: .7;
|
||||
}
|
||||
${BDFDB.dotCN.themedark} #charcounter {
|
||||
color: #ccc;
|
||||
opacity: .5;
|
||||
}
|
||||
${BDFDB.dotCNS.typing + BDFDB.dotCN.cooldownwrapper} {
|
||||
margin-right: 64px;
|
||||
}
|
||||
.charcounter-added {
|
||||
position: relative !important;
|
||||
}
|
||||
#charcounter {
|
||||
.charcounter {
|
||||
display: block;
|
||||
position: absolute;
|
||||
z-index: 1000;
|
||||
pointer-events: none;
|
||||
font-size: 15px;
|
||||
}
|
||||
#charcounter.normal {
|
||||
.charcounter.normal {
|
||||
right: 0;
|
||||
bottom: -1.3em;
|
||||
}
|
||||
#charcounter.edit {
|
||||
.charcounter.edit {
|
||||
left: 0;
|
||||
bottom: -1.3em;
|
||||
}
|
||||
#charcounter.form {
|
||||
.charcounter.form {
|
||||
right: 0;
|
||||
bottom: -1.0em;
|
||||
}
|
||||
#charcounter.nickname {
|
||||
.charcounter.nickname {
|
||||
right: 0 !important;
|
||||
top: 0 !important;
|
||||
}
|
||||
#charcounter.popout {
|
||||
.charcounter.popout {
|
||||
right: 3px !important;
|
||||
bottom: 1px !important;
|
||||
bottom: -8px !important;
|
||||
font-size: 10px !important;
|
||||
}
|
||||
#charcounter.profile {
|
||||
right: -5px !important;
|
||||
bottom: 3px !important;
|
||||
.charcounter.profile {
|
||||
right: 0 !important;
|
||||
bottom: -10px !important;
|
||||
font-size: 12px !important;
|
||||
}
|
||||
${BDFDB.dotCN.usernote} textarea:not(:focus) + #charcounter {
|
||||
${BDFDB.dotCN.usernote} textarea:not(:focus) + .charcounter {
|
||||
display: none;
|
||||
}`;
|
||||
}
|
||||
|
@ -121,8 +112,8 @@ class CharCounter {
|
|||
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
||||
this.stopping = true;
|
||||
|
||||
BDFDB.DOMUtils.remove(".charcounter");
|
||||
BDFDB.DOMUtils.removeClassFromDOM("charcounter-added");
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
|
||||
BDFDB.PluginUtils.clear(this);
|
||||
}
|
||||
}
|
||||
|
@ -130,40 +121,44 @@ class CharCounter {
|
|||
|
||||
// begin of own functions
|
||||
|
||||
processChannelTextArea (instance, wrapper, returnvalue) {
|
||||
if (instance.props && instance.props.type && this.maxLenghts[instance.props.type]) this.appendCounter(wrapper.querySelector("textarea"), instance.props.type, true);
|
||||
processChannelTextArea (e) {
|
||||
if (!this.stopping && e.instance.props && e.instance.props.type && this.maxLenghts[e.instance.props.type]) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: "TextAreaAutosize"});
|
||||
if (index > -1) this.injectCounter(e.returnvalue, children, e.instance.props.type, BDFDB.dotCN.textarea, true);
|
||||
}
|
||||
}
|
||||
|
||||
processNote (instance, wrapper, returnvalue) {
|
||||
this.appendCounter(wrapper.firstElementChild, BDFDB.DOMUtils.containsClass(wrapper, BDFDB.disCN.usernotepopout) ? "popout" : (BDFDB.DOMUtils.containsClass(wrapper, BDFDB.disCN.usernoteprofile) ? "profile" : null), false);
|
||||
processNote (e) {
|
||||
if (!this.stopping) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: "TextAreaAutosize"});
|
||||
if (index > -1) this.injectCounter(e.returnvalue, children, e.instance.props.className && e.instance.props.className.indexOf(BDFDB.disCN.usernotepopout) > -1 ? "popout" : "profile", "textarea");
|
||||
}
|
||||
}
|
||||
|
||||
processUserPopout (instance, wrapper, returnvalue) {
|
||||
this.appendCounter(wrapper.querySelector(BDFDB.dotCN.usernote).firstElementChild, "popout", false);
|
||||
processChangeNickname (e) {
|
||||
if (!this.stopping) {
|
||||
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name: "TextInput"});
|
||||
if (index > -1) this.injectCounter(e.returnvalue, children, "nickname", BDFDB.dotCN.input);
|
||||
}
|
||||
}
|
||||
|
||||
processUserProfile (instance, wrapper, returnvalue) {
|
||||
this.appendCounter(wrapper.querySelector(BDFDB.dotCN.usernote).firstElementChild, "profile", false);
|
||||
}
|
||||
|
||||
processChangeNickname (instance, wrapper, returnvalue) {
|
||||
let reset = wrapper.querySelector(BDFDB.dotCN.reset);
|
||||
if (reset && BDFDB.DOMUtils.getText(reset.firstElementChild) == BDFDB.LanguageUtils.LanguageStrings.RESET_NICKNAME) this.appendCounter(wrapper.querySelector(BDFDB.dotCN.inputdefault), "nickname", false);
|
||||
|
||||
injectCounter (parent, children, type, refClass, parsing) {
|
||||
if (!children) return;
|
||||
parent.props.className += " charcounter-added";
|
||||
children.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CharCounter, {
|
||||
className: `charcounter ${type}`,
|
||||
refClass: refClass,
|
||||
parsing: parsing,
|
||||
max: this.maxLenghts[type]
|
||||
}));
|
||||
}
|
||||
|
||||
appendCounter (input, type, parsing) {
|
||||
if (!input || !type) return;
|
||||
BDFDB.DOMUtils.remove(input.parentElement.querySelectorAll("#charcounter"));
|
||||
BDFDB.DOMUtils.remove(input.parentElement.querySelectorAll(".charcounter"));
|
||||
var counter = BDFDB.DOMUtils.create(`<div id="charcounter" class="charcounter ${type}"></div>`);
|
||||
input.parentElement.appendChild(counter);
|
||||
|
||||
var updateCounter = () => {
|
||||
var inputlength = parsing ? BDFDB.StringUtils.getParsedLength(input.value) : input.value.length;
|
||||
var seleclength = input.selectionEnd - input.selectionStart == 0 ? 0 : (parsing ? BDFDB.StringUtils.getParsedLength(input.value.slice(input.selectionStart, input.selectionEnd)) : (input.selectionEnd - input.selectionStart));
|
||||
seleclength = !seleclength ? 0 : (seleclength > inputlength ? inputlength - (inputlength - input.selectionEnd - input.selectionStart) : seleclength);
|
||||
counter.innerText = inputlength + "/" + (this.maxLenghts[type] || 2000) + (!seleclength ? "" : " (" + seleclength + ")");
|
||||
};
|
||||
|
||||
BDFDB.DOMUtils.addClass(input.parentElement.parentElement, "charcounter-added");
|
||||
if (type == "nickname") input.setAttribute("maxlength", 32);
|
||||
BDFDB.ListenerUtils.add(this, input, "keydown click change", e => {
|
||||
|
@ -173,11 +168,11 @@ class CharCounter {
|
|||
BDFDB.ListenerUtils.add(this, input, "mousedown", e => {
|
||||
BDFDB.ListenerUtils.add(this, document, "mouseup", () => {
|
||||
BDFDB.ListenerUtils.remove(this, document);
|
||||
if (input.selectionEnd - input.selectionStart) setImmediate(() => {BDFDB.ListenerUtils.add(this, document, "click", () => {
|
||||
if (this.props.end - input.selectionStart) setImmediate(() => {BDFDB.ListenerUtils.add(this, document, "click", () => {
|
||||
var contexttype = BDFDB.ReactUtils.getValue(document.querySelector(BDFDB.dotCN.contextmenu), "return.stateNode.props.type");
|
||||
if (!contexttype || !contexttype.startsWith("CHANNEL_TEXT_AREA")) {
|
||||
input.selectionStart = 0;
|
||||
input.selectionEnd = 0;
|
||||
this.props.end = 0;
|
||||
updateCounter();
|
||||
}
|
||||
else setTimeout(() => {updateCounter();},100);
|
||||
|
|
Loading…
Reference in New Issue