Skip to content

Commit

Permalink
Merge pull request #94 from festoney8/dev
Browse files Browse the repository at this point in the history
merge dev to main, v3.7.4
  • Loading branch information
festoney8 authored Jun 26, 2024
2 parents 5e8a57b + 541854d commit 53bb63c
Show file tree
Hide file tree
Showing 12 changed files with 360 additions and 35 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## 3.7.4

- 修复:动态页 隐藏动态右侧饰品
- 新增:播放页/番剧页 全屏时页面可滚动
- 新增:首页 推荐视频预加载下一屏

## 3.7.3

- 新增:直播页 隐藏倒计时互动
Expand Down
3 changes: 1 addition & 2 deletions src/filters/videoFilter/pages/homepage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
UploaderKeywordAction,
UploaderWhitelistAction,
} from './actions/action'
import { GM_getValue } from '$'

const homepagePageVideoFilterGroupList: Group[] = []

Expand All @@ -24,7 +23,7 @@ let isContextMenuFuncRunning = false
let isContextMenuUploaderEnable = false
let isContextMenuBvidEnable = false
// 带已关注tag的视频不被过滤
let isFollowingWhitelistEnable: boolean = GM_getValue('BILICLEANER_homepage-following-whitelist-filter-status', true)
let isFollowingWhitelistEnable = true

if (isPageHomepage()) {
let videoListContainer: HTMLElement
Expand Down
118 changes: 116 additions & 2 deletions src/rules/bangumi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ if (isPageBangumi()) {
}
`,
enableFunc: async () => {
// 在Chrome上可以神奇的禁用滚轮调节音量,Firefox不生效
// 禁用滚动调音量
document.removeEventListener('wheel', disableAdjustVolume)
document.addEventListener('wheel', disableAdjustVolume)

// 监听网页全屏按钮出现
waitForEle(document.body, '.bpx-player-ctrl-web', (node: HTMLElement): boolean => {
return node.className.includes('bpx-player-ctrl-web')
Expand All @@ -112,6 +114,118 @@ if (isPageBangumi()) {
enableFuncRunAt: 'document-end',
disableFunc: async () => document.removeEventListener('wheel', disableAdjustVolume),
}),
// 全屏时 页面可滚动
new CheckboxItem({
itemID: 'fullscreen-scrollable',
description: '全屏时 页面可滚动 滚轮调音量失效\n(实验功能,Firefox 不适用)',
itemCSS: `
body:has(#bilibili-player-wrap[class*='video_playerFullScreen']) {
overflow: auto !important;
position: relative !important;
}
body:has(#bilibili-player-wrap[class*='video_playerFullScreen']) .home-container {
background-color: white;
}
body:has(#bilibili-player-wrap[class*='video_playerFullScreen']) #bilibili-player-wrap {
position: absolute !important;
width: 100vw !important;
height: 100vh !important;
}
body:has(#bilibili-player-wrap[class*='video_playerFullScreen']) .main-container {
position: static !important;
margin: 0 auto !important;
padding-top: calc(100vh + 15px) !important;
}
body:has(#bilibili-player-wrap[class*='video_playerFullScreen']) .bpx-player-video-area {
flex: unset !important;
}
body:has(#bilibili-player-wrap[class*='video_playerFullScreen'])::-webkit-scrollbar {
display: none !important;
}
/* firefox */
@-moz-document url-prefix() {
:is(html, body):has(#bilibili-player-wrap[class*='video_playerFullScreen']) {
scrollbar-width: none !important;
}
}
`,
enableFunc: async () => {
if (!navigator.userAgent.toLocaleLowerCase().includes('chrome')) {
return
}

// 禁用滚动调音量
document.removeEventListener('wheel', disableAdjustVolume)
document.addEventListener('wheel', disableAdjustVolume)

let cnt = 0
const id = setInterval(() => {
const webBtn = document.body.querySelector(
'.bpx-player-ctrl-btn.bpx-player-ctrl-web',
) as HTMLElement
const fullBtn = document.body.querySelector(
'.bpx-player-ctrl-btn.bpx-player-ctrl-full',
) as HTMLElement
if (webBtn && fullBtn) {
clearInterval(id)

const isFullScreen = (): 'ele' | 'f11' | 'not' => {
if (document.fullscreenElement) {
// 由元素申请的全屏
return 'ele'
} else if (window.innerWidth === screen.width && window.innerHeight === screen.height) {
// 用户F11的全屏
return 'f11'
} else {
// 非全屏
return 'not'
}
}

const isWebScreen = (): boolean => {
return webBtn.classList.contains('bpx-state-entered')
}

// 全屏可滚动 = 网页全屏功能 + html/body元素申请全屏
const newFullBtn = fullBtn.cloneNode(true)
newFullBtn.addEventListener('click', () => {
switch (isFullScreen()) {
case 'ele':
if (isWebScreen()) {
// 退出网页全屏,自动退出全屏
webBtn.click()
} else {
document.exitFullscreen().then().catch()
}
break
case 'f11':
// f11全屏模式
if (isWebScreen()) {
webBtn.click()
} else {
webBtn.click()
}
break
case 'not':
// 申请可滚动全屏
document.body.requestFullscreen().then().catch()
if (!isWebScreen()) {
webBtn.click()
}
window.scrollTo(0, 0)
break
}
})
fullBtn.parentElement?.replaceChild(newFullBtn, fullBtn)
} else {
cnt++
cnt > 100 && clearInterval(id)
}
}, 100)
},
enableFuncRunAt: 'document-end',
disableFunc: async () => document.removeEventListener('wheel', disableAdjustVolume),
}),
// 普通播放 视频宽度调节
new NumberItem({
itemID: 'normalscreen-width',
Expand All @@ -126,7 +240,7 @@ if (isPageBangumi()) {
itemCSSPlaceholder: '???',
}),
]
bangumiGroupList.push(new Group('player-mode', '播放设定(实验功能)', playerInitItems))
bangumiGroupList.push(new Group('player-mode', '播放设定', playerInitItems))

// 播放器
const playerItems = [
Expand Down
4 changes: 2 additions & 2 deletions src/rules/dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ if (isPageDynamic()) {
// 修复字体
new CheckboxItem({
itemID: 'font-patch',
description: '修复字体 (实验功能)',
description: '修复字体',
itemCSS: fontPatchCSS,
}),
]
Expand Down Expand Up @@ -243,7 +243,7 @@ if (isPageDynamic()) {
new CheckboxItem({
itemID: 'hide-dynamic-page-bili-dyn-ornament',
description: '隐藏 动态右侧饰品',
itemCSS: `.bili-dyn-ornament {display: none !important;}`,
itemCSS: `.bili-dyn-ornament, .bili-dyn-item__ornament {display: none !important;}`,
}),
// 隐藏 动态内容中 警告notice, 默认开启
new CheckboxItem({
Expand Down
73 changes: 70 additions & 3 deletions src/rules/homepage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { unsafeWindow } from '$'
import { Group } from '../components/group'
import { CheckboxItem, NumberItem, RadioItem } from '../components/item'
import { isPageHomepage } from '../utils/page-type'
import { debounce, waitForEle } from '../utils/tool'

const homepageGroupList: Group[] = []

Expand Down Expand Up @@ -345,7 +346,7 @@ if (isPageHomepage()) {
background-color: unset !important;
border-radius: unset !important;
margin: 0 2px 0 0 !important;
font-size: unset !important;
font-size: 0 !important;
line-height: unset !important;
padding: unset !important;
user-select: none !important;
Expand Down Expand Up @@ -485,10 +486,10 @@ if (isPageHomepage()) {
// 增大 视频载入 视频数量
new CheckboxItem({
itemID: 'homepage-increase-rcmd-load-size',
description: '增大 视频载入 视频数量 (实验性)',
description: '增大 视频载入 视频数量 (实验功能)',
itemCSS: `
/* 扩增载入后会产生奇怪的骨架空位 */
.floor-single-card:has(.skeleton, .skeleton-item) {
.container.is-version8 > .floor-single-card:has(.skeleton, .skeleton-item, .floor-skeleton) {
display: none;
}`,
enableFunc: async () => {
Expand All @@ -507,6 +508,72 @@ if (isPageHomepage()) {
}
},
}),
// 启用 预加载下一屏
new CheckboxItem({
itemID: 'homepage-rcmd-video-preload',
description: '启用 预加载下一屏 (实验功能)\n需开启 隐藏分区视频推荐',
itemCSS: `
.load-more-anchor.preload {
position: fixed;
z-index: -99999;
visibility: hidden;
opacity: 0;
top: 0;
left: 0;
}
`,
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
2 changes: 1 addition & 1 deletion src/rules/live.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ if (isPageLiveRoom()) {
// 修复字体
new CheckboxItem({
itemID: 'font-patch',
description: '修复字体 (实验功能)',
description: '修复字体',
itemCSS: `
${fontFaceRegular}
body,
Expand Down
2 changes: 1 addition & 1 deletion src/rules/popular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ if (isPagePopular()) {
// 修复字体
new CheckboxItem({
itemID: 'font-patch',
description: '修复字体 (实验功能)',
description: '修复字体',
itemCSS: `
${fontFaceRegular}
${fontFaceMedium}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (isPageSpace()) {
// 修复字体
new CheckboxItem({
itemID: 'font-patch',
description: '修复字体 (实验功能)',
description: '修复字体',
itemCSS: `
${fontFaceRegular}
body,
Expand Down
Loading

0 comments on commit 53bb63c

Please sign in to comment.