This repository was archived by the owner on Aug 13, 2022. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
85 lines (71 loc) · 2.95 KB
/
Copy pathindex.js
File metadata and controls
85 lines (71 loc) · 2.95 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const { Plugin } = require('powercord/entities');
const { getModule, React, FluxDispatcher } = require("powercord/webpack");
const { findInReactTree } = require("powercord/util");
const { inject, uninject } = require("powercord/injector");
const ReactionButton = require("./components/ReactionButton");
let addedListener = false;
let emojiPickerMessage = "";
module.exports = class showAllMessageButtons extends Plugin {
startPlugin() {
this.addButtons();
}
pluginWillUnload() {
uninject("forced-buttons")
document
.querySelectorAll(".reaction-button")
.forEach((e) => (e.style.display = "none"));
}
async addButtons() {
const MiniPopover = await getModule(
(m) => m?.default?.displayName === "MiniPopover"
);
inject("forced-buttons", MiniPopover, "default", (_, res) => {
let props = findInReactTree(res, (r) => r?.message);
if (!props) return res;
// Not sure why I need to do this, but it doesn't work otherwise
props = res.props.children[res.props.children.length-1].props;
props.expanded = true;
if (props.message.id == emojiPickerMessage) {
props.showEmojiPicker = true;
if (!addedListener) {
addedListener = true;
const pickerClick = (event) => {
const onPicker = event.path.filter(
(element) => element.id == "emoji-picker-tab-panel"
).length == 1
if ((onPicker && !event.shiftKey) || !onPicker) {
removePickerClick();
addedListener = false;
emojiPickerMessage = "";
setTimeout(() => {
this.updateMessage(props.message, false);
}, 0);
}
};
const removePickerClick = () => {
document.body.removeEventListener("click", pickerClick);
}
document.body.addEventListener("click", pickerClick);
}
}
if (props.canReact) {
res.props.children.splice(res.props.children.length-1, 0,
React.createElement(ReactionButton, {
showEmojiPicker: (show) => {
this.updateMessage(props.message, show);
}
})
)
}
return res;
});
MiniPopover.default.displayName = "MiniPopover";
}
updateMessage(message, showEmojiPicker) {
emojiPickerMessage = showEmojiPicker ? message.id : "";
FluxDispatcher.dispatch({
type: "MESSAGE_UPDATE",
message,
});
}
}