Skip to content

Commit ed9dc75

Browse files
authored
Merge pull request #86 from eli-yip/fix/hide-sidebar-in-web-fullscreen
fix(top-bar): hide dock & sidebar in web fullscreen on bangumi pages
2 parents 245158e + add96a5 commit ed9dc75

4 files changed

Lines changed: 60 additions & 59 deletions

File tree

src/components/TopBar/OldTopBar.vue

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import type { Ref, UnwrapNestedRefs } from 'vue'
44
55
import { useBewlyApp } from '~/composables/useAppProvider'
66
import { useDelayedHover } from '~/composables/useDelayedHover'
7+
import { useWebFullscreen } from '~/composables/useWebFullscreen'
78
import { OVERLAY_SCROLL_BAR_SCROLL, TOP_BAR_VISIBILITY_CHANGE } from '~/constants/globalEvents'
89
import { AppPage } from '~/enums/appEnums'
910
import { settings } from '~/logic'
1011
import api from '~/utils/api'
11-
import { getUserID, isHomePage, isInIframe, isVideoOrBangumiPage, queryDomUntilFound, removeHttpFromUrl } from '~/utils/main'
12+
import { getUserID, isHomePage, removeHttpFromUrl } from '~/utils/main'
1213
import emitter from '~/utils/mitt'
1314
1415
import ChannelsPop from './components/ChannelsPop.vue'
@@ -314,34 +315,9 @@ onUnmounted(() => {
314315
emitter.off(OVERLAY_SCROLL_BAR_SCROLL)
315316
})
316317
317-
// #region Hide the top bar when entering web fullscreen (网页全屏)
318-
// On normal video pages Bilibili's web-fullscreen player layer happens to cover the top bar,
319-
// but on bangumi pages (`/bangumi/play/`) it doesn't, leaving the top bar floating over the video.
320-
// So we explicitly detect web fullscreen via the player's web-fullscreen button state and hide the
321-
// top bar ourselves. (The drawer/iframe case is handled separately in App.vue.)
322-
let webFullscreenObserver: MutationObserver | null = null
323-
const webFullscreenAbort = new AbortController()
324-
325-
onMounted(() => {
326-
if (isInIframe() || !isVideoOrBangumiPage())
327-
return
328-
329-
queryDomUntilFound('.bpx-player-ctrl-btn.bpx-player-ctrl-web', 500, webFullscreenAbort).then((webFullscreenBtn) => {
330-
if (!webFullscreenBtn)
331-
return
332-
333-
webFullscreenObserver = new MutationObserver(() => {
334-
toggleTopBarVisible(!webFullscreenBtn.classList.contains('bpx-state-entered'))
335-
})
336-
webFullscreenObserver.observe(webFullscreenBtn, { attributes: true, attributeFilter: ['class'] })
337-
})
338-
})
339-
340-
onUnmounted(() => {
341-
webFullscreenObserver?.disconnect()
342-
webFullscreenAbort.abort()
343-
})
344-
// #endregion
318+
// Hide the top bar when entering web fullscreen (网页全屏). See useWebFullscreen for details.
319+
const { isWebFullscreen } = useWebFullscreen()
320+
watch(isWebFullscreen, webFullscreen => toggleTopBarVisible(!webFullscreen))
345321
346322
async function initData() {
347323
await getUserInfo()

src/components/TopBar/TopBar.vue

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import type { Ref, UnwrapNestedRefs } from 'vue'
55
import { useBewlyApp } from '~/composables/useAppProvider'
66
import { useDark } from '~/composables/useDark'
77
import { useDelayedHover } from '~/composables/useDelayedHover'
8+
import { useWebFullscreen } from '~/composables/useWebFullscreen'
89
import { OVERLAY_SCROLL_BAR_SCROLL, TOP_BAR_VISIBILITY_CHANGE } from '~/constants/globalEvents'
910
import { AppPage } from '~/enums/appEnums'
1011
import { settings } from '~/logic'
1112
import api from '~/utils/api'
12-
import { getUserID, isHomePage, isInIframe, isVideoOrBangumiPage, queryDomUntilFound, removeHttpFromUrl } from '~/utils/main'
13+
import { getUserID, isHomePage, isInIframe, removeHttpFromUrl } from '~/utils/main'
1314
import emitter from '~/utils/mitt'
1415
import { createTransformer } from '~/utils/transformer'
1516
@@ -343,34 +344,9 @@ onUnmounted(() => {
343344
emitter.off(OVERLAY_SCROLL_BAR_SCROLL)
344345
})
345346
346-
// #region Hide the top bar when entering web fullscreen (网页全屏)
347-
// On normal video pages Bilibili's web-fullscreen player layer happens to cover the top bar,
348-
// but on bangumi pages (`/bangumi/play/`) it doesn't, leaving the top bar floating over the video.
349-
// So we explicitly detect web fullscreen via the player's web-fullscreen button state and hide the
350-
// top bar ourselves. (The drawer/iframe case is handled separately in App.vue.)
351-
let webFullscreenObserver: MutationObserver | null = null
352-
const webFullscreenAbort = new AbortController()
353-
354-
onMounted(() => {
355-
if (isInIframe() || !isVideoOrBangumiPage())
356-
return
357-
358-
queryDomUntilFound('.bpx-player-ctrl-btn.bpx-player-ctrl-web', 500, webFullscreenAbort).then((webFullscreenBtn) => {
359-
if (!webFullscreenBtn)
360-
return
361-
362-
webFullscreenObserver = new MutationObserver(() => {
363-
toggleTopBarVisible(!webFullscreenBtn.classList.contains('bpx-state-entered'))
364-
})
365-
webFullscreenObserver.observe(webFullscreenBtn, { attributes: true, attributeFilter: ['class'] })
366-
})
367-
})
368-
369-
onUnmounted(() => {
370-
webFullscreenObserver?.disconnect()
371-
webFullscreenAbort.abort()
372-
})
373-
// #endregion
347+
// Hide the top bar when entering web fullscreen (网页全屏). See useWebFullscreen for details.
348+
const { isWebFullscreen } = useWebFullscreen()
349+
watch(isWebFullscreen, webFullscreen => toggleTopBarVisible(!webFullscreen))
374350
375351
async function initData() {
376352
await getUserInfo()
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { isInIframe, isVideoOrBangumiPage, queryDomUntilFound } from '~/utils/main'
2+
3+
/**
4+
* Detect Bilibili web fullscreen (网页全屏) on video/bangumi pages.
5+
*
6+
* On normal video pages Bilibili's web-fullscreen player layer happens to cover our overlay
7+
* (top bar, dock, side buttons), but on bangumi pages (`/bangumi/play/`) it doesn't, leaving
8+
* them floating over the video. So we explicitly detect web fullscreen by observing the player's
9+
* web-fullscreen control button toggling `bpx-state-entered`, and let callers hide their overlay.
10+
*
11+
* Only active on video/bangumi pages outside of an iframe. (The drawer/iframe case is handled
12+
* separately in App.vue, which needs to message the parent frame instead.)
13+
*
14+
* @returns `isWebFullscreen` — a reactive ref that is `true` while in web fullscreen.
15+
*/
16+
export function useWebFullscreen() {
17+
const isWebFullscreen = ref<boolean>(false)
18+
19+
let observer: MutationObserver | null = null
20+
const abort = new AbortController()
21+
22+
onMounted(() => {
23+
if (isInIframe() || !isVideoOrBangumiPage())
24+
return
25+
26+
queryDomUntilFound('.bpx-player-ctrl-btn.bpx-player-ctrl-web', 500, abort).then((webFullscreenBtn) => {
27+
if (!webFullscreenBtn)
28+
return
29+
30+
const sync = () => {
31+
isWebFullscreen.value = webFullscreenBtn.classList.contains('bpx-state-entered')
32+
}
33+
sync()
34+
observer = new MutationObserver(sync)
35+
observer.observe(webFullscreenBtn, { attributes: true, attributeFilter: ['class'] })
36+
})
37+
})
38+
39+
onUnmounted(() => {
40+
observer?.disconnect()
41+
abort.abort()
42+
})
43+
44+
return { isWebFullscreen }
45+
}

src/contentScripts/views/App.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { Ref } from 'vue'
44
55
import type { BewlyAppProvider } from '~/composables/useAppProvider'
66
import { useDark } from '~/composables/useDark'
7+
import { useWebFullscreen } from '~/composables/useWebFullscreen'
78
import { BEWLY_MOUNTED, DRAWER_VIDEO_ENTER_PAGE_FULL, DRAWER_VIDEO_EXIT_PAGE_FULL, IFRAME_PAGE_SWITCH_BEWLY, IFRAME_PAGE_SWITCH_BILI, OVERLAY_SCROLL_BAR_SCROLL } from '~/constants/globalEvents'
89
import { AppPage } from '~/enums/appEnums'
910
import { settings } from '~/logic'
@@ -386,6 +387,9 @@ watchEffect(async (onCleanUp) => {
386387
})
387388
})
388389
390+
// Hide the floating dock / sidebar when entering web fullscreen (网页全屏), same as the top bar.
391+
const { isWebFullscreen } = useWebFullscreen()
392+
389393
provide<BewlyAppProvider>('BEWLY_APP', {
390394
activatedPage,
391395
mainAppRef,
@@ -619,7 +623,7 @@ document.head.appendChild(removeLeftQuoteIndent)
619623

620624
<!-- Dock & RightSideButtons -->
621625
<div
622-
v-if="!isInIframe()"
626+
v-if="!isInIframe() && !isWebFullscreen"
623627
pos="absolute top-0 left-0" w-full h-full overflow-hidden
624628
pointer-events-none
625629
>

0 commit comments

Comments
 (0)