From 9c4cf5fa18fa9254575365e123cf1c6410094f31 Mon Sep 17 00:00:00 2001 From: festoney8 Date: Tue, 10 Sep 2024 17:03:48 +0800 Subject: [PATCH] update: disable homepage preload --- src/rules/homepage.ts | 65 +++---------------------------------------- 1 file changed, 4 insertions(+), 61 deletions(-) diff --git a/src/rules/homepage.ts b/src/rules/homepage.ts index 461bcbc3..72930be3 100644 --- a/src/rules/homepage.ts +++ b/src/rules/homepage.ts @@ -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[] = [] @@ -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((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))