mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-02-24 15:35:11 +00:00
Add files via upload
This commit is contained in:
parent
c22ac15cc1
commit
7adac6b450
4 changed files with 163 additions and 0 deletions
80
src/plugins/keybinds/components/SettingsView.tsx
Normal file
80
src/plugins/keybinds/components/SettingsView.tsx
Normal file
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Vencord, a Discord client mod
|
||||
* Copyright (c) 2025 Vendicated and contributors
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import "./styles.css";
|
||||
|
||||
import { Text, TextInput, useState } from "@webpack/common";
|
||||
|
||||
import { keybinds } from "./keybinds";
|
||||
import { CheckboxRow, cl } from "./utils";
|
||||
|
||||
function keybindStr(key, ctrl, shift, alt) {
|
||||
return (ctrl ? "Ctrl+" : "") + (shift ? "Shift+" : "") + (alt ? "Alt+" : "") + key;
|
||||
}
|
||||
|
||||
|
||||
function KeybindDetector({ keybindSettings: k }) {
|
||||
|
||||
const [listening, setListening] = useState(false);
|
||||
|
||||
if (!listening)
|
||||
return (
|
||||
<div onClick={() => setListening(true)}>
|
||||
<TextInput editable={false} value={keybindStr(k.key, k.ctrl, k.shift, k.alt)} />
|
||||
</div >
|
||||
);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<TextInput placeholder="Press a key combination" value="" className={cl("keybind-input")} onKeyDown={e => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
if (e.key === "Escape") {
|
||||
setListening(false);
|
||||
return;
|
||||
}
|
||||
if (e.key === "Control" || e.key === "Shift" || e.key === "Alt") {
|
||||
return;
|
||||
}
|
||||
k.key = e.key.toUpperCase();
|
||||
k.ctrl = e.ctrlKey;
|
||||
k.shift = e.shiftKey;
|
||||
k.alt = e.altKey;
|
||||
setListening(false);
|
||||
}} />
|
||||
</div>
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function KeybindSettings({ keybind, settings }) {
|
||||
const keybindData = keybinds[keybind];
|
||||
const keybindSettings = settings.store[keybind];
|
||||
|
||||
return (
|
||||
<div className={cl("settings-row")}>
|
||||
<CheckboxRow value={keybindSettings.enabled} onChange={_ => keybindSettings.enabled = !keybindSettings.enabled}>
|
||||
<div className={cl("settings-row-content")}>
|
||||
<div >
|
||||
<Text variant="eyebrow">{keybindData.name}</Text>
|
||||
<Text variant="text-sm/normal">{keybindData.desc}</Text>
|
||||
</div>
|
||||
<KeybindDetector keybindSettings={keybindSettings} />
|
||||
</div>
|
||||
</CheckboxRow>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function SettingsView({ settings }) {
|
||||
return (
|
||||
<div>
|
||||
{Object.keys(keybinds).map(keybind => {
|
||||
return <KeybindSettings keybind={keybind} settings={settings} key={keybind} />;
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
58
src/plugins/keybinds/components/keybinds.tsx
Normal file
58
src/plugins/keybinds/components/keybinds.tsx
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Vencord, a Discord client mod
|
||||
* Copyright (c) 2025 Vendicated and contributors
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { relaunch } from "@utils/native";
|
||||
|
||||
export const keybinds: { [key: string]: any; } = {
|
||||
debuggerPause: {
|
||||
name: "Debugger Pause",
|
||||
desc: "Pauses the client in using the debugger",
|
||||
default: {
|
||||
enabled: false,
|
||||
key: "F8",
|
||||
ctrl: false,
|
||||
alt: false,
|
||||
shift: false,
|
||||
},
|
||||
action: () => {
|
||||
// Hi! You've just paused the client. Pressing F8 in DevTools or in the main window will unpause it again.
|
||||
// It's up to you on what to do, friend. Happy travels!
|
||||
debugger;
|
||||
},
|
||||
},
|
||||
inboxJump: {
|
||||
name: "Inbox Jump",
|
||||
desc: "Adds a keybind for the jump button in the inbox",
|
||||
default: {
|
||||
enabled: false,
|
||||
key: ";",
|
||||
ctrl: true,
|
||||
alt: false,
|
||||
shift: false
|
||||
},
|
||||
action: () => {
|
||||
const btn = document.querySelector(
|
||||
"div[class^=jumpButton]",
|
||||
);
|
||||
if (btn) btn?.click();
|
||||
console.log("Executed");
|
||||
}
|
||||
},
|
||||
restart: {
|
||||
name: "Restart",
|
||||
desc: "Restarts your discord client",
|
||||
default: {
|
||||
enabled: false,
|
||||
key: "R",
|
||||
ctrl: true,
|
||||
shift: true,
|
||||
alt: false,
|
||||
},
|
||||
action: () => {
|
||||
relaunch();
|
||||
}
|
||||
}
|
||||
};
|
12
src/plugins/keybinds/components/styles.css
Normal file
12
src/plugins/keybinds/components/styles.css
Normal file
|
@ -0,0 +1,12 @@
|
|||
.vc-keybinds-settings-row {
|
||||
padding: 3px;
|
||||
}
|
||||
|
||||
.vc-keybinds-settings-row-content {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
13
src/plugins/keybinds/components/utils.ts
Normal file
13
src/plugins/keybinds/components/utils.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
* Vencord, a Discord client mod
|
||||
* Copyright (c) 2025 Vendicated and contributors
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { classNameFactory } from "@api/Styles";
|
||||
import { findComponentByCodeLazy } from "@webpack";
|
||||
|
||||
export const cl = classNameFactory("vc-keybinds-");
|
||||
export const CheckboxRow = findComponentByCodeLazy(".labelReversed");
|
||||
|
||||
|
Loading…
Add table
Reference in a new issue