-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
138 lines (131 loc) · 5.18 KB
/
index.ts
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
import definePlugin, { OptionType } from "@utils/types";
import { Settings } from "Vencord";
const packs = {
"OperaGX": {
click1: new Audio("https://github.com/Domis-Vencord-Plugins/KeyboardSounds/raw/main/sounds/OperaGX/click1.wav"),
click2: new Audio("https://github.com/Domis-Vencord-Plugins/KeyboardSounds/raw/main/sounds/OperaGX/click2.wav"),
click3: new Audio("https://github.com/Domis-Vencord-Plugins/KeyboardSounds/raw/main/sounds/OperaGX/click3.wav"),
backspace: new Audio("https://github.com/Domis-Vencord-Plugins/KeyboardSounds/raw/main/sounds/OperaGX/backspace.wav"),
allowedKeys: []
},
"osu": {
caps: new Audio("https://github.com/Domis-Vencord-Plugins/KeyboardSounds/raw/main/sounds/osu/key-caps.mp3"),
enter: new Audio("https://github.com/Domis-Vencord-Plugins/KeyboardSounds/raw/main/sounds/osu/key-confirm.mp3"),
backspace: new Audio("https://github.com/Domis-Vencord-Plugins/KeyboardSounds/raw/main/sounds/osu/key-delete.mp3"),
arrow: new Audio("https://github.com/Domis-Vencord-Plugins/KeyboardSounds/raw/main/sounds/osu/key-movement.mp3"),
click1: new Audio("https://github.com/Domis-Vencord-Plugins/KeyboardSounds/raw/main/sounds/osu/key-press-1.mp3"),
click2: new Audio("https://github.com/Domis-Vencord-Plugins/KeyboardSounds/raw/main/sounds/osu/key-press-2.mp3"),
click3: new Audio("https://github.com/Domis-Vencord-Plugins/KeyboardSounds/raw/main/sounds/osu/key-press-3.mp3"),
click4: new Audio("https://github.com/Domis-Vencord-Plugins/KeyboardSounds/raw/main/sounds/osu/key-press-4.mp3"),
allowedKeys: [
"CapsLock",
"ArrowUp",
"ArrowRight",
"ArrowLeft",
"ArrowDown"
]
}
};
const ignoredKeys = [
"CapsLock",
"ShiftLeft",
"ShiftRight",
"ControlLeft",
"ControlRight",
"AltLeft",
"AltRight",
"MetaLeft",
"MetaRight",
"ArrowUp",
"ArrowRight",
"ArrowLeft",
"ArrowDown",
"MediaPlayPause",
"MediaStop",
"MediaTrackNext",
"MediaTrackPrevious",
"MediaSelect",
"MediaEject",
"MediaVolumeUp",
"MediaVolumeDown",
"AudioVolumeUp",
"AudioVolumeDown"
];
const getActiveSoundPack = () => Settings.plugins.KeyboardSounds.pack;
const keydown = (e: KeyboardEvent) => {
const currentPack = packs[getActiveSoundPack()];
if (ignoredKeys.includes(e.code) && !currentPack.allowedKeys.includes(e.code)) return;
for (const sound of Object.values(currentPack))
if (sound instanceof Audio) sound.pause();
switch (e.code) {
case "Enter":
currentPack.enter.currentTime = 0;
currentPack.enter.play();
break;
case "Backspace":
currentPack.backspace.currentTime = 0;
currentPack.backspace.play();
break;
case "CapsLock":
currentPack.caps.currentTime = 0;
currentPack.caps.play();
break;
case "ArrowUp":
case "ArrowRight":
case "ArrowLeft":
case "ArrowDown":
currentPack.arrow.currentTime = 0;
currentPack.arrow.play();
break;
default:
const clickSoundsCount = Object.keys(currentPack).filter(key => key.startsWith("click")).length;
const click = currentPack[`click${Math.floor(Math.random() * clickSoundsCount) + 1}`];
click.currentTime = 0;
click.play();
break;
}
};
export default definePlugin({
name: "KeyboardSounds",
description: "Adds the Opera GX Keyboard Sounds to Discord",
authors: [{ name: "domi.btnr", id: 354191516979429376n }],
start: () => {
const volume = Settings.plugins.KeyboardSounds.volume;
const currentPack = packs[getActiveSoundPack()];
for (const sound of Object.values(currentPack))
if (sound instanceof Audio) sound.volume = volume / 100;
document.addEventListener("keydown", keydown);
},
stop: () => document.removeEventListener("keydown", keydown),
options: {
pack: {
description: "Select the Sound Pack you want to use",
type: OptionType.SELECT,
options: Object.keys(packs).map((pack, i) => {
return {
label: pack,
value: pack,
default: i === 0
}
}),
onChange: () => {
const volume = Settings.plugins.KeyboardSounds.volume;
const currentPack = packs[getActiveSoundPack()];
for (const sound of Object.values(currentPack))
if (sound instanceof Audio) sound.volume = volume / 100;
}
},
volume: {
description: "Volume",
type: OptionType.SLIDER,
markers: [0, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100],
stickToMarkers: false,
default: 100,
onChange: value => {
const currentPack = packs[getActiveSoundPack()];
for (const sound of Object.values(currentPack))
if (sound instanceof Audio) sound.volume = value / 100;
}
}
}
});