This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
81 lines (65 loc) · 2.82 KB
/
index.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
const { Plugin } = require('powercord/entities');
const { getModule, messages } = require('powercord/webpack');
const { forceUpdateElement } = require('powercord/util');
const { inject, uninject } = require('powercord/injector');
const Settings = require('./Settings');
module.exports = class ClickableEdits extends Plugin {
constructor () {
super();
this.currentUserId = null;
this.classes = {
messages: getModule([ 'messages', 'scroller' ], false),
messageContent: getModule([ 'wrapper', 'username' ], false),
container: getModule([ 'container', 'embedWrapper' ], false),
markup: getModule([ 'markup' ], false)
};
Object.keys(this.classes).forEach(key =>
this.classes[key] = `.${this.classes[key][key]}`
);
}
async startPlugin () {
powercord.api.settings.registerSettings('pc-clickableEdits', {
category: this.entityID,
label: 'Clickable Edits',
render: Settings
});
this.getCurrentUser = (await getModule(['getCurrentUser'])).getCurrentUser;
this.patchMessageContent();
}
pluginWillUnload () {
powercord.api.settings.unregisterSettings('pc-clickableEdits');
uninject('clickableEdits-message');
forceUpdateElement(this.classes.messages);
}
async patchMessageContent () {
const renderMessage = (args, res) => {
const { childrenMessageContent: { props: { message } } } = args[0];
if (message && message.author.id === this.getCurrentUser().id) {
res.props.children.props.onMouseUp = this.handleMessageEdit(message.channel_id, message.id, message.content);
}
return res;
};
const Message = await getModule(m => (m.__powercordOriginal_default || m.default)?.toString().includes('childrenRepliedMessage'));
inject('clickableEdits-message', Message, 'default', renderMessage);
Message.default.displayName = 'Message';
forceUpdateElement(this.classes.messages);
}
handleMessageEdit (channel_id, message_id, content) {
const get = (key) => this.settings.get(key, false);
const shiftKey = (e) => e.shiftKey && e.button === (get('rightClickEdits') ? 2 : 0) && e.detail === 1;
const doubleClick = (e) => e.button === (get('rightClickEdits') ? 2 : 0) && e.detail > 1;
let args = [ channel_id, message_id, !get('clearContent') ? content : '' ];
const dualControl = (e) => get('dualControlEdits') && shiftKey(e)
? args = [ channel_id, message_id, '' ]
: doubleClick(e)
? args = [ channel_id, message_id, content ]
: false;
return (e) => {
if (get('dualControlEdits') ? dualControl(e) : get('useShiftKey') ? shiftKey(e) : doubleClick(e)) {
if (e.target.closest(`${this.classes.markup}${this.classes.messageContent}`) || e.target.closest(this.classes.container)) {
messages.startEditMessage(...args);
}
}
};
}
};