From 9a9f0b92911ba6fcc5bf2addfa33f1077fe5aee2 Mon Sep 17 00:00:00 2001 From: eric2788 Date: Sun, 10 Mar 2024 19:08:36 +0800 Subject: [PATCH 1/2] updated README.md and comment --- README.md | 28 ++++++++++++---------------- src/contents/index/App.tsx | 1 - src/contents/index/mounter.tsx | 2 +- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 862c80b9..9fef5004 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ## ➵ 下载 -[FireFox (请使用mv2版本 v0.12.4)](https://github.com/eric2788/bilibili-vup-stream-enhancer/releases/tag/0.12.4) +[FireFox (请使用 MV2 版本 v0.12.4)](https://github.com/eric2788/bilibili-vup-stream-enhancer/releases/tag/0.12.4) [Edge](https://microsoftedge.microsoft.com/addons/detail/ehdhihncinoejihhmhpdoeloadihnfio) @@ -23,21 +23,7 @@ 本浏览器插件透过挂接 WebSocket 为管人观众提供众多功能。 本插件虽然功能众多,但全部主要功能均为可选,你仍可为界面保持简化。 -目前所有功能都需要各位测试者的意见和bug回报,因此需要大量测试者.... - -当所有功能完善后,我们将会为 bilibili-jimaku-filter 推出正式的 v2.0 版本 😎😎 - -## ➵ 使用方式 - -1. [下载](#-下载)本扩展。 -2. 点击扩展图标进入设定页面,并根据你的偏好进入设定。完成后,然后按下保存设定。 -3. 进入B站任一直播间即可开始使用。 - -## ➵ 贡献 - -请参阅 [贡献指南](CONTRIBUTING.md)。 - -## ➵ 功能简介 +### 功能 **所有主要功能已全部改为可选**,例如: 你可以启用醒目留言记录而不启用同传字幕过滤, 且每个主要功能都有各自的房间黑/白名单 @@ -53,6 +39,16 @@ - 高亮用户弹幕/进入直播间 - 开播提醒 +## ➵ 使用方式 + +1. [下载](#-下载)本扩展。 +2. 点击扩展图标进入设定页面,并根据你的偏好进入设定。完成后,然后按下保存设定。 +3. 进入B站任一直播间即可开始使用。 + +## ➵ 贡献 + +请参阅 [贡献指南](CONTRIBUTING.md)。 + ## ➵ 其他连结 diff --git a/src/contents/index/App.tsx b/src/contents/index/App.tsx index 87350432..deaa6ca6 100644 --- a/src/contents/index/App.tsx +++ b/src/contents/index/App.tsx @@ -13,7 +13,6 @@ import Header from "./components/Header"; const shadowRoot = () => document.querySelector('bjf-csui').shadowRoot -//TODO: add steps const steps: Array = [ { target: '#bjf-main-menu-button', diff --git a/src/contents/index/mounter.tsx b/src/contents/index/mounter.tsx index e3d339ec..cb149985 100644 --- a/src/contents/index/mounter.tsx +++ b/src/contents/index/mounter.tsx @@ -193,7 +193,7 @@ function createApp(roomId: string, plasmo: PlasmoSpec, info: StreamInfo): App { await Promise.all(mounters.filter(m => enabled.includes(m.feature)).map(m => m.mount(settings))) console.info('渲染元素完成') - // TODO: change to use global data + // change to use global data in the future removeListener = addBLiveMessageCommandListener('DANMU_MSG', (data) => { const uname = data.info[2][1] const text = data.info[1] From 4539b197d5123ef34e64e762e7cb0b718255a271 Mon Sep 17 00:00:00 2001 From: eric2788 Date: Sun, 10 Mar 2024 21:57:20 +0800 Subject: [PATCH 2/2] optimized superchat feature and fixed only vtuber mechanism --- src/api/bilibili.ts | 6 ++-- src/contents/index/index.tsx | 2 +- .../components/SuperChatCaptureLayer.tsx | 9 ++++++ src/settings/features/superchat/index.tsx | 28 ++++++++++++++----- src/settings/fragments/features.tsx | 2 +- tests/content.spec.ts | 28 +++++++++++++++++-- tests/features/superchat.spec.ts | 27 ++++++++++++++++++ tests/fixtures/base.ts | 1 - tests/helpers/bilibili-api.ts | 7 +++-- tests/helpers/room-finder.ts | 2 +- tests/pages/settings.spec.ts | 10 +++---- 11 files changed, 97 insertions(+), 25 deletions(-) diff --git a/src/api/bilibili.ts b/src/api/bilibili.ts index 7ae7b642..5e0515c5 100644 --- a/src/api/bilibili.ts +++ b/src/api/bilibili.ts @@ -27,7 +27,7 @@ export async function getStreamInfo(room: string): Promise { title: data.room_info.title, uid: data.room_info.uid.toString(), username: data.anchor_info.base_info.uname, - isVtuber: data.room_info.parent_area_id !== 9, // 分區辨識 + isVtuber: data.room_info.parent_area_id === 9, // 分區辨識 status: data.room_info.live_status === 1 ? 'online' : 'offline', liveTime: data.room_info.live_start_time, isTheme: isThemePage() // 目前尚未知道如何在 API 中取得 @@ -62,9 +62,7 @@ export async function ensureLogin(): Promise { export async function ensureIsVtuber(info: StreamInfo): Promise { // real vtuber identification - const vup = await retryCatcher(() => identifyVup(info.uid), 3, - { id: info.uid, name: info.username, locale: 'idk' } // if failed, always return is vtuber = true - ) + const vup = await retryCatcher(() => identifyVup(info.uid), 3) // if failed, use area id to identify // if not undefined if (vup) { diff --git a/src/contents/index/index.tsx b/src/contents/index/index.tsx index 510a78b4..0419318f 100644 --- a/src/contents/index/index.tsx +++ b/src/contents/index/index.tsx @@ -67,7 +67,7 @@ const getStreamInfoFallbacks = [ title: r.data.room_info.title, uid: r.data.room_info.uid.toString(), username: r.data.anchor_info.base_info.uname, - isVtuber: r.data.room_info.parent_area_id !== 9, // 分區辨識 + isVtuber: r.data.room_info.parent_area_id === 9, // 分區辨識 status: r.data.room_info.live_status === 1 ? 'online' : 'offline', liveTime: r.data.room_info.live_start_time }) as StreamInfo), diff --git a/src/features/superchat/components/SuperChatCaptureLayer.tsx b/src/features/superchat/components/SuperChatCaptureLayer.tsx index 3668ae8f..a5fc913e 100644 --- a/src/features/superchat/components/SuperChatCaptureLayer.tsx +++ b/src/features/superchat/components/SuperChatCaptureLayer.tsx @@ -9,6 +9,8 @@ import SuperChatArea from "./SuperChatArea" import SuperChatFloatingButton from "./SuperChatFloatingButton" import type { SuperChatCard } from "./SuperChatItem" import { useTransaction } from "~hooks/optimizer" +import { useWebScreenChange } from "~hooks/bilibili" +import SuperChatFeatureContext from "~contexts/SuperChatFeatureContext" export type SuperChatCaptureLayerProps = { offlineRecords: SuperChatCard[] @@ -17,6 +19,7 @@ export type SuperChatCaptureLayerProps = { function SuperChatCaptureLayer(props: SuperChatCaptureLayerProps): JSX.Element { const { settings, info } = useContext(ContentContext) + const { displayFullScreen } = useContext(SuperChatFeatureContext) const { offlineRecords } = props const { enabledRecording, @@ -60,6 +63,12 @@ function SuperChatCaptureLayer(props: SuperChatCaptureLayerProps): JSX.Element { push(superChatProps) }) + const screenStatus = useWebScreenChange(settings['settings.developer'].classes) + + if (screenStatus !== 'normal' && !displayFullScreen) { + return <> + } + return ( = { floatingButtonColor: '#db7d1f', buttonColor: '#db7d1f', + displayFullScreen: true } -function SuperchatFeatureSettings({state, useHandler}: StateProxy): JSX.Element { +function SuperchatFeatureSettings({ state, useHandler }: StateProxy): JSX.Element { - const handler = useHandler, string>((e) => e.target.value) + const str = useHandler, string>((e) => e.target.value) + const bool = useHandler, boolean>((e) => e.target.checked) return (
- - + + +
+ 在全屏模式下显示 + } + checked={state.displayFullScreen} + onChange={bool('displayFullScreen')} + /> +
) } diff --git a/src/settings/fragments/features.tsx b/src/settings/fragments/features.tsx index 58502d04..0930a88c 100644 --- a/src/settings/fragments/features.tsx +++ b/src/settings/fragments/features.tsx @@ -33,7 +33,7 @@ export const defaultSettings: Readonly = { enabledRecording: [], common: { enabledPip: false, - onlyVtuber: false, + onlyVtuber: true, monitorWindow: false, useStreamingTime: true }, diff --git a/tests/content.spec.ts b/tests/content.spec.ts index 86f5db20..e68bb0f8 100644 --- a/tests/content.spec.ts +++ b/tests/content.spec.ts @@ -208,6 +208,30 @@ test('測試全屏時有否根據設定顯示隱藏浮動按鈕', async ({ conte await expect(button).toBeVisible() }) +test('测试仅限虚拟主播', async ({ context, room, tabUrl, api }) => { + + const nonVtbRooms = await api.getLiveRooms(1, 11) // 获取知识分区直播间 + test.skip(nonVtbRooms.length === 0, '没有知识分区直播间') + + await room.enterToRoom(nonVtbRooms[0]) + const content = await room.getContentLocator() + + const button = content.getByText('功能菜单') + await expect(button).toBeHidden() + + const settingsPage = await context.newPage() + await settingsPage.goto(tabUrl('settings.html'), { waitUntil: 'domcontentloaded' }) + await settingsPage.getByText('功能设定').click() + await settingsPage.getByText('仅限虚拟主播').click() + await settingsPage.getByText('保存设定').click() + + await room.page.bringToFront() + await content.waitForTimeout(1000) + + await expect(button).toBeVisible() + +}) + test('測試底部的按鈕', async ({ content, context }) => { const button = content.getByText('功能菜单') @@ -240,7 +264,7 @@ test('測試底部的按鈕', async ({ content, context }) => { await p3.close() }) -test('測試导航', async ({ room, content, serviceWorker }) => { +test('測試导航', async ({ room, content, serviceWorker }) => { const overlay = content.locator('.react-joyride__overlay') @@ -261,7 +285,7 @@ test('測試导航', async ({ room, content, serviceWorker }) => { const skip = content.getByRole('button', { name: '跳过' }) const finish = content.getByRole('button', { name: '完成' }) - while(await next.isVisible()) { + while (await next.isVisible()) { await next.click() await content.waitForTimeout(100) } diff --git a/tests/features/superchat.spec.ts b/tests/features/superchat.spec.ts index 4c40a5cc..46d04a90 100644 --- a/tests/features/superchat.spec.ts +++ b/tests/features/superchat.spec.ts @@ -185,6 +185,33 @@ test('測試房間名單列表(黑名單/白名單)', async ({ room, content, co }) +test('測試全屏時有否根據設定顯示隱藏浮動按鈕', async ({ content, context, tabUrl }) => { + + const button = content.locator('button', { hasText: /^醒目留言$/ }) + await expect(button).toBeVisible() + + logger.info('正在測試啟用時切換網頁全屏...') + await content.locator('#live-player').dblclick() + await expect(button).toBeVisible() + await content.locator('#live-player').dblclick() + + logger.info('正在修改設定...') + const settingsPage = await context.newPage() + await settingsPage.goto(tabUrl('settings.html'), { waitUntil: 'domcontentloaded' }) + await settingsPage.getByText('功能设定').click() + await settingsPage.locator('#features\\.superchat').getByText('在全屏模式下显示').click() // closed + await settingsPage.getByText('保存设定').click() + await settingsPage.close() + + await expect(button).toBeVisible() + + logger.info('正在測試禁用時切換網頁全屏...') + await content.locator('#live-player').dblclick() + await expect(button).toBeHidden() + await content.locator('#live-player').dblclick() + + await expect(button).toBeVisible() +}) test('測試保存設定後 css 能否生效', async ({ content, page, tabUrl, context }) => { diff --git a/tests/fixtures/base.ts b/tests/fixtures/base.ts index 80d9f896..3759bea0 100644 --- a/tests/fixtures/base.ts +++ b/tests/fixtures/base.ts @@ -54,7 +54,6 @@ export const extensionBase = base.extend { - const data = await this.fetch(`/xlive/web-interface/v1/second/getList?platform=web&parent_area_id=9&area_id=0&sort_type=online&page=${page}`) + async getLiveRooms(page: number = 1, area: number = 9): Promise { + const data = await this.fetch(`/xlive/web-interface/v1/second/getList?platform=web&parent_area_id=${area}&area_id=0&sort_type=online&page=${page}`) if (data.code !== 0) throw new Error(`获取bilibili直播房间列表失败:${data.message}`) return data.data.list as LiveRoomInfo[] } diff --git a/tests/helpers/room-finder.ts b/tests/helpers/room-finder.ts index a3b82d24..071b9b4c 100644 --- a/tests/helpers/room-finder.ts +++ b/tests/helpers/room-finder.ts @@ -53,7 +53,7 @@ export default class RoomTypeFinder { return type } } - logger.info(`房间 ${page.info.roomid} 的类型是: 普通`) + logger.info(`房间 ${page.info.roomid} 的类型是: normal`) return 'normal' } diff --git a/tests/pages/settings.spec.ts b/tests/pages/settings.spec.ts index 48036f9a..ccf707dd 100644 --- a/tests/pages/settings.spec.ts +++ b/tests/pages/settings.spec.ts @@ -28,7 +28,7 @@ test('測試能否保存設定', async ({ settings: page }) => { await page.getByText('功能设定').click() const chexkboxVtbOnly = page.getByTestId('vtb-only') - await expect(chexkboxVtbOnly).not.toBeChecked() + await expect(chexkboxVtbOnly).toBeChecked() await page.getByText('仅限虚拟主播').click() const checkboxMonitor = page.getByTestId('monitor-window') @@ -71,7 +71,7 @@ test('測試能否保存設定', async ({ settings: page }) => { logger.info('正在验证功能設定....') await page.getByText('功能设定').click() - await expect(chexkboxVtbOnly).toBeChecked() + await expect(chexkboxVtbOnly).not.toBeChecked() await expect(checkboxMonitor).toBeChecked() await expect(inputSubtitleSize).toHaveValue('20') await expect(inputFirstSubtitleSize).toHaveValue('22') @@ -96,7 +96,7 @@ test('測試導出導入設定', async ({ settings: page }) => { await page.getByText('功能设定').click() const chexkboxVtbOnly = page.getByTestId('vtb-only') - await expect(chexkboxVtbOnly).not.toBeChecked() + await expect(chexkboxVtbOnly).toBeChecked() await page.getByText('仅限虚拟主播').click() const checkboxMonitor = page.getByTestId('monitor-window') @@ -120,7 +120,7 @@ test('測試導出導入設定', async ({ settings: page }) => { logger.info('正在验证功能設定....') await page.getByText('功能设定').click() - await expect(chexkboxVtbOnly).toBeChecked() + await expect(chexkboxVtbOnly).not.toBeChecked() await expect(checkboxMonitor).toBeChecked() await expect(inputSubtitleSize).toHaveValue('20') await expect(inputFirstSubtitleSize).toHaveValue('22') @@ -135,7 +135,7 @@ test('測試導出導入設定', async ({ settings: page }) => { await page.getByText('设定已经导入成功。').waitFor({ state: 'visible' }) logger.info('正在验证功能設定....') - await expect(chexkboxVtbOnly).not.toBeChecked() + await expect(chexkboxVtbOnly).toBeChecked() await expect(checkboxMonitor).not.toBeChecked() await expect(inputSubtitleSize).toHaveValue('16') await expect(inputFirstSubtitleSize).toHaveValue('18')