forked from Metalloriff/BetterDiscordPlugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDoubleClickVoiceChannels.plugin.js
78 lines (60 loc) · 2.6 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
//META{"name":"DoubleClickVoiceChannels","website":"https://metalloriff.github.io/toms-discord-stuff/","source":"https://github.com/Metalloriff/BetterDiscordPlugins/blob/master/DoubleClickVoiceChannels.plugin.js"}*//
class DoubleClickVoiceChannels {
getName() { return "DoubleClickVoiceChannels"; }
getDescription() { return "Requires you to double click voice channels to connect to them."; }
getVersion() { return "0.0.2"; }
getAuthor() { return "Metalloriff"; }
getChanges() {
return {
};
}
load() {}
start() {
let libLoadedEvent = () => {
try { this.onLibLoaded(); }
catch (err) { console.error(this.getName(), "fatal error, plugin could not be started!", err); try { this.stop(); } catch (err) { console.error(this.getName() + ".stop()", err); }}
};
let lib = document.getElementById("NeatoBurritoLibrary");
if (!lib) {
lib = document.createElement("script");
lib.id = "NeatoBurritoLibrary";
lib.type = "text/javascript";
lib.src = "https://rawgit.com/Metalloriff/BetterDiscordPlugins/master/Lib/NeatoBurritoLibrary.js";
document.head.appendChild(lib);
}
this.forceLoadTimeout = setTimeout(libLoadedEvent, 30000);
if (typeof window.NeatoLib !== "undefined") libLoadedEvent();
else lib.addEventListener("load", libLoadedEvent);
}
getSettingsPanel() {
setTimeout(() => {
NeatoLib.Settings.pushElement(NeatoLib.Settings.Elements.createNewTextField("Double click time (ms)", this.settings.delay, e => {
if (isNaN(e.target.value)) return NeatoLib.showToast("Value must be a number", "error");
this.settings.delay = e.target.value;
this.saveSettings();
}), this.getName(), { tooltip: "The amount of time in milliseconds to wait for the next click" })
NeatoLib.Settings.pushChangelogElements(this);
}, 0);
return NeatoLib.Settings.Elements.pluginNameLabel(this.getName());
}
saveSettings() { NeatoLib.Settings.save(this); }
onLibLoaded() {
this.settings = NeatoLib.Settings.load(this, {
displayUpdateNotes: true,
delay: 250
});
NeatoLib.Updates.check(this);
//if (this.settings.displayUpdateNotes) NeatoLib.Changelog.compareVersions(this.getName(), this.getChanges());
let lastAttempt = 0;
this.unpatchSelect = NeatoLib.monkeyPatchInternal(NeatoLib.Modules.get("selectChannel"), "selectVoiceChannel", e => {
if (performance.now() - lastAttempt <= this.settings.delay || e.args[0] == null) {
e.callDefault();
lastAttempt = 0;
} else lastAttempt = performance.now();
});
NeatoLib.Events.onPluginLoaded(this);
}
stop() {
this.unpatchSelect();
}
}