Skip to content

Commit

Permalink
Merge pull request #124 from festoney8/dev
Browse files Browse the repository at this point in the history
merge dev to main, v3.10.4
  • Loading branch information
festoney8 authored Aug 15, 2024
2 parents 1b0a0a9 + 8cfb277 commit 8e635c0
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 170 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

## 3.10.4

- 修复:番剧页 小窗播放器记录位置
- 优化:播放页 非全屏隐藏弹幕栏、播放器宽度调节
- 新增:播放页 禁用弹幕云屏蔽灰测
- 新增:播放页 隐藏右栏

## 3.10.3

- 新增:番剧播放页 默认宽屏播放
Expand Down
3 changes: 3 additions & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ export declare global {
isWide?: boolean
hasBlackSide?: boolean
setSize?: function
webAbTest?: {
danmuku_block_version?: string
}
vd?: {
aid?: number
bvid?: string
Expand Down
60 changes: 24 additions & 36 deletions src/rules/bangumi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
})
},
Expand Down
2 changes: 1 addition & 1 deletion src/rules/live.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
190 changes: 61 additions & 129 deletions src/rules/video.ts
Original file line number Diff line number Diff line change
@@ -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 '$'
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -204,7 +227,7 @@ if (isPageVideo() || isPagePlaylist()) {
}
})
}
document.addEventListener('DOMContentLoaded', listener)
document.readyState !== 'loading' ? listener() : document.addEventListener('DOMContentLoaded', listener)
},
disableFunc: async () => {
wideScreenLock = false
Expand Down Expand Up @@ -498,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: '???',
}),
]
Expand Down Expand Up @@ -1143,84 +1124,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({
Expand Down Expand Up @@ -1469,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;}`,
Expand Down Expand Up @@ -1584,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 */
Expand Down Expand Up @@ -1627,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))

Expand Down
6 changes: 3 additions & 3 deletions src/utils/pageType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/')) {
Expand All @@ -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'
Expand Down
Loading

0 comments on commit 8e635c0

Please sign in to comment.