-
Notifications
You must be signed in to change notification settings - Fork 0
/
discord_inject.js
65 lines (55 loc) · 1.9 KB
/
discord_inject.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
let socket = new WebSocket("ws://127.0.0.1:8765");
socket.onopen = function(e) {
Logger.log("[open] Connection established");
Logger.log("Sending to server");
socket.send(JSON.stringify({type:"login",content:"discord client"}));
};
socket.onmessage = function(event) {
Logger.log(`[message] Data received from server: ${event.data}`);
let message = JSON.parse(event.data)
if(message.type == "hotkey"){
if(hotkeyFunctions[message.content]){
Logger.log("Executing hotkeyFunction")
hotkeyFunctions[message.content]()
}else{
Logger.log("No function with this name specified")
}
}
};
socket.onclose = function(event) {
if (event.wasClean) {
Logger.log(`[close] Connection closed cleanly, code=${event.code} reason=${event.reason}`);
} else {
// e.g. server process killed or network down
// event.code is usually 1006 in this case
Logger.log('[close] Connection died');
}
};
socket.onerror = function(error) {
Logger.log(`[error]`);
};
let Logger = {
log(msg){
console.log(`[LOCALHOST WS]${msg}`)
}
}
let hotkeyFunctions = {
leaveCall(){
console.log("[BETTER_DICORD]: leaveCall hotkey function triggered.")
try {
document.querySelector("button[aria-label='Verbindung trennen'").click()
} catch (error) {
console.log("Leve call element not found")
}
},
toggleCamera(){
const cameraOnButton = document.querySelector("button[aria-label='Kamera anschalten']")
const cameraOffButton = document.querySelector("button[aria-label='Kamera ausschalten']")
console.log("[BETTER_DICORD]: toggleCamera hotkey function triggered.")
if(cameraOnButton){
cameraOnButton.click()
}else{
cameraOffButton.click()
}
}
}