refactor: 使用监听选项方式来控制样式

This commit is contained in:
wsgh0202 2025-07-03 20:08:49 +08:00
parent 368cf8dd95
commit cb2f2ac859
No known key found for this signature in database
GPG Key ID: F9658C3FEDCF6979
2 changed files with 33 additions and 10 deletions

View File

@ -0,0 +1,11 @@
body.hide-home-carousel-full {
.recommended-swipe {
display: none !important;
}
}
body.hide-home-carousel-transparent {
.recommended-swipe {
opacity: 0;
}
}

View File

@ -1,14 +1,16 @@
import { defineComponentMetadata } from '@/components/define'
import { ComponentEntry } from '@/components/types'
import { select } from '@/core/spin-query'
import { addComponentListener } from '@/core/settings'
const entry: ComponentEntry = async ({ settings }) => {
select('.recommended-swipe').then((e: HTMLElement) => {
if (settings.options.keepPlaceholder) {
e.style.opacity = '0'
} else {
e.style.display = 'none'
}
const entry: ComponentEntry = async ({ metadata, settings }) => {
Object.keys(settings.options).forEach(disableType => {
addComponentListener(
`${metadata.name}.${disableType}`,
(value: boolean) => {
document.body.classList.toggle(`hide-home-carousel-${disableType}`, value)
},
true,
)
})
}
@ -18,9 +20,19 @@ export const component = defineComponentMetadata({
entry,
tags: [componentsTags.style],
urlInclude: [/^https:\/\/www\.bilibili\.com\/$/, /^https:\/\/www\.bilibili\.com\/index\.html$/],
instantStyles: [
{
name: 'hide-home-carousel',
style: () => import('./hide-home-carousel.scss'),
},
],
options: {
keepPlaceholder: {
displayName: '保留占位',
full: {
displayName: '完全隐藏',
defaultValue: true,
},
transparent: {
displayName: '透明化(保留占位)',
defaultValue: false,
},
},