blob: eb15d51801cdaf935d83299a4242b7a843d21709 (
plain) (
blame)
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
|
import select from 'select-dom';
import * as pageDetect from 'github-url-detection';
import copyToClipboard from 'copy-text-to-clipboard';
import features from '.';
import {isEditable} from '../helpers/dom-utils';
const handler = ({key, target}: KeyboardEvent): void => {
if (key === 'y' && !isEditable(target)) {
const permalink = select<HTMLAnchorElement>('.js-permalink-shortcut')!.href;
copyToClipboard(permalink + location.hash);
}
};
function init(): void {
window.addEventListener('keyup', handler);
}
function deinit(): void {
window.removeEventListener('keyup', handler);
}
void features.add({
id: __filebasename,
description: 'Enhances the `y` hotkey to also copy the permalink.',
screenshot: false
}, {
include: [
pageDetect.isSingleFile
],
waitForDomReady: false,
repeatOnBackButton: true,
init,
deinit
});
|