Skip to content

Commit

Permalink
update: disable homepage preload
Browse files Browse the repository at this point in the history
  • Loading branch information
festoney8 committed Sep 10, 2024
1 parent 6fa832b commit 9c4cf5f
Showing 1 changed file with 4 additions and 61 deletions.
65 changes: 4 additions & 61 deletions src/rules/homepage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Group } from '../components/group'
import { CheckboxItem, NumberItem, RadioItem } from '../components/item'
import fetchHook from '../utils/fetch'
import { isPageHomepage } from '../utils/pageType'
import { debounce, waitForEle } from '../utils/tool'

const homepageGroupList: Group[] = []

Expand Down Expand Up @@ -511,71 +510,15 @@ if (isPageHomepage()) {
})
},
}),
// 启用 预加载下一屏
// 优化 视频载入
new CheckboxItem({
itemID: 'homepage-rcmd-video-preload',
description: '启用 预加载下一屏 (实验功能)\n需开启 隐藏分区视频推荐',
description: '优化 视频载入',
itemCSS: `
.load-more-anchor.preload {
position: fixed;
z-index: -99999;
visibility: hidden;
opacity: 0;
top: 0;
left: 0;
.bili-video-card:not(.is-rcmd):has(~ .load-more-anchor) {
display: none !important;
}
`,
enableFunc: async () => {
waitForEle(document.body, '.load-more-anchor', (node: HTMLElement) => {
return node.className === 'load-more-anchor'
}).then((anchor) => {
if (!anchor) {
return
}
const fireRcmdLoad = () => {
const firstSkeleton = document.querySelector(
'.bili-video-card:has(.bili-video-card__skeleton:not(.hide)):has(~ .load-more-anchor)',
) as HTMLElement
if (!firstSkeleton || firstSkeleton.getBoundingClientRect().top > innerHeight * 2) {
return
}

anchor.classList.add('preload')
new Promise<void>((resolve) => {
const id = setInterval(() => {
const firstSkeleton = document.querySelector(
'.bili-video-card:has(.bili-video-card__skeleton:not(.hide)):has(~ .load-more-anchor)',
) as HTMLElement
if (!firstSkeleton) {
clearInterval(id)
resolve()
}

if (firstSkeleton.getBoundingClientRect().top < innerHeight * 2) {
new Promise((resolve) => setTimeout(resolve, 20)).then(() => {
window.dispatchEvent(new Event('scroll'))
})
} else {
clearInterval(id)
resolve()
}
}, 200)
}).then(() => {
anchor.classList.remove('preload')
})
}

fireRcmdLoad()

const debounceFireRcmdLoad = debounce(fireRcmdLoad, 250, true)
window.addEventListener('wheel', (e: WheelEvent) => {
if (e.deltaY > 0) {
debounceFireRcmdLoad()
}
})
})
},
enableFuncRunAt: 'document-end',
}),
]
homepageGroupList.push(new Group('homepage-rcmd-list', '视频列表', rcmdListItems))
Expand Down

0 comments on commit 9c4cf5f

Please sign in to comment.