Merge pull request #5207 from magicFeirl/preview-features-trending-search-liveroom

[功能 - 组件 - 隐藏热搜] 添加直播间搜索框的热搜隐藏功能
This commit is contained in:
Grant Howard 2025-04-12 13:38:15 +08:00 committed by GitHub
commit b3189a328c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 9 deletions

View File

@ -1,9 +1,8 @@
.search-panel {
.search-panel, .search-pannel {
> .trending {
display: none !important;
}
&:not(:has(.history)) {
padding: 0 !important;
border: none !important;

View File

@ -9,6 +9,26 @@ const resetPlaceholder = (input: HTMLInputElement) => {
input.title = DEFAULT_PLACEHOLDER
}
const isInLiveRoomPage = () => {
return window.location.host === 'live.bilibili.com'
}
const getSearchInputClassName = () => {
return isInLiveRoomPage() ? 'input.nav-search-content' : 'input.nav-search-input'
}
const isSearchInput = (target: Node) => {
if (!(target instanceof HTMLInputElement)) {
return false
}
const isSearch = ['nav-search-content', 'nav-search-input'].some(n =>
target.classList.contains(n),
)
return target.placeholder !== DEFAULT_PLACEHOLDER && isSearch
}
export const component = defineComponentMetadata({
name: 'hideTrendingSearch',
displayName: '隐藏热搜',
@ -20,7 +40,8 @@ export const component = defineComponentMetadata({
},
],
entry: async () => {
const input: HTMLInputElement = await select('input.nav-search-input', {
const clsName = getSearchInputClassName()
const input: HTMLInputElement = await select(clsName, {
queryInterval: 500,
})
@ -32,12 +53,8 @@ export const component = defineComponentMetadata({
// Fallback to observer
allMutations(records => {
records.forEach(record => {
if (
record.target instanceof HTMLInputElement &&
record.target.classList.contains('nav-search-input') &&
record.target.placeholder !== DEFAULT_PLACEHOLDER
) {
resetPlaceholder(record.target)
if (isSearchInput(record.target)) {
resetPlaceholder(record.target as HTMLInputElement)
}
})
})