You've already forked bilibili-subtitle
Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
149653ffac | ||
![]() |
f977b5e238 | ||
![]() |
c13ef4597b | ||
![]() |
65026f62af | ||
![]() |
bcff8b4f90 | ||
![]() |
ee1eaf9e08 | ||
![]() |
cc732de8e6 | ||
![]() |
cccf7e6149 | ||
![]() |
30dc724ebb | ||
![]() |
51a7e998b9 | ||
![]() |
556ccef4b2 | ||
![]() |
42b719fb98 |
@@ -51,6 +51,9 @@ node版本:18.15.0
|
|||||||
|
|
||||||
注:`./push.sh`是作者自用脚本,可以忽略。
|
注:`./push.sh`是作者自用脚本,可以忽略。
|
||||||
|
|
||||||
|
提示:本地edge开发调试可能有问题,会报csp错误!本地开发调试推荐用chrome。
|
||||||
|
构建后应该正常,关键是fix.cjs里将use_dynamic_url设置为false的这个操作。
|
||||||
|
|
||||||
## 贡献指南
|
## 贡献指南
|
||||||
|
|
||||||
欢迎贡献代码或提出改进建议!如果您希望为该项目做出贡献,请遵循以下步骤:
|
欢迎贡献代码或提出改进建议!如果您希望为该项目做出贡献,请遵循以下步骤:
|
||||||
|
7
fix.cjs
7
fix.cjs
@@ -5,4 +5,11 @@ const fs = require('fs')
|
|||||||
//copy index.html to sidepanel.html
|
//copy index.html to sidepanel.html
|
||||||
fs.copyFileSync('./dist/index.html', './dist/sidepanel.html')
|
fs.copyFileSync('./dist/index.html', './dist/sidepanel.html')
|
||||||
|
|
||||||
|
//set all use_dynamic_url to false
|
||||||
|
const manifest = require('./dist/manifest.json')
|
||||||
|
manifest.web_accessible_resources.forEach(resource => {
|
||||||
|
resource.use_dynamic_url = false
|
||||||
|
})
|
||||||
|
fs.writeFileSync('./dist/manifest.json', JSON.stringify(manifest, null, 2))
|
||||||
|
|
||||||
console.log('fix.js done');
|
console.log('fix.js done');
|
||||||
|
@@ -12,9 +12,10 @@ const [major, minor, patch, label = '0'] = version
|
|||||||
.split(/[.-]/)
|
.split(/[.-]/)
|
||||||
|
|
||||||
export default defineManifest(async (env) => ({
|
export default defineManifest(async (env) => ({
|
||||||
"name": "哔哔君 - bilibili哔哩哔哩字幕列表",
|
"name": '__MSG_appName__',
|
||||||
"description": "显示B站视频的字幕列表,可点击跳转与下载字幕,并支持翻译和总结字幕!",
|
"description": '__MSG_appDescription__',
|
||||||
"version": `${major}.${minor}.${patch}`,
|
"version": `${major}.${minor}.${patch}`,
|
||||||
|
"default_locale": "zh_CN",
|
||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"sidePanel",
|
"sidePanel",
|
||||||
@@ -56,7 +57,7 @@ export default defineManifest(async (env) => ({
|
|||||||
"resources": [
|
"resources": [
|
||||||
"index.html",
|
"index.html",
|
||||||
],
|
],
|
||||||
"use_dynamic_url": true
|
"use_dynamic_url": false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}))
|
}))
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "bilibili-subtitle",
|
"name": "bilibili-subtitle",
|
||||||
"version": "1.11.8",
|
"version": "1.11.13",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "哔哩哔哩字幕列表",
|
"description": "哔哩哔哩字幕列表",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
|
8
public/_locales/zh_CN/messages.json
Normal file
8
public/_locales/zh_CN/messages.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"appName": {
|
||||||
|
"message": "哔哔君 - bilibili哔哩哔哩字幕列表"
|
||||||
|
},
|
||||||
|
"appDescription": {
|
||||||
|
"message": "显示B站视频的字幕列表,可点击跳转与下载字幕,并支持翻译和总结字幕!"
|
||||||
|
}
|
||||||
|
}
|
@@ -39,6 +39,7 @@ import Ask from './Ask'
|
|||||||
import { v4 } from 'uuid'
|
import { v4 } from 'uuid'
|
||||||
import RateExtension from '../components/RateExtension'
|
import RateExtension from '../components/RateExtension'
|
||||||
import ApiKeyReminder from './ApiKeyReminder'
|
import ApiKeyReminder from './ApiKeyReminder'
|
||||||
|
import useMessaging from '@/messaging/layer2/useMessaging'
|
||||||
|
|
||||||
const Body = () => {
|
const Body = () => {
|
||||||
const dispatch = useAppDispatch()
|
const dispatch = useAppDispatch()
|
||||||
@@ -65,6 +66,7 @@ const Body = () => {
|
|||||||
// const fontSize = useAppSelector(state => state.env.envData.fontSize)
|
// const fontSize = useAppSelector(state => state.env.envData.fontSize)
|
||||||
const searchText = useAppSelector(state => state.env.searchText)
|
const searchText = useAppSelector(state => state.env.searchText)
|
||||||
const asks = useAppSelector(state => state.env.asks)
|
const asks = useAppSelector(state => state.env.asks)
|
||||||
|
const {disconnected} = useMessaging()
|
||||||
// const recommendIdx = useMemo(() => random(0, 3), [])
|
// const recommendIdx = useMemo(() => random(0, 3), [])
|
||||||
const showSearchInput = useMemo(() => {
|
const showSearchInput = useMemo(() => {
|
||||||
return (segments != null && segments.length > 0) && (envData.searchEnabled ? envData.searchEnabled : (envData.askEnabled ?? ASK_ENABLED_DEFAULT))
|
return (segments != null && segments.length > 0) && (envData.searchEnabled ? envData.searchEnabled : (envData.askEnabled ?? ASK_ENABLED_DEFAULT))
|
||||||
@@ -262,6 +264,10 @@ const Body = () => {
|
|||||||
{searchText && <button className='absolute top-1 right-2 btn btn-ghost btn-xs btn-circle text-base-content/75' onClick={onClearSearchText}><AiOutlineCloseCircle /></button>}
|
{searchText && <button className='absolute top-1 right-2 btn btn-ghost btn-xs btn-circle text-base-content/75' onClick={onClearSearchText}><AiOutlineCloseCircle /></button>}
|
||||||
</div>}
|
</div>}
|
||||||
|
|
||||||
|
{disconnected && <div className='flex flex-col justify-center items-center gap-2 text-sm bg-red-400 rounded mx-2'>
|
||||||
|
<span className='flex items-center gap-1 text-white'><AiOutlineCloseCircle className='text-white' />已断开连接</span>
|
||||||
|
</div>}
|
||||||
|
|
||||||
{/* auto scroll btn */}
|
{/* auto scroll btn */}
|
||||||
{!autoScroll && <div
|
{!autoScroll && <div
|
||||||
className='absolute z-[999] top-[96px] right-6 tooltip tooltip-left cursor-pointer rounded-full bg-primary/25 hover:bg-primary/75 text-primary-content p-1.5 text-xl'
|
className='absolute z-[999] top-[96px] right-6 tooltip tooltip-left cursor-pointer rounded-full bg-primary/25 hover:bg-primary/75 text-primary-content p-1.5 text-xl'
|
||||||
|
@@ -83,8 +83,8 @@ const Header = (props: {
|
|||||||
}
|
}
|
||||||
}}>
|
}}>
|
||||||
<div className='shrink-0 flex items-center'>
|
<div className='shrink-0 flex items-center'>
|
||||||
<img src="bibijun.png" alt="Logo" className="w-auto h-6 ml-2 mr-1" />
|
{/* <img src="bibijun.png" alt="Logo" className="w-auto h-6 ml-2 mr-1" /> */}
|
||||||
{/* <span className='shrink-0 text-[15px] font-medium pl-1 pr-[14px]'>字幕列表</span> */}
|
<span className='shrink-0 text-[15px] font-medium pl-[16px] pr-[14px]'>字幕列表</span>
|
||||||
<MoreBtn placement={'right-start'}/>
|
<MoreBtn placement={'right-start'}/>
|
||||||
</div>
|
</div>
|
||||||
<div className='flex gap-0.5 items-center mr-[16px]'>
|
<div className='flex gap-0.5 items-center mr-[16px]'>
|
||||||
|
@@ -210,7 +210,7 @@ const SegmentCard = (props: {
|
|||||||
}, [dispatch])
|
}, [dispatch])
|
||||||
|
|
||||||
return <div
|
return <div
|
||||||
className={classNames('border border-base-300 bg-base-200/25 rounded flex flex-col m-1.5 p-1.5 gap-1 shadow', showCurrent && 'shadow-primary')}>
|
className={classNames('border border-base-300 bg-base-200/25 rounded flex flex-col m-1.5 p-1.5 gap-1', showCurrent && 'shadow shadow-md')}>
|
||||||
<div className='relative flex justify-center min-h-[20px]'>
|
<div className='relative flex justify-center min-h-[20px]'>
|
||||||
{segments != null && segments.length > 0 &&
|
{segments != null && segments.length > 0 &&
|
||||||
<div className='absolute left-0 top-0 bottom-0 text-xs select-none flex-center desc'>
|
<div className='absolute left-0 top-0 bottom-0 text-xs select-none flex-center desc'>
|
||||||
|
@@ -167,7 +167,7 @@ const debug = (...args: any[]) => {
|
|||||||
ctime = pages[0].ctime
|
ctime = pages[0].ctime
|
||||||
author = pages[0].owner?.name
|
author = pages[0].owner?.name
|
||||||
title = pages[0].part
|
title = pages[0].part
|
||||||
await fetch(`https://api.bilibili.com/x/player/v2?aid=${aid}&cid=${cid}`, { credentials: 'include' }).then(res => res.json()).then(res => {
|
await fetch(`https://api.bilibili.com/x/player/wbi/v2?aid=${aid}&cid=${cid}`, { credentials: 'include' }).then(res => res.json()).then(res => {
|
||||||
subtitles = res.data.subtitle.subtitles
|
subtitles = res.data.subtitle.subtitles
|
||||||
})
|
})
|
||||||
} else {//bvxxx
|
} else {//bvxxx
|
||||||
@@ -179,7 +179,7 @@ const debug = (...args: any[]) => {
|
|||||||
author = res.data.owner?.name
|
author = res.data.owner?.name
|
||||||
pages = res.data.pages
|
pages = res.data.pages
|
||||||
})
|
})
|
||||||
await fetch(`https://api.bilibili.com/x/player/v2?aid=${aid}&cid=${cid}`, { credentials: 'include' }).then(res => res.json()).then(res => {
|
await fetch(`https://api.bilibili.com/x/player/wbi/v2?aid=${aid}&cid=${cid}`, { credentials: 'include' }).then(res => res.json()).then(res => {
|
||||||
subtitles = res.data.subtitle.subtitles
|
subtitles = res.data.subtitle.subtitles
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -226,15 +226,18 @@ const debug = (...args: any[]) => {
|
|||||||
lastAid = aid
|
lastAid = aid
|
||||||
lastCid = cid
|
lastCid = cid
|
||||||
if (aid && cid) {
|
if (aid && cid) {
|
||||||
fetch(`https://api.bilibili.com/x/player/v2?aid=${aid}&cid=${cid}`, {
|
fetch(`https://api.bilibili.com/x/player/wbi/v2?aid=${aid}&cid=${cid}`, {
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
})
|
})
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(res => {
|
.then(res => {
|
||||||
// console.log('refreshSubtitles: ', aid, cid, res)
|
//remove elements with empty subtitle_url
|
||||||
runtime.injectMessaging.sendApp('SET_INFOS', {
|
res.data.subtitle.subtitles = res.data.subtitle.subtitles.filter((item: any) => item.subtitle_url)
|
||||||
infos: res.data.subtitle.subtitles
|
if (res.data.subtitle.subtitles.length > 0) {
|
||||||
})
|
runtime.injectMessaging.sendApp('SET_INFOS', {
|
||||||
|
infos: res.data.subtitle.subtitles
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -25,6 +25,7 @@ class Layer1Protocol<L1Req = any, L1Res = any> {
|
|||||||
private timeout: number
|
private timeout: number
|
||||||
private requests: Map<string, { resolve: (value: L1Res) => void, reject: (reason?: any) => void, timer: number }>
|
private requests: Map<string, { resolve: (value: L1Res) => void, reject: (reason?: any) => void, timer: number }>
|
||||||
private handler: Handler<L1Req, L1Res>
|
private handler: Handler<L1Req, L1Res>
|
||||||
|
public disconnected: boolean = false
|
||||||
|
|
||||||
constructor(handler: Handler<L1Req, L1Res>, port: chrome.runtime.Port, autoDispose = true, timeout = 30000) { // 默认超时 30 秒
|
constructor(handler: Handler<L1Req, L1Res>, port: chrome.runtime.Port, autoDispose = true, timeout = 30000) { // 默认超时 30 秒
|
||||||
this.port = port;
|
this.port = port;
|
||||||
@@ -82,6 +83,7 @@ class Layer1Protocol<L1Req = any, L1Res = any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
|
this.disconnected = true
|
||||||
this.port.onMessage.removeListener(this._messageListener);
|
this.port.onMessage.removeListener(this._messageListener);
|
||||||
if (this.port.onDisconnect) {
|
if (this.port.onDisconnect) {
|
||||||
this.port.onDisconnect.removeListener(this.dispose);
|
this.port.onDisconnect.removeListener(this.dispose);
|
||||||
|
@@ -1,12 +1,18 @@
|
|||||||
import { msgWaiter } from './useMessagingService'
|
import { msgWaiter } from './useMessagingService'
|
||||||
import { useCallback } from 'react'
|
import { useCallback, useState } from 'react'
|
||||||
import Layer1Protocol from '../layer1/Layer1Protocol'
|
import Layer1Protocol from '../layer1/Layer1Protocol'
|
||||||
import { L2ReqMsg, L2ResMsg, TAG_TARGET_INJECT } from '../const'
|
import { L2ReqMsg, L2ResMsg, TAG_TARGET_INJECT } from '../const'
|
||||||
|
|
||||||
const useMessaging = <AllExtensionMessagesType extends ExtensionMessage, AllInjectMessagesType extends InjectMessage>() => {
|
const useMessaging = <AllExtensionMessagesType extends ExtensionMessage, AllInjectMessagesType extends InjectMessage>() => {
|
||||||
|
const [disconnected, setDisconnected] = useState(false)
|
||||||
|
|
||||||
const sendExtension = useCallback(async <M extends AllExtensionMessagesType | MessagingExtensionMessages, K extends M['method']>(method: K, params?: Extract<M, { method: K }>['params']): Promise<Extract<M, { method: K }>['return']> => {
|
const sendExtension = useCallback(async <M extends AllExtensionMessagesType | MessagingExtensionMessages, K extends M['method']>(method: K, params?: Extract<M, { method: K }>['params']): Promise<Extract<M, { method: K }>['return']> => {
|
||||||
// wait
|
// wait
|
||||||
const pmh = await msgWaiter.wait() as Layer1Protocol<L2ReqMsg, L2ResMsg>
|
const pmh = await msgWaiter.wait() as Layer1Protocol<L2ReqMsg, L2ResMsg>
|
||||||
|
if (pmh.disconnected) {
|
||||||
|
setDisconnected(true)
|
||||||
|
throw new Error('disconnected')
|
||||||
|
}
|
||||||
// send message
|
// send message
|
||||||
const res = await pmh.sendMessage({
|
const res = await pmh.sendMessage({
|
||||||
from: 'app',
|
from: 'app',
|
||||||
@@ -30,7 +36,8 @@ const useMessaging = <AllExtensionMessagesType extends ExtensionMessage, AllInje
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
sendExtension,
|
sendExtension,
|
||||||
sendInject
|
sendInject,
|
||||||
|
disconnected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -27,7 +27,7 @@ import toast from 'react-hot-toast'
|
|||||||
import {useBoolean, useEventTarget} from 'ahooks'
|
import {useBoolean, useEventTarget} from 'ahooks'
|
||||||
import {useEventChecked} from '@kky002/kky-hooks'
|
import {useEventChecked} from '@kky002/kky-hooks'
|
||||||
import { useMessage } from '@/hooks/message'
|
import { useMessage } from '@/hooks/message'
|
||||||
import { FaChevronDown, FaChevronUp } from 'react-icons/fa'
|
import { FaChevronDown, FaChevronUp, FaGripfire } from 'react-icons/fa'
|
||||||
|
|
||||||
const OptionCard = ({ title, children, defaultExpanded = true }: { title: React.ReactNode; children: React.ReactNode; defaultExpanded?: boolean }) => {
|
const OptionCard = ({ title, children, defaultExpanded = true }: { title: React.ReactNode; children: React.ReactNode; defaultExpanded?: boolean }) => {
|
||||||
const [isExpanded, setIsExpanded] = useState(defaultExpanded);
|
const [isExpanded, setIsExpanded] = useState(defaultExpanded);
|
||||||
@@ -261,14 +261,15 @@ const OptionsPage = () => {
|
|||||||
<div>服务器地址:<a className='link link-primary'
|
<div>服务器地址:<a className='link link-primary'
|
||||||
onClick={() => setServerUrlValue(DEFAULT_SERVER_URL_OPENAI)}
|
onClick={() => setServerUrlValue(DEFAULT_SERVER_URL_OPENAI)}
|
||||||
rel='noreferrer'>点击设置</a></div>
|
rel='noreferrer'>点击设置</a></div>
|
||||||
{/* <div className='flex justify-center font-semibold'>【第三方代理】</div> */}
|
<div className='flex justify-center font-semibold'>【第三方国内代理】</div>
|
||||||
{/* <div>代理网址:<a className='link link-primary' href='https://api.openai-up.com/register?aff=varM' */}
|
<div>代理网址:<a className='link link-primary' href='https://api.kksj.org/register?aff=ucVc'
|
||||||
{/* target='_blank' */}
|
target='_blank'
|
||||||
{/* rel="noreferrer">点击访问</a></div> */}
|
rel="noreferrer">点击访问</a></div>
|
||||||
{/* <div>服务器地址:<a className='link link-primary' */}
|
<div>服务器地址:<a className='link link-primary'
|
||||||
{/* onClick={() => setServerUrlValue('https://api.openai-up.com')} */}
|
onClick={() => setServerUrlValue('https://api.kksj.org')}
|
||||||
{/* rel='noreferrer'>点击设置</a></div> */}
|
rel='noreferrer'>点击设置</a></div>
|
||||||
{/* <div className='text-amber-600 flex justify-center items-center'><FaGripfire/>目前价格不到官方价格的6折<FaGripfire/></div> */}
|
<div className='text-amber-600 flex justify-center items-center'><FaGripfire/>目前0.9人民币可充值1美元(约官方价格1/8)<FaGripfire/></div>
|
||||||
|
<div className='text-amber-600 flex justify-center items-center'><FaGripfire/>国内可访问,无需🪜<FaGripfire/></div>
|
||||||
</div>
|
</div>
|
||||||
</div>}
|
</div>}
|
||||||
{(!aiTypeValue || aiTypeValue === 'openai') && <FormItem title='模型选择' htmlFor='modelSel' tip='注意,不同模型有不同价格与token限制'>
|
{(!aiTypeValue || aiTypeValue === 'openai') && <FormItem title='模型选择' htmlFor='modelSel' tip='注意,不同模型有不同价格与token限制'>
|
||||||
|
Reference in New Issue
Block a user