This repository was archived by the owner on Apr 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
64 lines (51 loc) · 2.27 KB
/
index.js
File metadata and controls
64 lines (51 loc) · 2.27 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
const { Plugin } = require('powercord/entities');
const { getModule, constants, messages } = require('powercord/webpack');
const { inject, uninject } = require('powercord/injector');
const { findInReactTree } = require('powercord/util');
const Message = getModule(m => (m.__powercordOriginal_default || m.default)?.toString().includes('childrenRepliedMessage'), false);
const { getCurrentUser } = getModule(['getCurrentUser', 'getUser'], false);
const Permissions = getModule(['getChannelPermissions'], false);
const Settings = require('./components/Settings');
module.exports = class QuickDelete extends Plugin {
startPlugin() {
powercord.api.settings.registerSettings(this.entityID, {
category: this.entityID,
label: 'Quick Delete',
render: Settings
});
document.body.addEventListener('keydown', this.keyDown);
document.body.addEventListener('keyup', this.keyUp);
inject('quick-delete', Message, 'default', (args, res) => {
let instance = findInReactTree(res, r => r?.message && r?.channel);
if (instance?.message && instance?.channel) {
const { message, channel } = instance;
const canDelete = (
Permissions.can(constants.Permissions.MANAGE_MESSAGES, channel) ||
getCurrentUser().id === message.author.id
);
let props = res.props.children.props;
props.oldOnClick = props.onClick;
props.onClick = (e) => {
if (props.oldOnClick) props.oldOnClick(e);
if (!this.keybindDown || !canDelete) return;
messages.deleteMessage(channel.id, message.id);
};
};
return res;
});
}
pluginWillUnload() {
uninject('quick-delete');
powercord.api.settings.unregisterSettings(this.entityID);
document.body.removeEventListener('keydown', this.keyDown);
document.body.removeEventListener('keyup', this.keyUp);
}
keyDown = (e) => {
let key = this.settings.get('keybind', 'Control');
if (key.toLowerCase() == e.key.toLowerCase()) this.keybindDown = true;
};
keyUp = (e) => {
let key = this.settings.get('keybind', 'Control');
if (key.toLowerCase() == e.key.toLowerCase()) this.keybindDown = false;
};
};