Plugin
CharCounter
Adds a Character Counter to most Inputs
Installation: Datei herunterladen und in deinen BetterDiscord-Ordner legen —
%appdata%\\BetterDiscord\\plugins
(Windows) bzw. über Discord: Einstellungen → Plugins → Plugin-Ordner öffnen.
CharCounter.plugin.js · 268 Zeilen · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/*
FILE META START
name: CharCounter.plugin.js
version: 0.0.10
description: Multi-surface admin, cloud, bot host, login, and secure chat server.
lastModified: 2026-05-04T20:22:59.633Z
checksum: dabd96aa25d48fb514bcbb498ea38e12c56043436192b77c3c312231b7b89854
FILE META END
*/
/**
* @name CharCounter
* @author HeadX
* @authorId 808385710700494919
* @description Adds a Character Counter to most Inputs
* @version 1.7.2
* @invite J6wTJJ5fp
* @website https://headcraft.cloud/better-discord
* @source https://headcraft.cloud/better-discord/CharCounter.plugin.js
* @updateUrl https://headcraft.cloud/better-discord/CharCounter.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.UI.showToast("Finished downloading BDFDB Library", {type: "success"}));
}).catch(error => {
BdApi.UI.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.UI.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 = `<div style="color: var(--text-strong); font-size: 16px; font-weight: 300; white-space: pre; line-height: 22px;">The Library Plugin needed for ${this.name} is missing.\nPlease click <a style="font-weight: 500;">Download Now</a> to install it.</div>`;
template.content.firstElementChild.querySelector("a").addEventListener("click", this.downloadLibrary);
return template.content.firstElementChild;
}
} : (([Plugin, BDFDB]) => {
const maxLengths = {
customstatus: 128,
popoutnote: 256,
profilenote: 256
};
const typeMap = {
normal: "chat",
form: "upload",
sidebar: "chat",
thread_creation: "threadcreation",
user_profile: "userprofile"
};
const nativeCounters = ["profile_bio_input"];
return class CharCounter extends Plugin {
onLoad () {
this.modulePatches = {
after: [
"ChannelTextAreaContainer",
"CustomStatusModalWithPreview",
"Note"
]
};
this.defaults = {
sliders: {
showPercentage: {value: 0, description: "Only shows Counter after certain % of Max Length is reached"}
},
switches: {
performanceMode: {value: false, description: "Disable character counters to reduce CPU usage"}
}
};
this.css = `
${BDFDB.dotCN._charcountercounteradded} {
position: relative !important;
width: 100%;
}
${BDFDB.dotCN._charcountercounter} {
display: block;
position: absolute;
font-size: 15px;
z-index: 10;
pointer-events: none;
}
${BDFDB.dotCN._charcounterchatcounter} {
right: 0.15em;
bottom: 0.75em;
font-size: 12px;
}
${BDFDB.dotCN._charcountereditcounter} {
right: 0;
bottom: -1.3em;
}
${BDFDB.dotCN._charcounterthreadcreationcounter} {
right: 16px;
bottom: 0.3em;
}
${BDFDB.dotCN._charcounteruserprofilecounter} {
right: 0;
bottom: -1.3em;
font-size: 12px;
}
${BDFDB.dotCN._charcountercustomstatuscounter} {
right: 0 !important;
top: -1.5em;
}
${BDFDB.dotCN._charcounterpopoutnotecounter} {
right: 3px !important;
bottom: -8px !important;
font-size: 10px !important;
}
${BDFDB.dotCN._charcounterprofilenotecounter} {
right: 0 !important;
bottom: -10px !important;
font-size: 12px !important;
}
${BDFDB.dotCN.channelsettingstopiccontainer} ~ ${BDFDB.dotCN._charcountercounter},
${BDFDB.dotCN.usernotetextarea}:not(:focus) ~ ${BDFDB.dotCN._charcountercounter},
${BDFDB.dotCNS.userpopoutouter + BDFDB.dotCN.textareawrapall}:not(:focus-within) ~ ${BDFDB.dotCN._charcountercounter} {
display: none;
}
`;
}
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.sliders) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
type: "Slider",
plugin: this,
keys: ["sliders", key],
basis: "30%",
label: this.defaults.sliders[key].description,
value: this.settings.sliders[key]
}));
for (let key in this.defaults.switches) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
type: "Switch",
plugin: this,
keys: ["switches", key],
label: this.defaults.switches[key].description,
value: this.settings.switches[key]
}));
return settingsItems;
}
});
}
onSettingsClosed () {
if (this.SettingsUpdated) {
delete this.SettingsUpdated;
BDFDB.PatchUtils.forceAllUpdates(this);
}
}
processChannelTextAreaContainer (e) {
if (this.settings.switches.performanceMode) return;
let editorContainer = BDFDB.ReactUtils.findChild(e.returnvalue, {name: "ChannelTextAreaEditor"});
if (editorContainer && editorContainer.props.type && !editorContainer.props.disabled) {
if (!BDFDB.ArrayUtils.is(e.returnvalue.props.children)) e.returnvalue.props.children = [e.returnvalue.props.children];
this.injectCounter(e.returnvalue, e.returnvalue.props.children, editorContainer.props.type.analyticsName || editorContainer.props.type, BDFDB.dotCN.textarea);
}
}
processNote (e) {
if (this.settings.switches.performanceMode) return;
let [children, index] = BDFDB.ReactUtils.findParent(e.returnvalue, {filter: n => n && n.props && n.props.autoCorrect != undefined});
if (index > -1) this.injectCounter(e.returnvalue, children, e.instance.props.className && e.instance.props.className.indexOf(BDFDB.disCN.usernotepopout) > -1 ? "popoutnote" : "profilenote", "textarea");
}
processNicknameSection (e) {
if (this.settings.switches.performanceMode) return;
e.returnvalue.props.children = BDFDB.ReactUtils.createElement("div", {
className: BDFDB.disCN._charcountercounteradded,
children: [
e.returnvalue.props.children,
BDFDB.ReactUtils.createElement("div", {
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.charcounter, BDFDB.disCN._charcountercounter, BDFDB.disCN._charcounternickcounter),
children: `${(e.instance.props.pendingNick || "").length}/${maxLengths.nick}`
})
].flat(10)
});
}
processCustomStatusModalWithPreview (e) {
if (this.settings.switches.performanceMode) return;
let formItem = BDFDB.ReactUtils.findChild(e.returnvalue, {props: [["className", BDFDB.disCN.emojiinputcontainer]]});
if (formItem) this.injectCounter(formItem, formItem.props.children, "customstatus", BDFDB.dotCN.input);
}
injectCounter (parent, children, type, refClass, parsing) {
if (!children || nativeCounters.indexOf(type) > -1) return;
if (parent.props.className) parent.props.className = BDFDB.DOMUtils.formatClassName(parent.props.className, BDFDB.disCN._charcountercounteradded);
else parent.props.children = BDFDB.ReactUtils.createElement("div", {
className: BDFDB.disCN._charcountercounteradded,
children: parent.props.children
});
children.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CharCounter, {
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN._charcountercounter, type && BDFDB.DiscordClasses[`_charcounter${typeMap[type] || type}counter`] && BDFDB.disCN[`_charcounter${typeMap[type] || type}counter`]),
refClass: refClass,
parsing: parsing,
max: maxLengths[type] || (BDFDB.LibraryModules.NitroUtils.canUseIncreasedMessageLength(BDFDB.LibraryStores.UserStore.getCurrentUser()) ? BDFDB.DiscordConstants.MAX_MESSAGE_LENGTH_PREMIUM : BDFDB.DiscordConstants.MAX_MESSAGE_LENGTH),
showPercentage: this.settings.sliders.showPercentage,
style: {visibility: "hidden"},
onChange: instance => {
let node = BDFDB.ReactUtils.findDOMNode(instance);
node && node.style.removeProperty("visibility");
let form = node && BDFDB.DOMUtils.getParent(BDFDB.dotCN.chatform, node);
if (form) {
let widthDifference = BDFDB.DOMUtils.getWidth(form.firstElementChild) - BDFDB.DOMUtils.getWidth(node.parentElement);
if (widthDifference > 0) node.style.setProperty("right", `-${widthDifference}px`);
let typing = form.querySelector(BDFDB.dotCN.typing);
if (typing) typing.style.setProperty("margin-right", `${BDFDB.DOMUtils.getWidth(node) + 10}px`);
}
}
}));
}
};
})(window.BDFDB_Global.PluginUtils.buildPlugin(changeLog));
})();