Merge branch 'preview-fixes' of https://github.com/the1812/Bilibili-Evolved into preview-fixes

This commit is contained in:
the1812 2025-08-01 08:48:00 +08:00
commit 4840c2f83d
3 changed files with 71 additions and 21 deletions

View File

@ -1,4 +1,7 @@
删除站内的各种广告. 包括首页的推广模块, 手机 app 推荐, 视频页面右侧的广告等. 注意: 首页推广模块删除后留下空白区域是正常现象, 如果觉得怪可以开启 \`占位文本\` 选项.
删除站内的各种广告. 包括首页的推广模块, 手机 app 推荐, 视频页面右侧的广告等.
- \`占位文本\`: 删除首页推广模块的广告后显示"🚫已屏蔽广告"来替代空白区域.
- \`保留活动横幅\`: 保留视频页面的活动横幅.
- `保留活动横幅`: 保留视频页面的活动横幅.
- `选项`
- `卡片占位`: 关闭时广告卡片将完全隐藏,后续的视频卡片会自动补上空缺位置
- `占位文本`: 屏蔽首页推广模块的广告后显示"🚫已屏蔽广告"来替代空白区域.
- `调试模式`: 用于查看是否正确屏蔽广告,启用时将边框高亮广告卡片,同时其他屏蔽选项会失效

View File

@ -1,5 +1,5 @@
import { ComponentEntry } from '@/components/types'
import { defineComponentMetadata } from '@/components/define'
import { wrapSwitchOptions } from '@/components/switch-options'
// const PromotionMark = 'data-be-promotion-mark'
const entry: ComponentEntry = async ({ settings, metadata }) => {
@ -81,15 +81,24 @@ const entry: ComponentEntry = async ({ settings, metadata }) => {
},
true,
)
addComponentListener(
`${metadata.name}.showPlaceholder`,
(value: boolean) => {
document.body.classList.toggle('promotion-show-placeholder', value)
},
true,
)
}
export const component = defineComponentMetadata({
export const component = wrapSwitchOptions({
name: 'removePromotionOptions',
switches: {
showContainer: {
displayName: '卡片占位',
defaultValue: true,
},
showPlaceholder: {
displayName: '占位文本',
defaultValue: true,
},
debug: {
displayName: '调试模式',
defaultValue: false,
},
},
})({
name: 'removePromotions',
displayName: '删除广告',
entry,
@ -101,10 +110,6 @@ export const component = defineComponentMetadata({
],
tags: [componentsTags.utils],
options: {
showPlaceholder: {
displayName: '占位文本',
defaultValue: true,
},
preserveEventBanner: {
displayName: '保留活动横幅',
defaultValue: false,

View File

@ -90,9 +90,51 @@ body.dark .blocked-ads.new {
body:not(.preserve-feed-goods) .bili-dyn-content__orig__additional:has(.dyn-goods) {
margin: 0 !important;
}
.feed-card:has(.bili-video-card a[href*='cm.bilibili.com']),
.bili-video-card.is-rcmd:has(a[href*='cm.bilibili.com']),
.bili-video-card__wrap:has(a[href*='cm.bilibili.com']),
body:not(.promotion-show-placeholder) :is(.bili-video-card.is-rcmd, .bili-feed4-layout .feed-card):not(:has(.bili-video-card__wrap)) {
display: none !important;
// switch类型选项类名前缀
$switchPrefix: 'removePromotions-switch';
// 首页广告推广
.container > :is(.feed-card, .bili-feed-card):has(.bili-video-card__stats > :is(.bili-video-card__stats--text, svg)),
// 视频搜索页广告
.video-list-item:has(.bili-video-card__info--ad) {
visibility: hidden;
pointer-events: none !important;
// 占位文本
& .bili-video-card__image::after {
@extend .blocked-ads;
content: '🚫已屏蔽广告';
width: 100%;
height: 100%;
position: absolute;
top: 0;
user-select: none;
visibility: hidden;
border-radius: 6px;
background-color: #eee;
body.dark & {
background-color: #333;
}
body.#{$switchPrefix}-showPlaceholder & {
visibility: visible;
}
body.#{$switchPrefix}-debug & {
visibility: hidden !important;
}
}
body:not(.#{$switchPrefix}-showContainer) & {
display: none;
}
body.#{$switchPrefix}-debug & {
display: unset;
visibility: visible;
border: red 1px solid;
}
}