mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Pass modifier keys to click event
This commit is contained in:
parent
64ea85a1c5
commit
9fe728043a
2
min/keymap.min.js
vendored
2
min/keymap.min.js
vendored
File diff suppressed because one or more lines are too long
@ -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
|
||||
|
||||
@ -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',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user