From 2918907dfa764797ba3207a8ea49f0c6f8b7ed49 Mon Sep 17 00:00:00 2001 From: festoney8 Date: Wed, 7 Aug 2024 23:43:02 +0800 Subject: [PATCH] fix: mini player position record #112 --- CHANGELOG.md | 3 ++- src/rules/video.ts | 54 +++++++++++++++++++++++++++++----------------- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b40ad406..ab9c6c29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ## 3.10.3 -- 新增:番剧播放页支持自动宽屏 +- 新增:番剧播放页 默认宽屏播放 +- 修复:分区排行榜视频过滤 ## 3.10.2 diff --git a/src/rules/video.ts b/src/rules/video.ts index 899d43f5..f44758dd 100644 --- a/src/rules/video.ts +++ b/src/rules/video.ts @@ -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 } @@ -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 {} } }) },