import React from 'dom-chef';

export function registerHotkey(hotkey: string, action: VoidFunction | string, {signal}: SignalAsOptions): void {
	const element = typeof action === 'string'
		? <a hidden href={action} data-hotkey={hotkey}/>
		: <button hidden type="button" data-hotkey={hotkey} onClick={action}/>;

	document.body.append(element);

	signal?.addEventListener('abort', () => {
		element.remove();
	});
}

/** Safely add a hotkey to an element, preserving any existing ones and avoiding duplicates */
export function addHotkey(button: HTMLAnchorElement | HTMLButtonElement | undefined, hotkey: string): void {
	if (button) {
		const hotkeys = new Set(button.dataset.hotkey?.split(','));
		hotkeys.add(hotkey);
		button.dataset.hotkey = [...hotkeys].join(',');
	}
}
e='dev-backup'>dev-backup</option>
<option value='docker-run-to-docker-compose-converter'>docker-run-to-docker-compose-converter</option>
<option value='ed25519-key-pair-generator'>ed25519-key-pair-generator</option>
<option value='feat/jwt-parser'>feat/jwt-parser</option>
<option value='landing-page'>landing-page</option>
<option value='main' selected='selected'>main</option>
<option value='master'>master</option>
<option value='ssg'>ssg</option>
<option value='svg-mesh-gradient-generator'>svg-mesh-gradient-generator</option>
<option value='update-dependencies'>update-dependencies</option>
<option value='update-deps'>update-deps</option>
</select> <input type='submit' value='switch'/></form></td></tr>
<tr><td class='sub'>Unnamed repository; edit this file 'description' to name the repository.</td><td class='sub right'></td></tr></table>
<table class='tabs'><tr><td>
<a href='/ansg191/it-tools/about/'>about</a><a href='/ansg191/it-tools/'>summary</a><a href='/ansg191/it-tools/refs/'>refs</a><a class='active' href='/ansg191/it-tools/log/src/tools/mime-types?follow=1'>log</a><a href='/ansg191/it-tools/tree/src/tools/mime-types'>tree</a><a href='/ansg191/it-tools/commit/src/tools/mime-types?follow=1'>commit</a><a href='/ansg191/it-tools/diff/src/tools/mime-types?follow=1'>diff</a></td><td class='form'><form class='right' method='get' action='/ansg191/it-tools/log/src/tools/mime-types'>
<select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/ansg191/it-tools/log/?follow=1'>root</a>/<a href='/ansg191/it-tools/log/src?follow=1'>src</a>/<a href='/ansg191/it-tools/log/src/tools?follow=1'>tools</a>/<a href='/ansg191/it-tools/log/src/tools/mime-types?follow=1'>mime-types</a> (<a href='/ansg191/it-tools/log/src/tools/mime-types'>unfollow</a>)</div><div class='content'><table class='list nowrap'><tr class='nohover'><th class='left'>Age</th><th class='left'>Commit message (<a href='/ansg191/it-tools/log/src/tools/mime-types?showmsg=1&amp;follow=1'>Expand</a>)</th><th class='left'>Author</th><th class='left'>Files</th><th class='left'>Lines</th></tr>
<tr><td><span title='2024-05-27 11:59:05 +0200'>2024-05-27</span></td><td><a href='/ansg191/it-tools/commit/src/tools/jwt-parser/jwt-parser.vue?id=dd4b7e687b7a9e2f58c4e52f6593f59dcd9e1ac1&amp;follow=1'>fix(jwt-parser): prevent UI overflow on small screen (#1095)</a></td><td><img src='//www.gravatar.com/avatar/2f1de1fd1b3f8e6593aa8f516122f985?s=13&amp;d=retro' width='13' height='13' alt='Gravatar' /> sharevb
</td><td>1</td><td><span class='deletions'>-2</span>/<span class='insertions'>+2</span></td></tr>
<tr><td><span title='2024-05-20 22:13:55 +0200'>2024-05-20</span></td><td><a href='/ansg191/it-tools/commit/src/utils/base64.ts?id=30144aa3f51f5d0dc90f64cf888bc6f83de11b10&amp;follow=1'>feat(base64): Base64 enhancements (#905)</a></td><td><img src='//www.gravatar.com/avatar/2f1de1fd1b3f8e6593aa8f516122f985?s=13&amp;d=retro' width='13' height='13' alt='Gravatar' /> sharevb
</td><td>6</td><td><span class='deletions'>-37</span>/<span class='insertions'>+163</span></td></tr>
<tr><td><span title='2024-05-13 10:54:18 +0200'>2024-05-13</span></td><td><a href='/ansg191/it-tools/commit/package.json?id=e876d0360812eab1255e414102a44d65f7c1bfaf&amp;follow=1'>chore(version): release 2024.05.13-a0bc346</a><span class='decoration'><a class='tag-annotated-deco' href='/ansg191/it-tools/tag/?h=v2024.5.13-a0bc346'>v2024.5.13-a0bc346</a></span></td><td><img src='//www.gravatar.com/avatar/54f6060db8779300271f0e188f0de9b1?s=13&amp;d=retro' width='13' height='13' alt='Gravatar' /> Corentin Thomasset
</td><td>1</td><td><span class='deletions'>-1</span>/<span class='insertions'>+1</span></td></tr>
<tr><td><span title='2024-05-13 10:54:18 +0200'>2024-05-13</span></td><td><a href='/ansg191/it-tools/commit/package.json?id=81cf6b54835499952ee39c5cb9bb20a196adc625&amp;follow=1'>docs(changelog): update changelog for 2024.05.13-a0bc346</a></td><td><img src='//www.gravatar.com/avatar/54f6060db8779300271f0e188f0de9b1?s=13&amp;d=retro' width='13' height='13' alt='Gravatar' /> Corentin Thomasset
</td><td>2</td><td><span class='deletions'>-2</span>/<span class='insertions'>+51</span></td></tr>
