From bc9fa114f2450157b22256b15d479ee929a5da53 Mon Sep 17 00:00:00 2001 From: festoney8 Date: Thu, 8 Aug 2024 07:00:57 +0800 Subject: [PATCH 1/6] fix: video page mini player position record --- CHANGELOG.md | 4 +++ src/rules/bangumi.ts | 60 ++++++++++++++++++-------------------------- vite.config.ts | 2 +- 3 files changed, 29 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08aba9a5..1f4de20e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 3.10.4 + +- 修复:番剧页 小窗播放器记录位置 + ## 3.10.3 - 新增:番剧播放页 默认宽屏播放 diff --git a/src/rules/bangumi.ts b/src/rules/bangumi.ts index d6dd28a7..f2f95abb 100644 --- a/src/rules/bangumi.ts +++ b/src/rules/bangumi.ts @@ -439,48 +439,36 @@ if (isPageBangumi()) { itemID: 'video-page-bpx-player-mini-mode-position-record', description: '记录小窗位置', enableFunc: async () => { - let player: HTMLElement - - // 监听mini播放器移动 - const addMiniPlayerMoveListener = () => { - if (!player) { - return - } - player.addEventListener('mouseup', () => { - if (player.getAttribute('data-screen') !== 'mini') { - return - } - GM_setValue( - 'BILICLEANER_video-page-bpx-player-mini-mode-position-record-right', - parseInt(player.style.right), - ) - GM_setValue( - 'BILICLEANER_video-page-bpx-player-mini-mode-position-record-bottom', - parseInt(player.style.bottom), - ) - }) + const keys = { + tx: 'BILICLEANER_video-page-bpx-player-mini-mode-position-record-translate-x', + ty: 'BILICLEANER_video-page-bpx-player-mini-mode-position-record-translate-y', } - // 设置player API内小窗播放器position初始值 - const setMiniPlayerState = () => { - const right = GM_getValue('BILICLEANER_video-page-bpx-player-mini-mode-position-record-right') - const bottom = GM_getValue('BILICLEANER_video-page-bpx-player-mini-mode-position-record-bottom') - if (typeof right === 'number' && typeof bottom === 'number') { - if (unsafeWindow.player) { - unsafeWindow.player.__core().uiStore.state.miniScreenRight = right - unsafeWindow.player.__core().uiStore.state.miniScreenBottom = bottom - } - } + + // 注入样式 + const x = GM_getValue(keys.tx, 0) + const y = GM_getValue(keys.ty, 0) + if (x && y) { + const s = document.createElement('style') + s.innerHTML = `.bpx-player-container[data-screen="mini"] {transform: translateX(${x}px) translateY(${y}px);}` + s.setAttribute('bili-cleaner-css', 'video-page-bpx-player-mini-mode-position-record') + document.documentElement.appendChild(s) } waitForEle(document.body, `#bilibili-player [class^="bpx-player-video"]`, (node: HTMLElement) => { return node.className.startsWith('bpx-player-video') }).then(() => { - player = document.querySelector('#bilibili-player .bpx-player-container') as HTMLElement - try { - setMiniPlayerState() - addMiniPlayerMoveListener() - } catch { - // err + const player = document.querySelector('.bpx-player-container') as HTMLElement + if (player) { + // 监听mini播放器移动 + player.addEventListener('mouseup', () => { + if (player.getAttribute('data-screen') === 'mini') { + const rect = player.getBoundingClientRect() + const dx = document.documentElement.clientWidth - rect.right + const dy = document.documentElement.clientHeight - rect.bottom + GM_setValue(keys.tx, 84 - dx) + GM_setValue(keys.ty, 48 - dy) + } + }) } }) }, diff --git a/vite.config.ts b/vite.config.ts index 7a4fb60c..a78895e9 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -8,7 +8,7 @@ export default defineConfig({ userscript: { name: 'bilibili 页面净化大师', namespace: 'http://tampermonkey.net/', - version: '3.10.3', + version: '3.10.4', description: '净化 B站/哔哩哔哩 页面,支持「精简功能、播放器净化、过滤视频、过滤评论、全站黑白名单」,提供 300+ 功能,定制自己的 B 站', author: 'festoney8', From 3f2e83cc1e083bc840c475d17bbb653e514c69ea Mon Sep 17 00:00:00 2001 From: festoney8 Date: Sun, 11 Aug 2024 01:50:52 +0800 Subject: [PATCH 2/6] feat: video page disable danmaku abtest --- CHANGELOG.md | 1 + src/global.d.ts | 3 +++ src/rules/video.ts | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f4de20e..0431e349 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## 3.10.4 +- 新增:播放页 禁用弹幕云屏蔽灰测 - 修复:番剧页 小窗播放器记录位置 ## 3.10.3 diff --git a/src/global.d.ts b/src/global.d.ts index 4d5c7050..8b6e008f 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -3,6 +3,9 @@ export declare global { isWide?: boolean hasBlackSide?: boolean setSize?: function + webAbTest?: { + danmuku_block_version?: string + } vd?: { aid?: number bvid?: string diff --git a/src/rules/video.ts b/src/rules/video.ts index b9f4e1e1..f9252e1e 100644 --- a/src/rules/video.ts +++ b/src/rules/video.ts @@ -174,6 +174,29 @@ if (isPageVideo() || isPagePlaylist()) { description: '顶栏 滚动页面后不再吸附顶部', itemCSS: `.fixed-header .bili-header__bar {position: relative !important;}`, }), + // 禁用 弹幕云屏蔽灰测 默认开启 + new CheckboxItem({ + itemID: 'video-page-disable-danmaku-abtest', + description: '禁用 弹幕云屏蔽灰测 (临时功能)', + defaultStatus: true, + enableFunc: () => { + let origValue = unsafeWindow.webAbTest + if (origValue) { + origValue.danmuku_block_version = 'OLD' + } + Object.defineProperty(unsafeWindow, 'webAbTest', { + get() { + return origValue + }, + set(value) { + if (value) { + value.danmuku_block_version = 'OLD' + } + origValue = value + }, + }) + }, + }), ] videoGroupList.push(new Group('video-basic', '播放页 基本功能', basicItems)) From 4be4248c5892194594b5cc8abcb88d4565be5249 Mon Sep 17 00:00:00 2001 From: festoney8 Date: Mon, 12 Aug 2024 03:42:32 +0800 Subject: [PATCH 3/6] update: live page item --- src/rules/live.ts | 2 +- src/utils/pageType.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rules/live.ts b/src/rules/live.ts index c6ea4974..c073708c 100644 --- a/src/rules/live.ts +++ b/src/rules/live.ts @@ -491,7 +491,7 @@ if (isPageLiveRoom()) { itemID: 'live-page-convention-msg', description: '隐藏 系统提示', defaultStatus: true, - itemCSS: `.convention-msg.border-box {display: none !important;}`, + itemCSS: `.convention-msg.border-box, .new-video-pk-item-dm {display: none !important;}`, }), // 隐藏 用户排名 new CheckboxItem({ diff --git a/src/utils/pageType.ts b/src/utils/pageType.ts index f8375cc6..4232af5f 100644 --- a/src/utils/pageType.ts +++ b/src/utils/pageType.ts @@ -11,7 +11,7 @@ const currPage = (): string => { ) { return 'invalid' } - if (href.startsWith('https://www.bilibili.com/') && ['/index.html', '/'].includes(pathname)) { + if (href.startsWith('https://www.bilibili.com') && ['/index.html', '/'].includes(pathname)) { return 'homepage' } if (href.includes('bilibili.com/video/')) { @@ -32,11 +32,11 @@ const currPage = (): string => { } if (host === 'live.bilibili.com') { // 匹配blanc页(赛事直播or活动直播用),用于对iframe内直播生效 - if (pathname.match(/^\/(?:blanc\/)?\d+(#\/)?/)) { + if (/^\/(?:blanc\/)?\d+(#\/)?/.test(pathname)) { return 'liveRoom' } // 匹配各种直播页iframe、直播活动, 不做处理 - if (href.match(/live\.bilibili\.com\/(p\/html|activity|blackboard)/)) { + if (/live\.bilibili\.com\/(p\/html|activity|blackboard)/.test(href)) { return '' } return 'liveHome' From 8f02c4743196288a1d90023d0c92c36657cb3217 Mon Sep 17 00:00:00 2001 From: festoney8 Date: Mon, 12 Aug 2024 04:46:17 +0800 Subject: [PATCH 4/6] update: video page hide danmaku sending area --- CHANGELOG.md | 1 + src/rules/video.ts | 90 +++++++++------------------------------------- 2 files changed, 17 insertions(+), 74 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0431e349..384bb598 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 3.10.4 - 新增:播放页 禁用弹幕云屏蔽灰测 +- 优化:播放页 非全屏隐藏弹幕栏 - 修复:番剧页 小窗播放器记录位置 ## 3.10.3 diff --git a/src/rules/video.ts b/src/rules/video.ts index f9252e1e..e44c46e9 100644 --- a/src/rules/video.ts +++ b/src/rules/video.ts @@ -1,6 +1,6 @@ import { Group } from '../components/group' import { CheckboxItem, NumberItem } from '../components/item' -import { debugRules as debug, error } from '../utils/logger' +import { error } from '../utils/logger' import { matchAvidBvid, matchBvid, waitForEle } from '../utils/tool' import { isPageFestival, isPagePlaylist, isPageVideo } from '../utils/pageType' import { GM_getValue, GM_setValue, unsafeWindow } from '$' @@ -227,7 +227,7 @@ if (isPageVideo() || isPagePlaylist()) { } }) } - document.addEventListener('DOMContentLoaded', listener) + document.readyState !== 'loading' ? listener() : document.addEventListener('DOMContentLoaded', listener) }, disableFunc: async () => { wideScreenLock = false @@ -1166,84 +1166,26 @@ if (isPageVideo() || isPagePlaylist() || isPageFestival()) { itemID: 'video-page-hide-bpx-player-sending-area', description: '非全屏下 关闭弹幕栏', itemCSS: ` - /* video page的player height由JS动态设定 */ - .bpx-player-sending-area {display: none !important;} + .bpx-player-sending-area { + display: none !important; + } + #bilibili-player-placeholder-bottom { + display: none !important; + } + #playerWrap:has(.bpx-player-container:not([data-screen="web"], [data-screen="full"])) { + height: unset !important; + aspect-ratio: 16 / 9; + } + #playerWrap:has(.bpx-player-container:not([data-screen="web"], [data-screen="full"])) #bilibili-player { + height: unset !important; + aspect-ratio: 16 / 9; + } /* 活动播放器直接去黑边 */ .page-main-content:has(.festival-video-player) .video-player-box {height: fit-content !important;} .festival-video-player {height: fit-content !important;} .festival-video-player #bilibili-player:not(.mode-webscreen) {height: calc(100% - 46px) !important;} `, - // 隐藏弹幕栏时,强行调节播放器高度 - enableFunc: async () => { - // 念咒 - const genSizeCSS = (): string => { - const e = unsafeWindow.isWide - const i = unsafeWindow.innerHeight - const t = Math.max((document.body && document.body.clientWidth) || unsafeWindow.innerWidth, 1100) - const n = 1680 < innerWidth ? 411 : 350 - const o = (16 * (i - (1690 < innerWidth ? 318 : 308))) / 9 - const r = t - 112 - n - let d = r < o ? r : o - if (d < 668) { - d = 668 - } - if (1694 < d) { - d = 1694 - } - let a = d + n - if (unsafeWindow.isWide) { - a -= 125 - d -= 100 - } - let l - if (unsafeWindow.hasBlackSide && !unsafeWindow.isWide) { - l = Math.round((d - 14 + (e ? n : 0)) * 0.5625) + 96 - } else { - l = Math.round((d + (e ? n : 0)) * 0.5625) - } - const s = ` - .video-container-v1 {width: auto;padding: 0 10px;} - .left-container {width: ${a - n}px;} - #bilibili-player {width: ${a - (e ? -30 : n)}px;height: ${l}px;position: ${e ? 'relative' : 'static'};} - #oldfanfollowEntry {position: relative;top: ${e ? `${l + 10}px` : '0'};} - #danmukuBox {margin-top: ${e ? `${l + 28}px` : '0'};} - #playerWrap {height: ${l}px;} - .video-discover {margin-left: ${(a - n) / 2}px;} - ` - return s.replace(/\n\s*/g, '').trim() - } - - // override CSS - // 插入新style覆盖(必须在原style出现后,appendChild在head尾部,权限更高) - const overrideCSS = () => { - const overrideStyle = document.getElementById('overrideSetSizeStyle') as HTMLStyleElement - if (!overrideStyle) { - const newStyleNode = document.createElement('style') - newStyleNode.id = 'overrideSetSizeStyle' - newStyleNode.innerHTML = genSizeCSS() - document.head.appendChild(newStyleNode) - debug('override setSize OK') - } else { - overrideStyle.innerHTML = genSizeCSS() - debug('refresh setSize OK') - } - } - - if (document.getElementById('setSizeStyle')) { - overrideCSS() - } - // 监听官方style #setSizeStyle 出现 - const observeStyle = new MutationObserver(() => { - if (document.getElementById('setSizeStyle')) { - overrideCSS() - observeStyle.disconnect() - } - }) - document.head && observeStyle.observe(document.head, { childList: true }) - // 宽屏模式 - onIsWideChangeFnArr.push(overrideCSS) - }, }), // 全屏下 关闭弹幕输入框 new CheckboxItem({ From b01de8777d2010f9a8e6600a374059e201e5ada9 Mon Sep 17 00:00:00 2001 From: festoney8 Date: Mon, 12 Aug 2024 12:05:15 +0800 Subject: [PATCH 5/6] update: video page normalscreen width --- CHANGELOG.md | 4 ++-- src/rules/video.ts | 60 +++++++--------------------------------------- 2 files changed, 11 insertions(+), 53 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 384bb598..ed7f2596 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,9 @@ ## 3.10.4 -- 新增:播放页 禁用弹幕云屏蔽灰测 -- 优化:播放页 非全屏隐藏弹幕栏 - 修复:番剧页 小窗播放器记录位置 +- 新增:播放页 禁用弹幕云屏蔽灰测 +- 优化:播放页 非全屏隐藏弹幕栏、播放器宽度调节 ## 3.10.3 diff --git a/src/rules/video.ts b/src/rules/video.ts index e44c46e9..0c44a948 100644 --- a/src/rules/video.ts +++ b/src/rules/video.ts @@ -521,71 +521,29 @@ if (isPageVideo() || isPagePlaylist()) { disableValue: -1, unit: 'vw', itemCSS: ` - /* 魔法, 勿动 */ :root { --normal-width: min(calc(100vw - 400px), ???vw); - --normal-height: calc(min(calc(100vw - 400px), ???vw) * 9 / 16); } - - #bilibili-player-placeholder { - visibility: hidden !important; - } - /* 需避免右侧视频预览 inline player 影响 data-screen变化慢, 播放模式判断一律用:not(), 使用html元素的bili-cleaner-is-wide加快wide模式判断 */ - /* 左列basis宽度 */ + /* 左列宽度 */ html:not([bili-cleaner-is-wide]) :is(.left-container, .playlist-container--left):has(.bpx-player-container:not([data-screen="wide"], [data-screen="web"], [data-screen="full"])) { - flex-basis: var(--normal-width); + flex-basis: var(--normal-width) !important; } - /* 播放器长宽限制 */ + /* 播放器长宽 */ html:not([bili-cleaner-is-wide]) :is(.left-container, .playlist-container--left):has(.bpx-player-container:not([data-screen="wide"], [data-screen="web"], [data-screen="full"], [data-screen="mini"])) :is(.bpx-player-video-area, video) { width: 100% !important; - height: var(--normal-height) !important; - min-height: var(--normal-height) !important; - max-height: var(--normal-height) !important; + height: unset !important; + aspect-ratio: 16 / 9 !important; } /* 播放器外层 */ html:not([bili-cleaner-is-wide]) :is(.left-container, .playlist-container--left):has(.bpx-player-container:not([data-screen="wide"], [data-screen="web"], [data-screen="full"], [data-screen="mini"])) :is(.bpx-player-primary-area, .bpx-player-container, .bpx-docker-major, #bilibili-player, #playerWrap) { - width: var(--normal-width); - height: fit-content; - max-height: calc(var(--normal-height) + 56px); - } - /* 普通mini模式 主播放器支撑 */ - html:not([bili-cleaner-is-wide]) #playerWrap:has(.bpx-player-container[data-screen="mini"]) { - background-color: transparent; - width: var(--normal-width); - height: calc(var(--normal-height) + 46px); - min-height: var(--normal-height); - max-height: calc(var(--normal-height) + 56px); - position: relative; - } - html:not([bili-cleaner-is-wide]) #playerWrap:has(.bpx-player-container[data-screen="mini"])::before { - content: ''; - position: absolute; - top: 0; - left: 0; - width: 100%; - height: calc(100% - 46px); - background-color: black; - } - /* 宽屏mini模式 主播放器支撑 */ - html[bili-cleaner-is-wide] #playerWrap:has(.bpx-player-container[data-screen="mini"]) { - background-color: transparent; - width: fit-content; - position: relative; - } - html[bili-cleaner-is-wide] #playerWrap:has(.bpx-player-container[data-screen="mini"])::before { - content: ''; - position: absolute; - top: 0; - left: 0; - width: 100%; - height: calc(100% - 46px); - background-color: black; - } - `, + width: var(--normal-width) !important; + height: unset !important; + min-height: calc(var(--normal-width) * 9 / 16) !important; + }`, itemCSSPlaceholder: '???', }), ] From 8cfb2778b35123486becc816c78381e7ee3fc4bb Mon Sep 17 00:00:00 2001 From: festoney8 Date: Tue, 13 Aug 2024 06:00:35 +0800 Subject: [PATCH 6/6] feat: video page hide right container #121 --- CHANGELOG.md | 3 ++- src/rules/video.ts | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed7f2596..da6d0a95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,9 @@ ## 3.10.4 - 修复:番剧页 小窗播放器记录位置 -- 新增:播放页 禁用弹幕云屏蔽灰测 - 优化:播放页 非全屏隐藏弹幕栏、播放器宽度调节 +- 新增:播放页 禁用弹幕云屏蔽灰测 +- 新增:播放页 隐藏右栏 ## 3.10.3 diff --git a/src/rules/video.ts b/src/rules/video.ts index 0c44a948..580dd07c 100644 --- a/src/rules/video.ts +++ b/src/rules/video.ts @@ -1392,10 +1392,10 @@ if (isPageVideo() || isPagePlaylist()) { itemCSS: `#reco_list .next-play {display: none !important;} #reco_list .rec-list {margin-top: 0 !important;}`, }), - // 视频合集 增加合集列表高度, 默认开启 + // 优化 视频合集列表高度, 默认开启 new CheckboxItem({ itemID: 'video-page-hide-right-container-section-height', - description: '视频合集 增加合集列表高度', + description: '优化 视频合集列表高度', defaultStatus: true, itemCSS: `.base-video-sections-v1 .video-sections-content-list {height: fit-content !important; max-height: 350px !important;} .video-sections-v1 .video-sections-content-list {height: fit-content !important; max-height: 350px !important;}`, @@ -1507,10 +1507,10 @@ if (isPageVideo() || isPagePlaylist()) { justify-content: space-between; }`, }), - // 隐藏 相关视频 全部列表 + // 隐藏 全部相关视频 new CheckboxItem({ itemID: 'video-page-hide-right-container-reco-list-rec-list', - description: '隐藏 相关视频 全部列表', + description: '隐藏 全部相关视频', itemCSS: `#reco_list .rec-list {display: none !important;} #reco_list .rec-footer {display: none !important;} /* 适配watchlater, favlist */ @@ -1550,6 +1550,15 @@ if (isPageVideo() || isPagePlaylist()) { } `, }), + // 隐藏 整个右栏 + new CheckboxItem({ + itemID: 'video-page-hide-right-container', + description: '隐藏 整个右栏 (宽屏模式不适用)', + itemCSS: ` + html:not([bili-cleaner-is-wide]) .right-container { + display: none !important; + }`, + }), ] videoGroupList.push(new Group('video-right', '右侧 视频栏', rightItems))