mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Add toggle player light (#3587)
This commit is contained in:
parent
0169269d7d
commit
e422ca01b6
@ -4,7 +4,7 @@
|
||||
{{ row.displayName }}
|
||||
</div>
|
||||
<div
|
||||
class="row-default-binding"
|
||||
class="row-default-binding row-binding"
|
||||
:class="{
|
||||
overwritten: isOverwrittern(presets[selectedPreset], customKeyBindings),
|
||||
'not-set': presetBase[row.name] === undefined,
|
||||
@ -13,7 +13,7 @@
|
||||
{{ showReadonlyKey(presetBase) }}
|
||||
</div>
|
||||
<div
|
||||
class="row-preset-binding"
|
||||
class="row-preset-binding row-binding"
|
||||
:class="{
|
||||
overwritten: isOverwrittern(customKeyBindings),
|
||||
'not-set': presets[selectedPreset][row.name] === undefined,
|
||||
@ -21,7 +21,7 @@
|
||||
>
|
||||
{{ showReadonlyKey(presets[selectedPreset]) }}
|
||||
</div>
|
||||
<div class="row-custom-binding">
|
||||
<div class="row-custom-binding row-binding">
|
||||
<div v-if="editable" class="custom-binding-edit">
|
||||
<TextBox
|
||||
ref="customBindingTextBox"
|
||||
@ -129,6 +129,12 @@ export default Vue.extend({
|
||||
opacity: 0.25;
|
||||
}
|
||||
}
|
||||
.row-binding {
|
||||
&,
|
||||
& input {
|
||||
font-family: monospace, sans-serif;
|
||||
}
|
||||
}
|
||||
.row-custom-binding {
|
||||
.be-button {
|
||||
padding: 4px;
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
import { KeyBindingAction } from 'registry/lib/components/utils/keymap/bindings'
|
||||
import { PluginMetadata } from '@/plugins/plugin'
|
||||
import { toggleLight } from '@/components/video/player-light'
|
||||
|
||||
export const plugin: PluginMetadata = {
|
||||
name: 'keymap.actions.togglePlayerLight',
|
||||
displayName: '快捷键扩展 - 开关灯',
|
||||
description: '在快捷键的动作列表里添加一个 "开关灯".',
|
||||
setup: ({ addData }) => {
|
||||
addData('keymap.actions', (actions: Record<string, KeyBindingAction>) => {
|
||||
actions.togglePlayerLight = {
|
||||
displayName: '开关灯',
|
||||
run: async () => {
|
||||
toggleLight()
|
||||
},
|
||||
}
|
||||
})
|
||||
addData('keymap.presets', (presetBase: Record<string, string>) => {
|
||||
presetBase.togglePlayerLight = 'shift l'
|
||||
})
|
||||
},
|
||||
}
|
||||
@ -70,8 +70,13 @@ export abstract class PlayerAgent {
|
||||
}
|
||||
|
||||
/** true 开灯,false 关灯 */
|
||||
async toggleLight(on: boolean) {
|
||||
async toggleLight(on?: boolean) {
|
||||
const checkbox = (await this.query.control.settings.lightOff()) as HTMLInputElement
|
||||
// 无指定参数, 直接 toggle
|
||||
if (on === undefined) {
|
||||
checkbox.click()
|
||||
return
|
||||
}
|
||||
// 关灯状态 && 要开灯 -> 开灯
|
||||
checkbox.checked && on && checkbox.click()
|
||||
// 开灯状态 && 要关灯 -> 关灯
|
||||
|
||||
@ -5,7 +5,7 @@ import { playerAgent } from './player-agent'
|
||||
|
||||
// let initialized = false
|
||||
|
||||
const setLight = (on: boolean) => {
|
||||
const setLight = (on?: boolean) => {
|
||||
if (!playerUrls.some(url => matchUrlPattern(url))) {
|
||||
return none
|
||||
}
|
||||
@ -27,3 +27,4 @@ const setLight = (on: boolean) => {
|
||||
|
||||
export const lightOn = setLight(true)
|
||||
export const lightOff = setLight(false)
|
||||
export const toggleLight = setLight()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user