diff --git a/src/components/TopBar/TopBar.vue b/src/components/TopBar/TopBar.vue index 0cb67ad8..56ae753b 100644 --- a/src/components/TopBar/TopBar.vue +++ b/src/components/TopBar/TopBar.vue @@ -5,7 +5,7 @@ import type { Ref, UnwrapNestedRefs } from 'vue' import { useApiClient } from '~/composables/api' import { useBewlyApp } from '~/composables/useAppProvider' import { useDelayedHover } from '~/composables/useDelayedHover' -import { TOP_BAR_VISIBILITY_CHANGE } from '~/constants/globalEvents' +import { OVERLAY_SCROLL_BAR_SCROLL, TOP_BAR_VISIBILITY_CHANGE } from '~/constants/globalEvents' import { AppPage } from '~/enums/appEnums' import { settings } from '~/logic' import { getUserID, isHomePage } from '~/utils/main' @@ -292,11 +292,21 @@ onMounted(async () => { initData() await nextTick() toggleTopBarVisible(true) - window.addEventListener('scroll', handleScroll) + + emitter.off(OVERLAY_SCROLL_BAR_SCROLL) + if (isHomePage() && !settings.value.useOriginalBilibiliHomepage) { + emitter.on(OVERLAY_SCROLL_BAR_SCROLL, () => { + handleScroll() + }) + } + else { + window.addEventListener('scroll', handleScroll) + } }) -onBeforeMount(() => { +onUnmounted(() => { window.removeEventListener('scroll', handleScroll) + emitter.off(OVERLAY_SCROLL_BAR_SCROLL) }) async function initData() { @@ -310,7 +320,7 @@ async function initData() { } function handleScroll() { - if (isHomePage()) { + if (isHomePage() && !settings.value.useOriginalBilibiliHomepage) { const osInstance = scrollbarRef.value?.osInstance() scrollTop.value = osInstance.elements().viewport.scrollTop as number } diff --git a/src/constants/globalEvents.ts b/src/constants/globalEvents.ts index e2fdaef7..abb27a54 100644 --- a/src/constants/globalEvents.ts +++ b/src/constants/globalEvents.ts @@ -1 +1,2 @@ export const TOP_BAR_VISIBILITY_CHANGE = 'topBarVisibilityChange' +export const OVERLAY_SCROLL_BAR_SCROLL = 'overlayScrollBarScroll' diff --git a/src/contentScripts/views/App.vue b/src/contentScripts/views/App.vue index 3b78685b..f382163f 100644 --- a/src/contentScripts/views/App.vue +++ b/src/contentScripts/views/App.vue @@ -13,9 +13,11 @@ import Settings from '~/components/Settings/Settings.vue' import TopBar from '~/components/TopBar/TopBar.vue' import type { BewlyAppProvider } from '~/composables/useAppProvider' import { useDark } from '~/composables/useDark' +import { OVERLAY_SCROLL_BAR_SCROLL } from '~/constants/globalEvents' import { AppPage, LanguageType } from '~/enums/appEnums' import { accessKey, settings } from '~/logic' import { getUserID, hexToRGBA, isHomePage, scrollToTop } from '~/utils/main' +import emitter from '~/utils/mitt' const { isDark } = useDark() const activatedPage = ref(settings.value.dockItemVisibilityList.find(e => e.visible === true)?.page ?? AppPage.Home) @@ -177,6 +179,8 @@ function handleAdaptToOtherPageStylesChange() { } function handleOsScroll() { + emitter.emit(OVERLAY_SCROLL_BAR_SCROLL) + const osInstance = scrollbarRef.value?.osInstance() const { viewport } = osInstance.elements() const { scrollTop, scrollHeight, clientHeight } = viewport // get scroll offset