Skip to content

Commit

Permalink
update: video page screen scrollable
Browse files Browse the repository at this point in the history
  • Loading branch information
festoney8 committed Oct 20, 2024
1 parent a299623 commit 2855014
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/modules/rules/bangumi/groups/playerLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,24 @@ import { unsafeWindow } from '$'
import { Item } from '../../../../types/item'
import { waitForEle } from '../../../../utils/tool'

const disableAdjustVolume = () => {}
/**
* Firefox DOMMouseScroll无法被stopImmediatePropagation
*/
let webScroll = false
let fullScroll = false
const fn = () => (event: Event) => event.stopImmediatePropagation()
const disableTuneVolume = () => {
if (!webScroll && !fullScroll) {
window.addEventListener('mousewheel', fn, { capture: true })
// window.addEventListener('DOMMouseScroll', fn, { capture: true })
}
}
const enableTuneVolume = () => {
if (!(webScroll && fullScroll)) {
window.removeEventListener('mousewheel', fn)
// window.removeEventListener('DOMMouseScroll', fn)
}
}

export const bangumiPlayerLayoutItems: Item[] = [
{
Expand Down Expand Up @@ -35,8 +52,8 @@ export const bangumiPlayerLayoutItems: Item[] = [
description: ['播放器内滚轮调节音量失效', 'Firefox 不适用'],
enableFn: async () => {
// 禁用滚动调音量
document.removeEventListener('wheel', disableAdjustVolume)
document.addEventListener('wheel', disableAdjustVolume)
disableTuneVolume()
webScroll = true

// 监听网页全屏按钮出现
waitForEle(document.body, '.bpx-player-ctrl-web', (node: HTMLElement): boolean => {
Expand All @@ -51,7 +68,7 @@ export const bangumiPlayerLayoutItems: Item[] = [
}
})
},
disableFn: async () => document.removeEventListener('wheel', disableAdjustVolume),
disableFn: enableTuneVolume,
enableFnRunAt: 'document-end',
},
{
Expand All @@ -65,8 +82,8 @@ export const bangumiPlayerLayoutItems: Item[] = [
}

// 禁用滚动调音量
document.removeEventListener('wheel', disableAdjustVolume)
document.addEventListener('wheel', disableAdjustVolume)
disableTuneVolume()
fullScroll = true

let cnt = 0
const id = setInterval(() => {
Expand Down Expand Up @@ -125,7 +142,7 @@ export const bangumiPlayerLayoutItems: Item[] = [
}
}, 200)
},
disableFn: async () => document.removeEventListener('wheel', disableAdjustVolume),
disableFn: enableTuneVolume,
enableFnRunAt: 'document-end',
},
{
Expand Down

0 comments on commit 2855014

Please sign in to comment.