forked from Inve1951/BetterDiscordStuff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CharacterCounter.plugin.js
99 lines (81 loc) · 2.77 KB
/
CharacterCounter.plugin.js
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
//META { "name": "CharCounter", "website": "https://inve1951.github.io/BetterDiscordStuff/" } *//
var CharCounter = (function (){
var CharacterCounter, TextArea, cancel, install, css, React, getOwnerInstance;
class CharCounter {
getName() { return "Character Counter"; }
getDescription() { return "Adds a character counter to chat inputs."; }
getAuthor() { return "square"; };
getVersion() { return "2.1.0"; }
load() {
return window.SuperSecretSquareStuff != null ? window.SuperSecretSquareStuff : window.SuperSecretSquareStuff = new Promise(function (c, r) {
return require("request").get("https://raw.githubusercontent.com/Inve1951/BetterDiscordStuff/master/plugins/0circle.plugin.js", function (err, res, body) {
if (err || 200 !== (res != null ? res.statusCode : void 0)) {
return r(err != null ? err : res);
}
Object.defineProperties(window.SuperSecretSquareStuff, {
libLoaded: {
value: c
},
code: {
value: body
}
});
return (0, eval)(body);
});
});
}
async start() {
({getOwnerInstance, React} = await SuperSecretSquareStuff);
if(!install()) this.onSwitch = install;
BdApi.injectCSS("css_charCounter", css);
}
stop() {
BdApi.clearCSS("css_charCounter");
cancel && cancel();
cancel = null;
}
}
install = function() {
var ta;
if(!TextArea) TextArea = BDV2.WebpackModules.find(m=>m.prototype&&["calculateNodeStyling"].every(p=>null!=m.prototype[p]));
if(!TextArea || !React) return false;
delete this.onSwitch;
cancel = Utils.monkeyPatch(TextArea.prototype, "render", {after: function(data) {
data.returnValue = React.createElement(
React.Fragment, null, data.returnValue, React.createElement(CharacterCounter, {value: data.thisObject.props.value})
);
}});
if(ta = document.querySelector("form textarea")) try {
getOwnerInstance(ta).forceUpdate();
} catch (e) {}
return true;
};
CharacterCounter = function({value}) {
if(null == value) return null;
var {length} = value.trim();
return React.createElement(
"span", {id: "charcounter", className: 2000 < length && "over2k"}, `${length}/2000`
);
};
css = `
#charcounter {
color: rgba(255, 255, 255, .5);
user-select: none;
pointer-events: none;
display: block;
position: absolute;
right: 5px; bottom: -1.1em;
z-index: 1;
}
.message-1PNnaP #charcounter {
right: unset;
left: 5px;
}
#charcounter.over2k {
color: rgba(240,71,71,.8);
}
.uploadModal-2ifh8j #charcounter.over2k {
color: rgba(172,10,10,.8);
}`;
return CharCounter;
})();