mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Merge pull request #5207 from magicFeirl/preview-features-trending-search-liveroom
[功能 - 组件 - 隐藏热搜] 添加直播间搜索框的热搜隐藏功能
This commit is contained in:
commit
b3189a328c
@ -1,9 +1,8 @@
|
|||||||
.search-panel {
|
.search-panel, .search-pannel {
|
||||||
|
|
||||||
> .trending {
|
> .trending {
|
||||||
display: none !important;
|
display: none !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
&:not(:has(.history)) {
|
&:not(:has(.history)) {
|
||||||
padding: 0 !important;
|
padding: 0 !important;
|
||||||
border: none !important;
|
border: none !important;
|
||||||
|
|||||||
@ -9,6 +9,26 @@ const resetPlaceholder = (input: HTMLInputElement) => {
|
|||||||
input.title = DEFAULT_PLACEHOLDER
|
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({
|
export const component = defineComponentMetadata({
|
||||||
name: 'hideTrendingSearch',
|
name: 'hideTrendingSearch',
|
||||||
displayName: '隐藏热搜',
|
displayName: '隐藏热搜',
|
||||||
@ -20,7 +40,8 @@ export const component = defineComponentMetadata({
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
entry: async () => {
|
entry: async () => {
|
||||||
const input: HTMLInputElement = await select('input.nav-search-input', {
|
const clsName = getSearchInputClassName()
|
||||||
|
const input: HTMLInputElement = await select(clsName, {
|
||||||
queryInterval: 500,
|
queryInterval: 500,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -32,12 +53,8 @@ export const component = defineComponentMetadata({
|
|||||||
// Fallback to observer
|
// Fallback to observer
|
||||||
allMutations(records => {
|
allMutations(records => {
|
||||||
records.forEach(record => {
|
records.forEach(record => {
|
||||||
if (
|
if (isSearchInput(record.target)) {
|
||||||
record.target instanceof HTMLInputElement &&
|
resetPlaceholder(record.target as HTMLInputElement)
|
||||||
record.target.classList.contains('nav-search-input') &&
|
|
||||||
record.target.placeholder !== DEFAULT_PLACEHOLDER
|
|
||||||
) {
|
|
||||||
resetPlaceholder(record.target)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user