You've already forked bilibili-subtitle
优化
This commit is contained in:
@@ -20,7 +20,7 @@ import {EVENT_EXPAND, GEMINI_TOKENS, TOTAL_HEIGHT_MAX, TOTAL_HEIGHT_MIN, WORDS_M
|
||||
import {useAsyncEffect, useInterval} from 'ahooks'
|
||||
import {getModelMaxTokens, getWholeText} from '../utils/bizUtil'
|
||||
import {MESSAGE_TO_INJECT_GET_SUBTITLE} from '../consts/const'
|
||||
import useMessage from '../messaging/layer2/useMessaging'
|
||||
import useMessaging from '../messaging/layer2/useMessaging'
|
||||
|
||||
/**
|
||||
* Service是单例,类似后端的服务概念
|
||||
@@ -44,7 +44,7 @@ const useSubtitleService = () => {
|
||||
const autoTranslate = useAppSelector(state => state.env.autoTranslate)
|
||||
const reviewed = useAppSelector(state => state.env.tempData.reviewed)
|
||||
const reviewActions = useAppSelector(state => state.env.tempData.reviewActions)
|
||||
const {sendInject} = useMessage()
|
||||
const {sendInject} = useMessaging()
|
||||
|
||||
//如果reviewActions达到15次,则设置reviewed为false
|
||||
useEffect(() => {
|
||||
@@ -79,7 +79,7 @@ const useSubtitleService = () => {
|
||||
// 获取
|
||||
useEffect(() => {
|
||||
if (curInfo && !curFetched) {
|
||||
sendInject(MESSAGE_TO_INJECT_GET_SUBTITLE, {info: curInfo}).then(data => {
|
||||
sendInject('GET_SUBTITLE', {info: curInfo}).then(data => {
|
||||
data?.body?.forEach((item: TranscriptItem, idx: number) => {
|
||||
item.idx = idx
|
||||
})
|
||||
@@ -94,9 +94,9 @@ const useSubtitleService = () => {
|
||||
|
||||
useAsyncEffect(async () => {
|
||||
// 初始获取列表
|
||||
sendInject(MESSAGE_TO_INJECT_REFRESH_VIDEO_INFO, {force: true})
|
||||
sendInject('REFRESH_VIDEO_INFO', {force: true})
|
||||
// 初始获取设置信息
|
||||
sendInject(MESSAGE_TO_INJECT_GET_VIDEO_ELEMENT_INFO, {}).then(info => {
|
||||
sendInject('GET_VIDEO_ELEMENT_INFO', {}).then(info => {
|
||||
dispatch(setNoVideo(info.noVideo))
|
||||
if (envData.sidePanel) {
|
||||
// get screen height
|
||||
@@ -192,7 +192,7 @@ const useSubtitleService = () => {
|
||||
|
||||
// 每0.5秒更新当前视频时间
|
||||
useInterval(() => {
|
||||
sendInject(MESSAGE_TO_INJECT_GET_VIDEO_STATUS, {}).then(status => {
|
||||
sendInject('GET_VIDEO_STATUS', {}).then(status => {
|
||||
dispatch(setCurrentTime(status.currentTime))
|
||||
})
|
||||
}, 500)
|
||||
@@ -200,15 +200,15 @@ const useSubtitleService = () => {
|
||||
// show translated text in the video
|
||||
useEffect(() => {
|
||||
if (hideOnDisableAutoTranslate && !autoTranslate) {
|
||||
sendInject(MESSAGE_TO_INJECT_HIDE_TRANS, {})
|
||||
sendInject('HIDE_TRANS', {})
|
||||
return
|
||||
}
|
||||
|
||||
const transResult = curIdx?transResults[curIdx]:undefined
|
||||
if (transResult?.code === '200' && transResult.data) {
|
||||
sendInject(MESSAGE_TO_INJECT_UPDATETRANSRESULT, {result: transResult.data})
|
||||
sendInject('UPDATE_TRANS_RESULT', {result: transResult.data})
|
||||
} else {
|
||||
sendInject(MESSAGE_TO_INJECT_HIDE_TRANS, {})
|
||||
sendInject('HIDE_TRANS', {})
|
||||
}
|
||||
}, [autoTranslate, curIdx, hideOnDisableAutoTranslate, transResults])
|
||||
}
|
||||
|
Reference in New Issue
Block a user