forked from Inve1951/BetterDiscordStuff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clearInputOnEsc.plugin.js
54 lines (41 loc) · 1.56 KB
/
clearInputOnEsc.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
//META{"name":"clearInputOnEsc"}*//
var clearInputOnEsc = (function(){
var TextArea, cancel, install;
class clearInputOnEsc {
getName(){ return "Clear-Input-on-Escape" }
getDescription(){ return "Clears chat inputs when hitting escape inside it." }
getVersion(){ return "1.3.0" }
getAuthor(){ return "square" }
load(){}
start(){
if(!install()) this.onSwitch = install;
}
stop(){
cancel && cancel();
cancel = this.onSwitch = void 0;
}
}
install = function() {
var ta;
if(!TextArea) TextArea = BDV2.WebpackModules.find(m=>m.prototype&&["calculateNodeStyling"].every(p=>null!=m.prototype[p]));
if(!TextArea) return false;
delete this.onSwitch;
cancel = Utils.monkeyPatch(TextArea.prototype, "render", {after: function({thisObject, returnValue: ta}) {
if("textarea" !== ta.type) ({props: {children: [ta]}} = ta); // CharacterCounter support
if(!ta || "textarea" !== ta.type || null == ta.props.value) return;
Utils.monkeyPatch(ta.props, "onKeyDown", {silent: true, instead: function({methodArguments: [ev], callOriginalMethod}) {
if("Escape" !== ev.key || !thisObject.props.value) return callOriginalMethod();
ev.type = "change";
ev.value = thisObject._textArea.value = "";
ev.preventDefault();
ev.stopPropagation();
thisObject.handleChange(ev);
}});
}});
if(ta = document.querySelector("form textarea")) try {
getInternalInstance(ta).forceUpdate();
} catch (e) {}
return true;
};
return clearInputOnEsc;
})();