Pass modifier keys to click event

This commit is contained in:
the1812 2021-03-02 17:58:07 +08:00
parent 64ea85a1c5
commit 9fe728043a
3 changed files with 14 additions and 10 deletions

2
min/keymap.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,9 +1,10 @@
export type KeyBindingAction = (context: {
export interface KeyBindingActionContext {
binding: KeyBinding
event: KeyboardEvent
isWatchlater: boolean
isMediaList: boolean
}) => void
}
export type KeyBindingAction = (context: KeyBindingActionContext) => void
export interface KeyBinding {
keys: string[]
action: KeyBindingAction

View File

@ -1,5 +1,5 @@
import { VideoSpeedController } from '../video-speed/video-speed-controller'
import { KeyBinding, KeyBindingAction } from './key-bindings'
import { KeyBinding, KeyBindingAction, KeyBindingActionContext } from './key-bindings'
const supportedUrls = [
'https://www.bilibili.com/bangumi/',
@ -13,11 +13,14 @@ const supportedUrls = [
let config: { enable: boolean, bindings: KeyBinding[] } | undefined = undefined
if (supportedUrls.some(url => document.URL.startsWith(url))) {
const clickElement = (target: string | HTMLElement) => {
return () => {
return ({ event }: KeyBindingActionContext) => {
const mouseEvent = new MouseEvent('click', {
..._.pick(event, 'ctrlKey', 'shiftKey', 'altKey', 'metaKey')
})
if (typeof target === 'string') {
(dq(target) as HTMLElement)?.click()
(dq(target) as HTMLElement)?.dispatchEvent(mouseEvent)
} else {
target.click()
target.dispatchEvent(mouseEvent)
}
}
}
@ -92,8 +95,8 @@ if (supportedUrls.some(url => document.URL.startsWith(url))) {
showTip(`${after}%`, 'mdi-volume-high')
}
},
mute: () => {
clickElement('.bilibili-player-video-btn-volume .bilibili-player-iconfont-volume')()
mute: (context: KeyBindingActionContext) => {
clickElement('.bilibili-player-video-btn-volume .bilibili-player-iconfont-volume')(context)
const isMute = unsafeWindow.player.isMute()
if (isMute) {
showTip('已静音', 'mdi-volume-off')
@ -219,7 +222,7 @@ if (supportedUrls.some(url => document.URL.startsWith(url))) {
videoSpeedDecrease: 'shift < 《 arrowDown',
videoSpeedReset: 'shift ? ',
videoSpeedForget: 'shift : ',
takeScreenshot: 'ctrl alt c',
takeScreenshot: 'ctrl [shift] alt c',
previousFrame: 'shift arrowLeft',
nextFrame: 'shift arrowRight',
seekBegin: '0',