This repository has been archived by the owner on Jul 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (45 loc) · 1.55 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
/*
* Copyright (c) 2020 Bowser65
* Licensed under the Open Software License version 3.0
* Original work under MIT; See LICENSE.
*/
const { Plugin } = require('powercord/entities');
const { React, FluxDispatcher, getModule } = require('powercord/webpack');
const { findInReactTree } = require('powercord/util');
const { inject, uninject } = require('powercord/injector');
const BlockButton = require('./components/BlockButton');
const { getMessage } = getModule([ 'getMessages' ], false);
module.exports = class BlockMessages extends Plugin {
async startPlugin () {
this.loadStylesheet('style.scss');
const MiniPopover = getModule(m => m?.default?.displayName === 'MiniPopover', false);
inject('block-messages-button', MiniPopover, 'default', (_, res) => {
const props = findInReactTree(res, r => r?.message);
if (!props) {
return res;
}
res.props.children.unshift(
React.createElement(BlockButton, {
message: props.message,
onToggle: () => this.updateMessage(props.message)
})
);
return res;
});
MiniPopover.default.displayName = 'MiniPopover';
}
pluginWillUnload () {
uninject('block-messages-button');
}
updateMessage (message) {
FluxDispatcher.dirtyDispatch({
type: 'MESSAGE_UPDATE',
message
});
// weird fix but it works lol
setTimeout(() => {
document.querySelector('[id^=chat-message] > * > *').click();
document.querySelector('main').click();
}, 5);
}
};