|
|
@@ -218,12 +218,37 @@ class PeerTubeHotkeysPlugin extends Plugin { |
|
|
|
} |
|
|
|
|
|
|
|
private isNaked (event: KeyboardEvent, key: string) { |
|
|
|
return (!event.ctrlKey && !event.altKey && !event.metaKey && !event.shiftKey && event.key === key) |
|
|
|
if (key.length === 1) key = key.toUpperCase() |
|
|
|
|
|
|
|
return (!event.ctrlKey && !event.altKey && !event.metaKey && !event.shiftKey && this.getLatinKey(event.key, event.code) === key) |
|
|
|
} |
|
|
|
|
|
|
|
private isNakedOrShift (event: KeyboardEvent, key: string) { |
|
|
|
return (!event.ctrlKey && !event.altKey && !event.metaKey && event.key === key) |
|
|
|
} |
|
|
|
|
|
|
|
// Thanks Maciej Krawczyk |
|
|
|
// https://stackoverflow.com/questions/70211837/keyboard-shortcuts-commands-on-non-latin-alphabet-keyboards-javascript?rq=1 |
|
|
|
private getLatinKey (key: string, code: string) { |
|
|
|
if (key.length !== 1) { |
|
|
|
return key |
|
|
|
} |
|
|
|
|
|
|
|
const capitalHetaCode = 880 |
|
|
|
const isNonLatin = key.charCodeAt(0) >= capitalHetaCode |
|
|
|
|
|
|
|
if (isNonLatin) { |
|
|
|
if (code.indexOf('Key') === 0 && code.length === 4) { // i.e. 'KeyW' |
|
|
|
return code.charAt(3) |
|
|
|
} |
|
|
|
|
|
|
|
if (code.indexOf('Digit') === 0 && code.length === 6) { // i.e. 'Digit7' |
|
|
|
return code.charAt(5) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return key.toUpperCase() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
videojs.registerPlugin('peerTubeHotkeysPlugin', PeerTubeHotkeysPlugin) |
|
|
|