refactor: 修改选项为switch方式

This commit is contained in:
wsgh0202 2025-07-25 23:49:44 +08:00
parent 27f41b0370
commit b08f444fdc
No known key found for this signature in database
GPG Key ID: F9658C3FEDCF6979
3 changed files with 23 additions and 29 deletions

View File

@ -2,6 +2,7 @@
> 注意: 首页推广模块删除后留下空白区域是正常现象, 如果觉得怪可以开启 `占位文本` 选项.
- `占位文本`: 删除首页推广模块的广告后显示"🚫已屏蔽广告"来替代空白区域.
- `保留活动横幅`: 保留视频页面的活动横幅.
- `debug`: 调试模式,用于查看是否正确屏蔽广告
- `选项`
- `占位文本`: 删除首页推广模块的广告后显示"🚫已屏蔽广告"来替代空白区域.
- `调试模式`: 用于查看是否正确屏蔽广告

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,22 +81,20 @@ const entry: ComponentEntry = async ({ settings, metadata }) => {
},
true,
)
addComponentListener(
`${metadata.name}.showPlaceholder`,
(value: boolean) => {
document.body.classList.toggle('promotion-show-placeholder', value)
},
true,
)
addComponentListener(
`${metadata.name}.debug`,
(value: boolean) => {
document.body.classList.toggle('debug', value)
},
true,
)
}
export const component = defineComponentMetadata({
export const component = wrapSwitchOptions({
name: 'removePromotionOptions',
switches: {
showPlaceholder: {
displayName: '占位文本',
defaultValue: true,
},
debug: {
displayName: '调试模式',
defaultValue: false,
},
},
})({
name: 'removePromotions',
displayName: '删除广告',
entry,
@ -108,10 +106,6 @@ export const component = defineComponentMetadata({
],
tags: [componentsTags.utils],
options: {
showPlaceholder: {
displayName: '占位文本',
defaultValue: true,
},
preserveEventBanner: {
displayName: '保留活动横幅',
defaultValue: false,
@ -120,9 +114,5 @@ export const component = defineComponentMetadata({
displayName: '保留动态商品推荐',
defaultValue: false,
},
debug: {
displayName: '调试模式',
defaultValue: false,
},
},
})

View File

@ -91,6 +91,9 @@ body:not(.preserve-feed-goods) .bili-dyn-content__orig__additional:has(.dyn-good
margin: 0 !important;
}
// switch类型选项类名前缀
$switchPrefix: 'removePromotions-switch';
// 首页广告推广
.bili-video-card__wrap:has(.bili-video-card__stats > :is(.bili-video-card__stats--text, svg)),
// 视频搜索页广告
@ -116,16 +119,16 @@ body:not(.preserve-feed-goods) .bili-dyn-content__orig__additional:has(.dyn-good
background-color: #333;
}
body.promotion-show-placeholder & {
body.#{$switchPrefix}-showPlaceholder & {
visibility: visible;
}
body.debug & {
body.#{$switchPrefix}-debug & {
visibility: hidden !important;
}
}
body.debug & {
body.#{$switchPrefix}-debug & {
visibility: visible;
border: red 1px solid;
}