MCPcopy
hub / github.com/refined-github/refined-github / registerHotkey

Function registerHotkey

source/github-helpers/hotkey.tsx:5–19  ·  view source on GitHub ↗
(
	hotkey: string,
	functionOrUrl: React.MouseEventHandler<HTMLButtonElement> | string,
	{signal}: SignalAsOptions = {},
)

Source from the content-addressed store, hash-verified

3import {isMac} from './index.js';
4
5export function registerHotkey(
6 hotkey: string,
7 functionOrUrl: React.MouseEventHandler<HTMLButtonElement> | string,
8 {signal}: SignalAsOptions = {},
9): void {
10 const element = typeof functionOrUrl === 'string'
11 ? <a hidden href={functionOrUrl} data-hotkey={hotkey} />
12 : <button hidden type="button" data-hotkey={hotkey} onClick={functionOrUrl} />;
13
14 document.body.prepend(element);
15
16 signal?.addEventListener('abort', () => {
17 element.remove();
18 });
19}
20
21/** Safely add a hotkey to an element, preserving any existing ones and avoiding duplicates */
22export function addHotkey(button: HTMLAnchorElement | HTMLButtonElement | undefined, hotkey: string): void {

Callers 10

initOnceFunction · 0.85
addShortcutFunction · 0.85
initFunction · 0.85
initOnceFunction · 0.85
replaceRerunDropdownFunction · 0.85
initFunction · 0.85
initFunction · 0.85
initFunction · 0.85
initFunction · 0.85
initOnceFunction · 0.85

Calls 2

prependMethod · 0.80
removeMethod · 0.80

Tested by

no test coverage detected