Skip to content

Commit

Permalink
fix: mini player position record #112
Browse files Browse the repository at this point in the history
  • Loading branch information
festoney8 committed Aug 7, 2024
1 parent 48718e3 commit 2918907
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## 3.10.3

- 新增:番剧播放页支持自动宽屏
- 新增:番剧播放页 默认宽屏播放
- 修复:分区排行榜视频过滤

## 3.10.2

Expand Down
54 changes: 34 additions & 20 deletions src/rules/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -929,12 +929,10 @@ if (isPageVideo() || isPagePlaylist() || isPageFestival()) {
// 记录小窗位置
new CheckboxItem({
itemID: 'video-page-bpx-player-mini-mode-position-record',
description: '记录小窗位置',
description: '记录小窗位置 (拖动时有bug)',
enableFunc: async () => {
let player: HTMLElement

// 监听mini播放器移动
const addMiniPlayerMoveListener = () => {
const moveListener = (player: HTMLElement) => {
if (!player) {
return
}
Expand All @@ -952,29 +950,45 @@ if (isPageVideo() || isPagePlaylist() || isPageFestival()) {
)
})
}
// 设置player API内小窗播放器position初始值
const setMiniPlayerState = () => {
const right = GM_getValue('BILICLEANER_video-page-bpx-player-mini-mode-position-record-right')
const bottom = GM_getValue('BILICLEANER_video-page-bpx-player-mini-mode-position-record-bottom')
if (typeof right === 'number' && typeof bottom === 'number') {
if (unsafeWindow.player) {
unsafeWindow.player.__core().uiStore.state.miniScreenRight = right
unsafeWindow.player.__core().uiStore.state.miniScreenBottom = bottom

// 监听mini播放器出现
let isMini = false
const miniListener = (player: HTMLElement) => {
const observer = new MutationObserver((mutationsList) => {
for (const mutation of mutationsList) {
if (mutation.attributeName === 'data-screen') {
if (player.getAttribute('data-screen') === 'mini') {
if (!isMini) {
const right = GM_getValue(
'BILICLEANER_video-page-bpx-player-mini-mode-position-record-right',
)
const bottom = GM_getValue(
'BILICLEANER_video-page-bpx-player-mini-mode-position-record-bottom',
)
if (typeof right === 'number' && typeof bottom === 'number') {
player.style.right = right + 'px'
player.style.bottom = bottom + 'px'
}
}
isMini = true
} else {
isMini = false
}
break
}
}
}
})
observer.observe(player, { attributes: true })
}

waitForEle(document.body, '#bilibili-player .bpx-player-container', (node: HTMLElement) => {
waitForEle(document, '#bilibili-player .bpx-player-container', (node: HTMLElement) => {
return node.className.startsWith('bpx-player-container')
}).then((ele) => {
if (ele) {
player = ele
try {
setMiniPlayerState()
addMiniPlayerMoveListener()
} catch {
// err
}
miniListener(ele)
moveListener(ele)
} catch {}
}
})
},
Expand Down

0 comments on commit 2918907

Please sign in to comment.