-
Notifications
You must be signed in to change notification settings - Fork 357
/
DoubleClickVoiceChannels.plugin.js
139 lines (118 loc) · 4.38 KB
/
DoubleClickVoiceChannels.plugin.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* @name DoubleClickVoiceChannels
* @invite yNqzuJa
* @authorLink https://github.com/Metalloriff
* @donate https://www.paypal.me/israelboone
* @website https://metalloriff.github.io/toms-discord-stuff/
* @source https://github.com/Metalloriff/BetterDiscordPlugins/blob/master/DoubleClickVoiceChannels.plugin.js
*/
module.exports = (() => {
const config =
{
info:
{
name: "DoubleClickVoiceChannels",
authors:
[
{
name: "Metalloriff",
discord_id: "264163473179672576",
github_username: "metalloriff",
twitter_username: "Metalloriff"
}
],
version: "2.0.4",
description: "Requires you to double click voice channels to join them.",
github: "https://github.com/Metalloriff/BetterDiscordPlugins/blob/master/DoubleClickVoiceChannels.plugin.js",
github_raw: "https://raw.githubusercontent.com/Metalloriff/BetterDiscordPlugins/master/DoubleClickVoiceChannels.plugin.js"
},
changelog:
[
{
title: "Patched",
type: "fixed",
items: ["Fixed again. Thanks cmd430 for the help!"]
}
]
};
return !global.ZeresPluginLibrary ? class {
constructor() { this._config = config; }
getName = () => config.info.name;
getAuthor = () => config.info.description;
getVersion = () => config.info.version;
load() {
BdApi.showConfirmationModal("Library Missing", `The library plugin needed for ${config.info.name} is missing. Please click Download Now to install it.`, {
confirmText: "Download Now",
cancelText: "Cancel",
onConfirm: () => {
require("request").get("https://rauenzi.github.io/BDPluginLibrary/release/0PluginLibrary.plugin.js", async (err, res, body) => {
if (err) return require("electron").shell.openExternal("https://betterdiscord.net/ghdl?url=https://raw.githubusercontent.com/rauenzi/BDPluginLibrary/master/release/0PluginLibrary.plugin.js");
await new Promise(r => require("fs").writeFile(require("path").join(BdApi.Plugins.folder, "0PluginLibrary.plugin.js"), body, r));
});
}
});
}
start() { }
stop() { }
} : (([Plugin, Api]) => {
const plugin = (Plugin, Api) => {
const { WebpackModules, Patcher, Utilities, ReactComponents } = Api;
return class DoubleClickVoiceChannels extends Plugin {
constructor() {
super();
}
async showChangelog(footer) {
try { footer = (await WebpackModules.getByProps("getUser", "acceptAgreements").getUser("264163473179672576")).tag + " | https://discord.gg/yNqzuJa"; }
finally { super.showChangelog(footer); }
}
async onStart() {
const { component: ChannelItem } = await ReactComponents.getComponentByName("VoiceChannel", "*");
if (ChannelItem) {
Patcher.after(ChannelItem.prototype, "render", (r, _, el) => {
const children_type0 = Utilities.getNestedProp(el, "props.children.props.children.0.props.children.props.children");
const children_type1 = Utilities.getNestedProp(el, "props.children.0.props.children.props.children");
if (children_type0 || children_type1) {
const handleClick = (children) => {
const c = children();
const handler = c.props.children;
c.props.children = () => {
const h = handler({});
if (!h.props.connected) {
// for whatever reason, onDoubleClick stopped working, so here's a dumb workaround
const onClick = h.props.onClick;
let t = performance.now() - 200;
h.props.onClick = () => {
if (performance.now() - t < 200)
onClick();
t = performance.now();
};
}
return h;
};
return c;
};
if (children_type0) {
el.props.children.props.children[0].props.children.props.children = () => {
return handleClick(children_type0);
};
}
if (children_type1) {
el.props.children[0].props.children.props.children = () => {
return handleClick(children_type1);
};
};
}
else {
console.warn("DoubleClickVoiceChannel: Failed to get nested props!");
}
});
}
}
onStop() {
Patcher.unpatchAll();
}
}
};
return plugin(Plugin, Api);
})(global.ZeresPluginLibrary.buildPlugin(config));
})();