-
Notifications
You must be signed in to change notification settings - Fork 533
/
QuickDeleteMessages.plugin.js
117 lines (100 loc) · 3.55 KB
/
QuickDeleteMessages.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//META { "name": "QuickDeleteMessages", "website": "https://inve1951.github.io/BetterDiscordStuff/" } *//
global.QuickDeleteMessages = function () {
var AsyncKeystate, EndpointMessages, MessagePrompts, Permissions, UserStore, _qualifies, getOwnerInstance, gotDeletePermission, onClick, settings;
class QuickDeleteMessages {
getName() {
return "Quick Delete Messages";
}
getDescription() {
return "Hold Delete and click a message to delete it.";
}
getAuthor() {
return "square";
}
getVersion() {
return "1.4.2";
}
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() {
var ref;
({ AsyncKeystate, getOwnerInstance } = await SuperSecretSquareStuff);
settings.confirm = (ref = BdApi.getData("QuickDeleteMessages", "confirm")) != null ? ref : false;
if (UserStore == null) {
UserStore = BdApi.findModuleByProps("getCurrentUser");
}
if (Permissions == null) {
Permissions = BdApi.findModuleByProps("computePermissions");
}
if (EndpointMessages == null) {
EndpointMessages = BdApi.findModuleByProps("deleteMessage");
}
if (MessagePrompts == null) {
MessagePrompts = BdApi.findModuleByProps("confirmDelete");
}
return document.addEventListener("click", onClick, true);
}
stop() {
return document.removeEventListener("click", onClick, true);
}
getSettingsPanel() {
return `<label style="color: #87909C"><input type="checkbox" name="confirm" onChange="QuickDeleteMessages.updateSettings(this)"\n${settings.confirm && "checked" || ""} />confirm delete?</label>`;
}
static updateSettings({ name, checked }) {
settings[name] = checked;
BdApi.saveData("QuickDeleteMessages", name, checked);
}
};
settings = Object.create(null);
Permissions = UserStore = EndpointMessages = MessagePrompts = null;
AsyncKeystate = getOwnerInstance = null;
_qualifies = ".message-2qnXI6";
onClick = function (event) {
var channel, element, message, shiftKey;
if (!(AsyncKeystate.key("Delete") || "darwin" === process.platform && AsyncKeystate.key("Backspace"))) {
return;
}
({
path: [element],
shiftKey
} = event);
if (!(element.matches(_qualifies) || (element = element.closest(_qualifies)))) {
return;
}
({
props: { channel, message }
} = SuperSecretSquareStuff.ReactDom._internal.ReactDOMComponentTree.getClosestInstanceFromNode(element).return.pendingProps.childrenAccessories);
if (!gotDeletePermission(channel, message)) {
return;
}
if (settings.confirm && !shiftKey) {
MessagePrompts.confirmDelete(channel, message, false);
} else {
EndpointMessages.deleteMessage(channel.id, message.id, false);
}
event.preventDefault();
event.stopImmediatePropagation();
};
gotDeletePermission = function (channel, message) {
var self;
self = UserStore.getCurrentUser();
return self === message.author || 0x2000 & Permissions.computePermissions(self, channel);
};
return QuickDeleteMessages;
}.call(this);