Skip to content

Commit

Permalink
perf: improve BewlyBewly inject speed
Browse files Browse the repository at this point in the history
  • Loading branch information
hakadao committed Sep 10, 2024
1 parent c43577b commit bc3b9d2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/constants/globalEvents.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const TOP_BAR_VISIBILITY_CHANGE = 'topBarVisibilityChange'
export const OVERLAY_SCROLL_BAR_SCROLL = 'overlayScrollBarScroll'
export const BEWLY_MOUNTED = 'bewlyMounted'
8 changes: 6 additions & 2 deletions src/contentScripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import '~/styles'
import { createApp } from 'vue'

import { useDark } from '~/composables/useDark'
import { BEWLY_MOUNTED } from '~/constants/globalEvents'
import { settings } from '~/logic'
import { setupApp } from '~/logic/common-setup'
import { runWhenIdle } from '~/utils/lazyLoad'
Expand Down Expand Up @@ -113,6 +114,11 @@ if (settings.value.adaptToOtherPageStyles && isHomePage()) {
`)
}

window.addEventListener(BEWLY_MOUNTED, () => {
if (beforeLoadedStyleEl)
document.documentElement.removeChild(beforeLoadedStyleEl)
})

// Set the original Bilibili top bar to `display: none` to prevent it from showing before the load
// see: https://github.com/BewlyBewly/BewlyBewly/issues/967
let removeOriginalTopBar: HTMLStyleElement | null = null
Expand All @@ -139,8 +145,6 @@ async function onDOMLoaded() {
if (originalTopBar)
document.body.appendChild(originalTopBar)
}
if (beforeLoadedStyleEl)
document.documentElement.removeChild(beforeLoadedStyleEl)

if (isSupportedPages()) {
// Then inject the app
Expand Down
3 changes: 2 additions & 1 deletion src/contentScripts/views/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import browser from 'webextension-polyfill'
import type { BewlyAppProvider } from '~/composables/useAppProvider'
import { useDark } from '~/composables/useDark'
import { OVERLAY_SCROLL_BAR_SCROLL } from '~/constants/globalEvents'
import { BEWLY_MOUNTED, OVERLAY_SCROLL_BAR_SCROLL } from '~/constants/globalEvents'
import { AppPage, LanguageType } from '~/enums/appEnums'
import { accessKey, settings } from '~/logic'
import { getUserID, isHomePage, scrollToTop } from '~/utils/main'
Expand Down Expand Up @@ -109,6 +109,7 @@ onBeforeMount(() => {
})
onMounted(() => {
window.dispatchEvent(new CustomEvent(BEWLY_MOUNTED))
// openVideoPageIfBvidExists()
if (isHomePage()) {
Expand Down

0 comments on commit bc3b9d2

Please sign in to comment.