Skip to content

Commit

Permalink
Merge pull request #76 from festoney8/dev
Browse files Browse the repository at this point in the history
merge dev to main, v3.6.2
  • Loading branch information
festoney8 committed May 26, 2024
2 parents f0bc1c0 + 85f4173 commit 99ee29c
Show file tree
Hide file tree
Showing 14 changed files with 392 additions and 16 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.6.2

- 新增:稍后再看列表页,双列布局
- 新增:修复字体(直播页、热门页、空间页、稍后再看)
- 新增:播放页 支持筛选视频结束后推荐视频
- 更新:直播页净化功能,适配网页变动

## 3.6.1

- 新增:动态页隐藏头像框
Expand Down
8 changes: 4 additions & 4 deletions src/components/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { debugComponents as debug, error } from '../utils/logger'

/** IItem是插件的每项功能设定, 在每个group内显示为一行组件 */
interface IItem {
readonly nodeHTML: myHTML
readonly nodeHTML: string
insertItem(groupID: string): void
insertItemCSS?(): void
removeItemCSS?(): void
Expand All @@ -27,7 +27,7 @@ interface ICheckboxItemOption {
defaultStatus?: boolean
itemFunc?: () => void
isItemFuncReload?: boolean
itemCSS?: myCSS
itemCSS?: string
callback?: () => void
}

Expand Down Expand Up @@ -198,7 +198,7 @@ interface IRadioItemOption {
defaultStatus?: boolean
itemFunc?: () => void
isItemFuncReload?: boolean
itemCSS?: myCSS
itemCSS?: string
}

/** 互斥开关 */
Expand Down Expand Up @@ -385,7 +385,7 @@ interface INumberItemOption {
maxValue: number
disableValue: number
unit: string
itemCSS?: myCSS
itemCSS?: string
// CSS中待替换为数值的占位符
itemCSSPlaceholder?: string
callback?: (value: number) => void
Expand Down
69 changes: 67 additions & 2 deletions src/filters/videoFilter/pages/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import coreFilterInstance, { VideoSelectorFunc } from '../filters/core'
import { ButtonItem, CheckboxItem, NumberItem } from '../../../components/item'
import { Group } from '../../../components/group'
import { isPagePlaylist, isPageVideo } from '../../../utils/page-type'
import { matchBvid, showEle, waitForEle } from '../../../utils/tool'
import { hideEle, isEleHide, matchBvid, showEle, waitForEle } from '../../../utils/tool'
import {
BvidAction,
DurationAction,
Expand All @@ -24,7 +24,8 @@ let isContextMenuUploaderEnable = false
let isContextMenuBvidEnable = false
// 接下来播放是否免过滤
let isNextPlayWhitelistEnable: boolean = GM_getValue('BILICLEANER_video-next-play-whitelist-filter-status', true)

// 视频结束后播放器内推荐是否免过滤
let isEndingWhitelistEnable: boolean = GM_getValue('BILICLEANER_video-ending-whitelist-filter-status', true)
if (isPageVideo() || isPagePlaylist()) {
let videoListContainer: HTMLElement
// 构建SelectorFunc
Expand Down Expand Up @@ -143,6 +144,52 @@ if (isPageVideo() || isPagePlaylist()) {
}
}

// 视频结束后筛选播放器内视频
const watchPlayerEnding = () => {
if (isEndingWhitelistEnable) {
return
}
const video = document.querySelector('video')
if (!video) {
return
}
const check = () => {
const rightList = document.querySelectorAll<HTMLElement>(`.next-play .video-page-card-small,
.next-play .video-page-operator-card-small,
.rec-list .video-page-card-small,
.rec-list .video-page-operator-card-small,
.recommend-video-card`)
const blacklistVideoTitle = new Set<string>()
rightList.forEach((video: HTMLElement) => {
if (isEleHide(video)) {
const title =
video.querySelector('.info > a p')?.getAttribute('title') ||
video.querySelector('.info > a p')?.textContent
title && blacklistVideoTitle.add(title)
}
})
let cnt = 0
const endingInterval = setInterval(() => {
const endingVideos = document.querySelectorAll<HTMLElement>('.bpx-player-ending-related-item')
if (endingVideos.length > 0) {
endingVideos.forEach((video: HTMLElement) => {
const title = video.querySelector('.bpx-player-ending-related-item-title')?.textContent?.trim()
if (title && blacklistVideoTitle.has(title)) {
hideEle(video)
}
})
clearInterval(endingInterval)
} else {
cnt++
if (cnt > 100) {
clearInterval(endingInterval)
}
}
}, 10)
}
video.ended ? check() : video.addEventListener('ended', check)
}

try {
// 监听视频列表出现
waitForEle(document, '#reco_list, .recommend-list-container', (node: Node): boolean => {
Expand All @@ -157,6 +204,8 @@ if (isPageVideo() || isPagePlaylist()) {
watchVideoListContainer()
}
})
// 监听视频播放结束,筛选播放器内视频推荐
document.addEventListener('DOMContentLoaded', watchPlayerEnding)
} catch (err) {
error(err)
error(`watch video list ERROR`)
Expand Down Expand Up @@ -389,6 +438,22 @@ if (isPageVideo() || isPagePlaylist()) {
checkVideoList(true)
},
}),
// 视频播放结束推荐 免过滤
new CheckboxItem({
itemID: 'video-ending-whitelist-filter-status',
description: '视频播放结束推荐 免过滤',
defaultStatus: true,
itemFunc: () => {
isEndingWhitelistEnable = true
document
.querySelectorAll<HTMLElement>('.bpx-player-ending-related-item')
.forEach((e: HTMLElement) => showEle(e))
},
callback: () => {
isEndingWhitelistEnable = false
watchPlayerEnding()
},
}),
// 启用 播放页UP主白名单
new CheckboxItem({
itemID: videoUploaderWhitelistAction.statusKey,
Expand Down
2 changes: 0 additions & 2 deletions src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export declare global {
type myCSS = string
type myHTML = string
interface Window {
isWide?: boolean
hasBlackSide?: boolean
Expand Down
4 changes: 4 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import { channelPageVideoFilterGroupList } from './filters/videoFilter/pages/cha
import { videoPageCommentFilterGroupList } from './filters/commentFilter/pages/video'
import { spacePageVideoFilterGroupList } from './filters/videoFilter/pages/space'
import { dynamicPageCommentFilterGroupList } from './filters/commentFilter/pages/dynamic'
import { watchlaterGroupList } from './rules/watchlater'
import { spaceGroupList } from './rules/space'

const main = async () => {
// 载入元素屏蔽规则
Expand All @@ -45,6 +47,8 @@ const main = async () => {
...dynamicGroupList,
...liveGroupList,
...channelGroupList,
...watchlaterGroupList,
...spaceGroupList,
...commonGroupList,
]
RULE_GROUPS.forEach((e) => e.enableGroup())
Expand Down
5 changes: 4 additions & 1 deletion src/rules/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import {
* 净化掉vd_source参数会导致充电窗口载入失败
*/
const cleanURL = () => {
if (location.href.includes('www.bilibili.com/correspond/')) {
return
}
// 直播域名各种iframe页面(天选、抽奖)和活动页特殊处理
if (location.href.match(/live\.bilibili\.com\/(p\/html|activity|blackboard)/)) {
return
Expand Down Expand Up @@ -90,7 +93,7 @@ const cleanURL = () => {
const commonGroupList: Group[] = []

// 通用 页面直角化,去除圆角,根据URL选取CSS
let borderRadiusCSS: myCSS = ''
let borderRadiusCSS = ''
if (isPageDynamic()) {
borderRadiusCSS = `
#nav-searchform,
Expand Down
2 changes: 1 addition & 1 deletion src/rules/homepage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ if (isPageHomepage()) {
itemID: 'homepage-hide-danmaku-count',
description: '隐藏 弹幕数',
defaultStatus: true,
itemCSS: `main:not(:has(.bilibili-app-recommend-root)) .bili-video-card__stats--item:nth-child(2) {visibility: hidden;}`,
itemCSS: `main:not(:has(.bilibili-app-recommend-root)) .bili-video-card__stats--item:nth-child(2) {display: none !important;}`,
}),
// 隐藏 稍后再看提示语
new CheckboxItem({
Expand Down
22 changes: 19 additions & 3 deletions src/rules/live.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Group } from '../components/group'
import { CheckboxItem } from '../components/item'
import { debugRules as debug } from '../utils/logger'
import { isPageLiveHome, isPageLiveRoom } from '../utils/page-type'
import settings from '../settings'

let isCleanLiveDanmakuRunning = false
// 清理计数结尾弹幕
Expand Down Expand Up @@ -98,6 +99,21 @@ if (isPageLiveRoom()) {
}
`,
}),
// 修复字体
new CheckboxItem({
itemID: 'font-patch',
description: '修复字体 (实验功能)\n直播/热门/空间/稍后再看页',
itemCSS: `
${settings.fontFaceRegular}
body,
.gift-item,
.feed-card,
.bb-comment, .comment-bilibili-fold {
font-family: PingFang SC, HarmonyOS_Regular, Helvetica Neue, Microsoft YaHei, sans-serif !important;
font-weight: 400;
}
`,
}),
]
liveGroupList.push(new Group('live-basic', '直播页 基本功能', basicItems))

Expand Down Expand Up @@ -429,10 +445,10 @@ if (isPageLiveRoom()) {
defaultStatus: true,
itemCSS: `.flip-view {display: none !important;}`,
}),
// 隐藏 直播间介绍
// 隐藏 直播间推荐
new CheckboxItem({
itemID: 'live-page-room-info-ctnr',
description: '隐藏 直播间介绍',
description: '隐藏 直播间推荐/直播间介绍',
itemCSS: `#sections-vm .room-info-ctnr {display: none !important;}`,
}),
// 隐藏 主播动态
Expand All @@ -445,7 +461,7 @@ if (isPageLiveRoom()) {
new CheckboxItem({
itemID: 'live-page-announcement-cntr',
description: '隐藏 主播公告',
itemCSS: `#sections-vm .announcement-cntr {display: none !important;}`,
itemCSS: `#sections-vm .room-detail-box {display: none !important;}`,
}),
// 隐藏 全部内容
new CheckboxItem({
Expand Down
23 changes: 22 additions & 1 deletion src/rules/popular.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Group } from '../components/group'
import { CheckboxItem, RadioItem } from '../components/item'
import { isPagePopular } from '../utils/page-type'
import settings from '../settings'

const popularGroupList: Group[] = []

Expand Down Expand Up @@ -153,6 +154,26 @@ if (isPagePopular()) {
margin-right: 0 !important;
}`,
}),
// 修复字体
new CheckboxItem({
itemID: 'font-patch',
description: '修复字体 (实验功能)\n直播/热门/空间/稍后再看页',
itemCSS: `
${settings.fontFaceRegular}
${settings.fontFaceMedium}
#internationalHeader,
.international-header,
.suggest-wrap,
.van-popover {
font-family: PingFang SC, HarmonyOS_Regular, Helvetica Neue, Microsoft YaHei, sans-serif !important;
font-weight: 400;
}
#app {
font-family: PingFang SC, HarmonyOS_Medium, Helvetica Neue, Microsoft YaHei, sans-serif !important;
font-weight: 500;
}
`,
}),
]
popularGroupList.push(new Group('popular-basic', '热门/排行榜页 基本功能', basicItems))

Expand Down Expand Up @@ -674,7 +695,7 @@ if (isPagePopular()) {
}`,
}),
]
popularGroupList.push(new Group('popular-layout', '页面强制布局 (单选,实验性)', layoutItems))
popularGroupList.push(new Group('popular-layout', '页面强制布局 (单选)', layoutItems))

// 综合热门
const hotItems = [
Expand Down
40 changes: 40 additions & 0 deletions src/rules/space.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Group } from '../components/group'
import { CheckboxItem } from '../components/item'
import { isPageSpace } from '../utils/page-type'
import settings from '../settings'

const spaceGroupList: Group[] = []

if (isPageSpace()) {
// 基本功能
const basicItems = [
// 修复字体
new CheckboxItem({
itemID: 'font-patch',
description: '修复字体 (实验功能)\n直播/热门/空间/稍后再看页',
itemCSS: `
${settings.fontFaceRegular}
body,
.h .h-sign,
.reply-item .root-reply-container .content-warp .user-info .user-name,
.bili-comment.browser-pc * {
font-family: PingFang SC, HarmonyOS_Regular, Helvetica Neue, Microsoft YaHei, sans-serif !important;
font-weight: 400;
}
body,
.n .n-text {
font-size: 14px;
}
#page-index .channel .channel-item .small-item,
#page-video .page-head__left .be-tab-item,
.n .n-data .n-data-k,
.n .n-data .n-data-v {
font-size: 13px;
}
`,
}),
]
spaceGroupList.push(new Group('space-basic', '空间页 基本功能', basicItems))
}

export { spaceGroupList }
Loading

0 comments on commit 99ee29c

Please sign in to comment.