-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
52 lines (40 loc) · 1.38 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
const { Plugin } = require('powercord/entities');
const { React, getModule } = require('powercord/webpack');
const { inject, uninject } = require('powercord/injector');
const { findInReactTree } = require('powercord/util');
const Timer = require('./Timer.jsx');
/**
* Shows how much time has passed since you joined a voice channel.
* @link https://github.com/RazerMoon/vcTimer
* @license MIT
* @extends Plugin
*/
module.exports = class VCTimer extends Plugin {
startPlugin () {
this.patchPanel();
}
async patchPanel () {
const PanelSubtext = await getModule((m) => (m.__powercordOriginal_default || m.default)?.displayName === 'PanelSubtext');
inject('vcTimer-panel-patch', PanelSubtext, 'default', (args) => {
const [ { className } ] = args;
if (!className || !className.includes('channel')) {
return args;
}
const hasTimer = findInReactTree(args[0].children, child => child.props && child.props.id === 'timer');
if (!hasTimer) {
const TimerItem = React.createElement(Timer, {
id: 'timer'
});
if (!Array.isArray(args[0].children)) {
args[0].children = [ args[0].children ];
}
args[0].children.push(TimerItem);
}
return args;
}, true);
PanelSubtext.default.displayName = 'PanelSubtext';
}
pluginWillUnload () {
uninject('vcTimer-panel-patch');
}
};