From 1616061f656dbf4c138569a0aad14c9e0ba5cacd Mon Sep 17 00:00:00 2001 From: magicFeirl <2100709458@qq.com> Date: Thu, 10 Apr 2025 21:50:26 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E9=9A=90=E8=97=8F=E7=9B=B4?= =?UTF-8?q?=E6=92=AD=E9=97=B4=E7=83=AD=E6=90=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trending-search/hide-trending-search.scss | 3 +- .../style/hide/trending-search/index.ts | 31 ++++++++++++++----- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/registry/lib/components/style/hide/trending-search/hide-trending-search.scss b/registry/lib/components/style/hide/trending-search/hide-trending-search.scss index c9d8407e7..cc62fcf9e 100644 --- a/registry/lib/components/style/hide/trending-search/hide-trending-search.scss +++ b/registry/lib/components/style/hide/trending-search/hide-trending-search.scss @@ -1,9 +1,8 @@ -.search-panel { +.search-panel, .search-pannel { > .trending { display: none !important; } - &:not(:has(.history)) { padding: 0 !important; border: none !important; diff --git a/registry/lib/components/style/hide/trending-search/index.ts b/registry/lib/components/style/hide/trending-search/index.ts index d4003911b..0868f9965 100644 --- a/registry/lib/components/style/hide/trending-search/index.ts +++ b/registry/lib/components/style/hide/trending-search/index.ts @@ -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: any) => { + 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) } }) }) From 82f0e97a1a2d9c25dba74c1f59a0f756df835903 Mon Sep 17 00:00:00 2001 From: magicFeirl <2100709458@qq.com> Date: Sat, 12 Apr 2025 13:24:31 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E7=B1=BB=E5=9E=8B=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- registry/lib/components/style/hide/trending-search/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/registry/lib/components/style/hide/trending-search/index.ts b/registry/lib/components/style/hide/trending-search/index.ts index 0868f9965..2310e73cc 100644 --- a/registry/lib/components/style/hide/trending-search/index.ts +++ b/registry/lib/components/style/hide/trending-search/index.ts @@ -17,7 +17,7 @@ const getSearchInputClassName = () => { return isInLiveRoomPage() ? 'input.nav-search-content' : 'input.nav-search-input' } -const isSearchInput = (target: any) => { +const isSearchInput = (target: Node) => { if (!(target instanceof HTMLInputElement)) { return false }