Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated docs and fixed test cases #67

Merged
merged 2 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -23,21 +23,7 @@

本浏览器插件透过挂接 WebSocket 为管人观众提供众多功能。 本插件虽然功能众多,但全部主要功能均为可选,你仍可为界面保持简化。

目前所有功能都需要各位测试者的意见和bug回报,因此需要大量测试者....

当所有功能完善后,我们将会为 bilibili-jimaku-filter 推出正式的 v2.0 版本 😎😎

## ➵ 使用方式

1. [下载](#-下载)本扩展。
2. 点击扩展图标进入设定页面,并根据你的偏好进入设定。完成后,然后按下保存设定。
3. 进入B站任一直播间即可开始使用。

## ➵ 贡献

请参阅 [贡献指南](CONTRIBUTING.md)。

## ➵ 功能简介
### 功能

**所有主要功能已全部改为可选**,例如: 你可以启用醒目留言记录而不启用同传字幕过滤, 且每个主要功能都有各自的房间黑/白名单

Expand All @@ -53,6 +39,16 @@
- 高亮用户弹幕/进入直播间
- 开播提醒

## ➵ 使用方式

1. [下载](#-下载)本扩展。
2. 点击扩展图标进入设定页面,并根据你的偏好进入设定。完成后,然后按下保存设定。
3. 进入B站任一直播间即可开始使用。

## ➵ 贡献

请参阅 [贡献指南](CONTRIBUTING.md)。


## ➵ 其他连结

Expand Down
6 changes: 2 additions & 4 deletions src/api/bilibili.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function getStreamInfo(room: string): Promise<StreamInfo> {
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 中取得
Expand Down Expand Up @@ -62,9 +62,7 @@ export async function ensureLogin(): Promise<boolean> {

export async function ensureIsVtuber(info: StreamInfo): Promise<StreamInfo> {
// 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) {
Expand Down
1 change: 0 additions & 1 deletion src/contents/index/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Header from "./components/Header";

const shadowRoot = () => document.querySelector('bjf-csui').shadowRoot

//TODO: add steps
const steps: Array<TutorialStep> = [
{
target: '#bjf-main-menu-button',
Expand Down
2 changes: 1 addition & 1 deletion src/contents/index/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/contents/index/mounter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
9 changes: 9 additions & 0 deletions src/features/superchat/components/SuperChatCaptureLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand All @@ -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,
Expand Down Expand Up @@ -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 (
<SuperChatFloatingButton>
<SuperChatArea
Expand Down
28 changes: 21 additions & 7 deletions src/settings/features/superchat/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Switch, Typography } from "@material-tailwind/react"
import { type ChangeEvent } from "react"
import type { StateProxy } from "~hooks/binding"
import ColorInput from "~settings/components/ColorInput"
import type { HexColor } from "~types/common"
import type { FeatureSettingsDefinition } from ".."
import { Fragment, type ChangeEvent } from "react"
import ColorInput from "~settings/components/ColorInput"
import type { StateProxy } from "~hooks/binding"

export const title: string = '醒目留言'

Expand All @@ -13,22 +14,35 @@ export const define: FeatureSettingsDefinition = {
export type FeatureSettingSchema = {
floatingButtonColor: HexColor,
buttonColor: HexColor,
displayFullScreen: boolean
}

export const defaultSettings: Readonly<FeatureSettingSchema> = {
floatingButtonColor: '#db7d1f',
buttonColor: '#db7d1f',
displayFullScreen: true
}


function SuperchatFeatureSettings({state, useHandler}: StateProxy<FeatureSettingSchema>): JSX.Element {
function SuperchatFeatureSettings({ state, useHandler }: StateProxy<FeatureSettingSchema>): JSX.Element {

const handler = useHandler<ChangeEvent<HTMLInputElement>, string>((e) => e.target.value)
const str = useHandler<ChangeEvent<HTMLInputElement>, string>((e) => e.target.value)
const bool = useHandler<ChangeEvent<HTMLInputElement>, boolean>((e) => e.target.checked)

return (
<div className="grid max-md:grid-cols-1 md:grid-cols-2 gap-10">
<ColorInput data-testid="floater-color" label="浮动按钮颜色" value={state.floatingButtonColor} onChange={handler('floatingButtonColor')} />
<ColorInput data-testid="operator-color" label="操作按钮颜色" value={state.buttonColor} onChange={handler('buttonColor')} />
<ColorInput data-testid="floater-color" label="浮动按钮颜色" value={state.floatingButtonColor} onChange={str('floatingButtonColor')} />
<ColorInput data-testid="operator-color" label="操作按钮颜色" value={state.buttonColor} onChange={str('buttonColor')} />
<div className="md:col-span-2 max-md:col-span-1">
<Switch
crossOrigin={'annoymous'}
label={
<Typography className="font-medium" >在全屏模式下显示</Typography>
}
checked={state.displayFullScreen}
onChange={bool('displayFullScreen')}
/>
</div>
</div>
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/settings/fragments/features.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const defaultSettings: Readonly<SettingSchema> = {
enabledRecording: [],
common: {
enabledPip: false,
onlyVtuber: false,
onlyVtuber: true,
monitorWindow: false,
useStreamingTime: true
},
Expand Down
28 changes: 26 additions & 2 deletions tests/content.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('功能菜单')
Expand Down Expand Up @@ -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')

Expand All @@ -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)
}
Expand Down
27 changes: 27 additions & 0 deletions tests/features/superchat.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {

Expand Down
1 change: 0 additions & 1 deletion tests/fixtures/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export const extensionBase = base.extend<ExtensionFixture, ExtensionOptions & Ex
const context = await chromium.launchPersistentContext('', {
headless: false,
args: [
'--mute-audio',
`--disable-extensions-except=${pathToExtension}`,
`--load-extension=${pathToExtension}`,
...(process.env.CI ? ['--headless=new'] : [])
Expand Down
7 changes: 4 additions & 3 deletions tests/helpers/bilibili-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,13 @@ export default class BilbiliApi {

/**
* 获取一页的直播房间。
* @param page - 要获取的页码。
* @param page - 要获取的页码, 默认为 1。
* @param area - 要获取的分区,默认为 9 (虚拟主播分区)。
* @returns 一个解析为直播房间信息数组的Promise。
* @throws 如果无法获取直播房间列表,则抛出错误。
*/
async getLiveRooms(page: number = 1): Promise<LiveRoomInfo[]> {
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<LiveRoomInfo[]> {
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[]
}
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/room-finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default class RoomTypeFinder {
return type
}
}
logger.info(`房间 ${page.info.roomid} 的类型是: 普通`)
logger.info(`房间 ${page.info.roomid} 的类型是: normal`)
return 'normal'
}

Expand Down
10 changes: 5 additions & 5 deletions tests/pages/settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
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')
Expand Down Expand Up @@ -71,7 +71,7 @@

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')
Expand All @@ -96,7 +96,7 @@
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')
Expand All @@ -120,7 +120,7 @@

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')
Expand All @@ -135,7 +135,7 @@
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')
Expand Down Expand Up @@ -474,7 +474,7 @@

async function compareTable(table: Locator, data: string[], index: number = 0): Promise<void> {
const rows = await table.locator('tbody tr').all()
expect(rows.length).toBe(data.length)

Check failure on line 477 in tests/pages/settings.spec.ts

View workflow job for this annotation

GitHub Actions / test (edge, -theme)

[edge-theme] › pages/settings.spec.ts:287:5 › 測試設定數據從MV2遷移

1) [edge-theme] › pages/settings.spec.ts:287:5 › 測試設定數據從MV2遷移 ──────────────────────────────────── Error: expect(received).toBe(expected) // Object.is equality Expected: 4 Received: 1 475 | async function compareTable(table: Locator, data: string[], index: number = 0): Promise<void> { 476 | const rows = await table.locator('tbody tr').all() > 477 | expect(rows.length).toBe(data.length) | ^ 478 | for (let i = 0; i < rows.length; i++) { 479 | await expect(rows[i].locator('td').nth(index)).toHaveText(data[i]) 480 | } at compareTable (/home/runner/work/bilibili-vup-stream-enhancer/bilibili-vup-stream-enhancer/tests/pages/settings.spec.ts:477:25) at /home/runner/work/bilibili-vup-stream-enhancer/bilibili-vup-stream-enhancer/tests/pages/settings.spec.ts:411:5
for (let i = 0; i < rows.length; i++) {
await expect(rows[i].locator('td').nth(index)).toHaveText(data[i])
}
Expand Down
Loading