You've already forked bilibili-subtitle
Compare commits
48 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c40338a5f5 | ||
![]() |
13e90c1ab7 | ||
![]() |
9b2d620cdf | ||
![]() |
2383603b39 | ||
![]() |
1d2b708682 | ||
![]() |
2ba841c8f2 | ||
![]() |
e6db674755 | ||
![]() |
72c8f9608e | ||
![]() |
7a03d37c61 | ||
![]() |
a86ba9e09f | ||
![]() |
d6d7e17f84 | ||
![]() |
0881312025 | ||
![]() |
d5b4ab472b | ||
![]() |
dc73be25d6 | ||
![]() |
8e23f143e4 | ||
![]() |
d7085ba75e | ||
![]() |
b8d8b8fe06 | ||
![]() |
d42844ac3c | ||
![]() |
e66f85ff9f | ||
![]() |
d97af83c9e | ||
![]() |
c70fa81482 | ||
![]() |
4dbce345c2 | ||
![]() |
aa098df6a5 | ||
![]() |
fa99fa8b3d | ||
![]() |
5078baca1b | ||
![]() |
771a802728 | ||
![]() |
9038bf7128 | ||
![]() |
f01e175b4e | ||
![]() |
8098d7cf9b | ||
![]() |
728e4dce84 | ||
![]() |
a54b4a7e5f | ||
![]() |
8a908ecf99 | ||
![]() |
bdc7823965 | ||
![]() |
8d1bac4623 | ||
![]() |
9f486b7269 | ||
![]() |
e10de9bc48 | ||
![]() |
dd7ce4ab38 | ||
![]() |
250da4fd28 | ||
![]() |
65861829e2 | ||
![]() |
0b4890399a | ||
![]() |
51bf522eeb | ||
![]() |
a5808d8385 | ||
![]() |
e005c5e214 | ||
![]() |
e7e8758716 | ||
![]() |
49e311a9ed | ||
![]() |
a1462ae2f2 | ||
![]() |
2b0d294c2a | ||
![]() |
2825f9355a |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -25,3 +25,5 @@ dist-ssr
|
|||||||
*.sw?
|
*.sw?
|
||||||
|
|
||||||
stats.html
|
stats.html
|
||||||
|
dist.zip
|
||||||
|
360/
|
||||||
|
@@ -19,7 +19,9 @@
|
|||||||
|
|
||||||
## 下载扩展
|
## 下载扩展
|
||||||
|
|
||||||
[chrome商店](https://chrome.google.com/webstore/detail/bciglihaegkdhoogebcdblfhppoilclp)
|
- [chrome商店](https://chrome.google.com/webstore/detail/bciglihaegkdhoogebcdblfhppoilclp)
|
||||||
|
- [edge商店](https://microsoftedge.microsoft.com/addons/detail/lignnlhlpiefmcjkdkmfjdckhlaiajan)
|
||||||
|
- [firefox商店](https://addons.mozilla.org/zh-CN/firefox/addon/bilibili-subtitle)
|
||||||
|
|
||||||
## 使用说明
|
## 使用说明
|
||||||
|
|
||||||
|
22
fixFirefox.cjs
Normal file
22
fixFirefox.cjs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
console.log('fixFirefox.js loaded');
|
||||||
|
|
||||||
|
const fs = require('fs')
|
||||||
|
|
||||||
|
const manifest = require('./dist/manifest.json')
|
||||||
|
manifest.web_accessible_resources[0].resources.push('index.html')
|
||||||
|
manifest.action.default_popup = 'popup.html'
|
||||||
|
//browser_specific_settings
|
||||||
|
manifest.browser_specific_settings = {
|
||||||
|
"gecko": {
|
||||||
|
"id": "bilibili-subtitle@indiekky"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//background
|
||||||
|
manifest.background = {
|
||||||
|
type: "module",
|
||||||
|
scripts: [manifest.background.service_worker]
|
||||||
|
}
|
||||||
|
//写回文件
|
||||||
|
fs.writeFileSync('./dist/manifest.json', JSON.stringify(manifest, null, 2))
|
||||||
|
|
||||||
|
console.log('fixFirefox.js done');
|
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "哔哩哔哩字幕列表",
|
"name": "哔哩哔哩字幕列表",
|
||||||
"description": "显示B站视频的字幕列表,可点击跳转与下载字幕,并支持翻译和总结字幕!",
|
"description": "显示B站视频的字幕列表,可点击跳转与下载字幕,并支持翻译和总结字幕!",
|
||||||
"version": "1.7.3",
|
"version": "1.9.1",
|
||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"storage"
|
"storage"
|
||||||
|
@@ -1,15 +1,16 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "bilibili-subtitle",
|
"name": "bilibili-subtitle",
|
||||||
"version": "1.7.3",
|
"version": "1.9.1",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "哔哩哔哩字幕列表",
|
"description": "哔哩哔哩字幕列表",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build_chrome": "tsc && vite build -m production_chrome && pnpm run fixChrome",
|
"build": "tsc && vite build -m production_chrome",
|
||||||
"fix": "eslint --fix --quiet .",
|
"build_chrome": "pnpm run build && node fixChrome.cjs",
|
||||||
"fixChrome": "node fixChrome.cjs"
|
"build_firefox": "pnpm run build && node fixFirefox.cjs",
|
||||||
|
"fix": "eslint --fix --quiet ."
|
||||||
},
|
},
|
||||||
"author": "IndieKKY",
|
"author": "IndieKKY",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
10
pnpm-lock.yaml
generated
10
pnpm-lock.yaml
generated
@@ -1,5 +1,9 @@
|
|||||||
lockfileVersion: '6.0'
|
lockfileVersion: '6.0'
|
||||||
|
|
||||||
|
settings:
|
||||||
|
autoInstallPeers: true
|
||||||
|
excludeLinksFromLockfile: false
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
'@crxjs/vite-plugin':
|
'@crxjs/vite-plugin':
|
||||||
specifier: ^1.0.14
|
specifier: ^1.0.14
|
||||||
@@ -2386,6 +2390,7 @@ packages:
|
|||||||
/iconv-lite@0.6.3:
|
/iconv-lite@0.6.3:
|
||||||
resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==}
|
resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==}
|
||||||
engines: {node: '>=0.10.0'}
|
engines: {node: '>=0.10.0'}
|
||||||
|
requiresBuild: true
|
||||||
dependencies:
|
dependencies:
|
||||||
safer-buffer: 2.1.2
|
safer-buffer: 2.1.2
|
||||||
optional: true
|
optional: true
|
||||||
@@ -3392,6 +3397,7 @@ packages:
|
|||||||
/pify@4.0.1:
|
/pify@4.0.1:
|
||||||
resolution: {integrity: sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==}
|
resolution: {integrity: sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==}
|
||||||
engines: {node: '>=6'}
|
engines: {node: '>=6'}
|
||||||
|
requiresBuild: true
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
/postcss-import@14.1.0(postcss@8.4.19):
|
/postcss-import@14.1.0(postcss@8.4.19):
|
||||||
@@ -3475,6 +3481,7 @@ packages:
|
|||||||
|
|
||||||
/prr@1.0.1:
|
/prr@1.0.1:
|
||||||
resolution: {integrity: sha512-yPw4Sng1gWghHQWj0B3ZggWUm4qVbPwPFcRG8KyxiU7J2OHFSoEHKS+EZ3fv5l1t9CyCiop6l/ZYeWbrgoQejw==}
|
resolution: {integrity: sha512-yPw4Sng1gWghHQWj0B3ZggWUm4qVbPwPFcRG8KyxiU7J2OHFSoEHKS+EZ3fv5l1t9CyCiop6l/ZYeWbrgoQejw==}
|
||||||
|
requiresBuild: true
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
/punycode@2.1.1:
|
/punycode@2.1.1:
|
||||||
@@ -3802,10 +3809,12 @@ packages:
|
|||||||
|
|
||||||
/safer-buffer@2.1.2:
|
/safer-buffer@2.1.2:
|
||||||
resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==}
|
resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==}
|
||||||
|
requiresBuild: true
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
/sax@1.2.4:
|
/sax@1.2.4:
|
||||||
resolution: {integrity: sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==}
|
resolution: {integrity: sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==}
|
||||||
|
requiresBuild: true
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
/scheduler@0.23.0:
|
/scheduler@0.23.0:
|
||||||
@@ -3822,6 +3831,7 @@ packages:
|
|||||||
/semver@5.7.1:
|
/semver@5.7.1:
|
||||||
resolution: {integrity: sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==}
|
resolution: {integrity: sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
|
requiresBuild: true
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
/semver@6.3.0:
|
/semver@6.3.0:
|
||||||
|
BIN
public/bibigpt.png
Normal file
BIN
public/bibigpt.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.0 KiB |
BIN
public/immersive-summary.png
Normal file
BIN
public/immersive-summary.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 23 KiB |
BIN
public/openai-up.ico
Normal file
BIN
public/openai-up.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 40 KiB |
BIN
public/youtube-caption.png
Normal file
BIN
public/youtube-caption.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
1
push.sh
1
push.sh
@@ -25,6 +25,7 @@ echo "Version updated to: $new_version"
|
|||||||
# build
|
# build
|
||||||
pnpm run build_chrome
|
pnpm run build_chrome
|
||||||
# zip dist
|
# zip dist
|
||||||
|
rm -f dist.zip
|
||||||
cd dist
|
cd dist
|
||||||
zip -r ../dist.zip ./*
|
zip -r ../dist.zip ./*
|
||||||
cd ../
|
cd ../
|
||||||
|
@@ -15,6 +15,7 @@ import {handleJson} from '@kky002/kky-util'
|
|||||||
import {useLocalStorage} from '@kky002/kky-hooks'
|
import {useLocalStorage} from '@kky002/kky-hooks'
|
||||||
import {Toaster} from 'react-hot-toast'
|
import {Toaster} from 'react-hot-toast'
|
||||||
import {setTheme} from './util/biz_util'
|
import {setTheme} from './util/biz_util'
|
||||||
|
import useSearchService from './hooks/useSearchService'
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const dispatch = useAppDispatch()
|
const dispatch = useAppDispatch()
|
||||||
@@ -72,6 +73,7 @@ function App() {
|
|||||||
// services
|
// services
|
||||||
useSubtitleService()
|
useSubtitleService()
|
||||||
useTranslateService()
|
useTranslateService()
|
||||||
|
useSearchService()
|
||||||
|
|
||||||
return <div className={classNames('select-none', import.meta.env.VITE_ENV === 'web-dev'?'w-[350px]':'w-full')} style={{
|
return <div className={classNames('select-none', import.meta.env.VITE_ENV === 'web-dev'?'w-[350px]':'w-full')} style={{
|
||||||
height: fold?undefined:`${totalHeight}px`,
|
height: fold?undefined:`${totalHeight}px`,
|
||||||
|
296
src/biz/Body.tsx
296
src/biz/Body.tsx
@@ -1,23 +1,49 @@
|
|||||||
import React, {useCallback, useEffect, useRef} from 'react'
|
import React, {useCallback, useEffect, useMemo, useRef} from 'react'
|
||||||
import {
|
import {
|
||||||
|
setAskFold,
|
||||||
|
setAskQuestion,
|
||||||
setAutoScroll,
|
setAutoScroll,
|
||||||
setAutoTranslate,
|
setAutoTranslate,
|
||||||
setCheckAutoScroll,
|
setCheckAutoScroll,
|
||||||
setCompact,
|
|
||||||
setFoldAll,
|
setFoldAll,
|
||||||
setNeedScroll,
|
setNeedScroll,
|
||||||
setPage,
|
setPage,
|
||||||
setSegmentFold
|
setSearchText,
|
||||||
|
setSegmentFold,
|
||||||
|
setTempData
|
||||||
} from '../redux/envReducer'
|
} from '../redux/envReducer'
|
||||||
import {useAppDispatch, useAppSelector} from '../hooks/redux'
|
import {useAppDispatch, useAppSelector} from '../hooks/redux'
|
||||||
import {AiOutlineAim, FaRegArrowAltCircleDown, IoWarning, MdExpand, RiFileCopy2Line, RiTranslate} from 'react-icons/all'
|
import {
|
||||||
|
AiOutlineAim,
|
||||||
|
AiOutlineCloseCircle,
|
||||||
|
BsDashSquare,
|
||||||
|
BsPlusSquare,
|
||||||
|
FaGripfire,
|
||||||
|
FaQuestion,
|
||||||
|
FaRegArrowAltCircleDown,
|
||||||
|
IoWarning,
|
||||||
|
MdExpand,
|
||||||
|
RiTranslate
|
||||||
|
} from 'react-icons/all'
|
||||||
import classNames from 'classnames'
|
import classNames from 'classnames'
|
||||||
import toast from 'react-hot-toast'
|
import toast from 'react-hot-toast'
|
||||||
import SegmentCard from './SegmentCard'
|
import SegmentCard from './SegmentCard'
|
||||||
import {HEADER_HEIGHT, PAGE_SETTINGS, SUMMARIZE_ALL_THRESHOLD, SUMMARIZE_TYPES, TITLE_HEIGHT} from '../const'
|
import {
|
||||||
|
ASK_ENABLED_DEFAULT,
|
||||||
|
HEADER_HEIGHT,
|
||||||
|
PAGE_SETTINGS,
|
||||||
|
RECOMMEND_HEIGHT,
|
||||||
|
SEARCH_BAR_HEIGHT,
|
||||||
|
SUMMARIZE_ALL_THRESHOLD,
|
||||||
|
TITLE_HEIGHT
|
||||||
|
} from '../const'
|
||||||
import {FaClipboardList} from 'react-icons/fa'
|
import {FaClipboardList} from 'react-icons/fa'
|
||||||
import useTranslate from '../hooks/useTranslate'
|
import useTranslate from '../hooks/useTranslate'
|
||||||
import {getSummarize} from '../util/biz_util'
|
import {getSummarize} from '../util/biz_util'
|
||||||
|
import {openUrl} from '@kky002/kky-util'
|
||||||
|
import Markdown from '../components/Markdown'
|
||||||
|
import {random} from 'lodash-es'
|
||||||
|
import useKeyService from '../hooks/useKeyService'
|
||||||
|
|
||||||
const Body = () => {
|
const Body = () => {
|
||||||
const dispatch = useAppDispatch()
|
const dispatch = useAppDispatch()
|
||||||
@@ -27,12 +53,17 @@ const Body = () => {
|
|||||||
const segments = useAppSelector(state => state.env.segments)
|
const segments = useAppSelector(state => state.env.segments)
|
||||||
const foldAll = useAppSelector(state => state.env.foldAll)
|
const foldAll = useAppSelector(state => state.env.foldAll)
|
||||||
const envData = useAppSelector(state => state.env.envData)
|
const envData = useAppSelector(state => state.env.envData)
|
||||||
const compact = useAppSelector(state => state.env.compact)
|
const compact = useAppSelector(state => state.env.tempData.compact)
|
||||||
const apiKey = useAppSelector(state => state.env.envData.apiKey)
|
|
||||||
const floatKeyPointsSegIdx = useAppSelector(state => state.env.floatKeyPointsSegIdx)
|
const floatKeyPointsSegIdx = useAppSelector(state => state.env.floatKeyPointsSegIdx)
|
||||||
const translateEnable = useAppSelector(state => state.env.envData.translateEnable)
|
const translateEnable = useAppSelector(state => state.env.envData.translateEnable)
|
||||||
const summarizeEnable = useAppSelector(state => state.env.envData.summarizeEnable)
|
const summarizeEnable = useAppSelector(state => state.env.envData.summarizeEnable)
|
||||||
const {addSummarizeTask} = useTranslate()
|
const {addSummarizeTask, addAskTask} = useTranslate()
|
||||||
|
const infos = useAppSelector(state => state.env.infos)
|
||||||
|
const askFold = useAppSelector(state => state.env.askFold)
|
||||||
|
const askQuestion = useAppSelector(state => state.env.askQuestion)
|
||||||
|
const askContent = useAppSelector(state => state.env.askContent)
|
||||||
|
const askStatus = useAppSelector(state => state.env.askStatus)
|
||||||
|
const askError = useAppSelector(state => state.env.askError)
|
||||||
const bodyRef = useRef<any>()
|
const bodyRef = useRef<any>()
|
||||||
const curOffsetTop = useAppSelector(state => state.env.curOffsetTop)
|
const curOffsetTop = useAppSelector(state => state.env.curOffsetTop)
|
||||||
const checkAutoScroll = useAppSelector(state => state.env.checkAutoScroll)
|
const checkAutoScroll = useAppSelector(state => state.env.checkAutoScroll)
|
||||||
@@ -40,13 +71,38 @@ const Body = () => {
|
|||||||
const totalHeight = useAppSelector(state => state.env.totalHeight)
|
const totalHeight = useAppSelector(state => state.env.totalHeight)
|
||||||
const curSummaryType = useAppSelector(state => state.env.tempData.curSummaryType)
|
const curSummaryType = useAppSelector(state => state.env.tempData.curSummaryType)
|
||||||
const title = useAppSelector(state => state.env.title)
|
const title = useAppSelector(state => state.env.title)
|
||||||
|
const fontSize = useAppSelector(state => state.env.envData.fontSize)
|
||||||
|
const searchText = useAppSelector(state => state.env.searchText)
|
||||||
|
const recommendIdx = useMemo(() => random(0, 3), [])
|
||||||
|
const showSearchInput = useMemo(() => {
|
||||||
|
return (segments != null && segments.length > 0) && (envData.searchEnabled ? envData.searchEnabled : (envData.askEnabled ?? ASK_ENABLED_DEFAULT))
|
||||||
|
}, [envData.askEnabled, envData.searchEnabled, segments])
|
||||||
|
const searchPlaceholder = useMemo(() => {
|
||||||
|
let placeholder = ''
|
||||||
|
if (envData.searchEnabled) {
|
||||||
|
if (envData.askEnabled??ASK_ENABLED_DEFAULT) {
|
||||||
|
placeholder = '搜索或提问字幕内容'
|
||||||
|
} else {
|
||||||
|
placeholder = '搜索字幕内容'
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (envData.askEnabled??ASK_ENABLED_DEFAULT) {
|
||||||
|
placeholder = '提问字幕内容'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return placeholder
|
||||||
|
}, [envData.askEnabled, envData.searchEnabled])
|
||||||
|
|
||||||
const normalCallback = useCallback(() => {
|
const normalCallback = useCallback(() => {
|
||||||
dispatch(setCompact(false))
|
dispatch(setTempData({
|
||||||
|
compact: false
|
||||||
|
}))
|
||||||
}, [dispatch])
|
}, [dispatch])
|
||||||
|
|
||||||
const compactCallback = useCallback(() => {
|
const compactCallback = useCallback(() => {
|
||||||
dispatch(setCompact(true))
|
dispatch(setTempData({
|
||||||
|
compact: true
|
||||||
|
}))
|
||||||
}, [dispatch])
|
}, [dispatch])
|
||||||
|
|
||||||
const posCallback = useCallback(() => {
|
const posCallback = useCallback(() => {
|
||||||
@@ -54,6 +110,7 @@ const Body = () => {
|
|||||||
}, [dispatch])
|
}, [dispatch])
|
||||||
|
|
||||||
const onSummarizeAll = useCallback(() => {
|
const onSummarizeAll = useCallback(() => {
|
||||||
|
const apiKey = envData.aiType === 'gemini'?envData.geminiApiKey:envData.apiKey
|
||||||
if (!apiKey) {
|
if (!apiKey) {
|
||||||
dispatch(setPage(PAGE_SETTINGS))
|
dispatch(setPage(PAGE_SETTINGS))
|
||||||
toast.error('需要先设置ApiKey!')
|
toast.error('需要先设置ApiKey!')
|
||||||
@@ -76,10 +133,11 @@ const Body = () => {
|
|||||||
}
|
}
|
||||||
toast.success(`已添加${segments_.length}个总结任务!`)
|
toast.success(`已添加${segments_.length}个总结任务!`)
|
||||||
}
|
}
|
||||||
}, [addSummarizeTask, apiKey, curSummaryType, dispatch, segments])
|
}, [addSummarizeTask, curSummaryType, dispatch, envData.aiType, envData.apiKey, envData.geminiApiKey, segments])
|
||||||
|
|
||||||
const onFoldAll = useCallback(() => {
|
const onFoldAll = useCallback(() => {
|
||||||
dispatch(setFoldAll(!foldAll))
|
dispatch(setFoldAll(!foldAll))
|
||||||
|
dispatch(setAskFold(!foldAll))
|
||||||
for (const segment of segments ?? []) {
|
for (const segment of segments ?? []) {
|
||||||
dispatch(setSegmentFold({
|
dispatch(setSegmentFold({
|
||||||
segmentStartIdx: segment.startIdx,
|
segmentStartIdx: segment.startIdx,
|
||||||
@@ -89,13 +147,14 @@ const Body = () => {
|
|||||||
}, [dispatch, foldAll, segments])
|
}, [dispatch, foldAll, segments])
|
||||||
|
|
||||||
const toggleAutoTranslateCallback = useCallback(() => {
|
const toggleAutoTranslateCallback = useCallback(() => {
|
||||||
if (envData.apiKey) {
|
const apiKey = envData.aiType === 'gemini'?envData.geminiApiKey:envData.apiKey
|
||||||
|
if (apiKey) {
|
||||||
dispatch(setAutoTranslate(!autoTranslate))
|
dispatch(setAutoTranslate(!autoTranslate))
|
||||||
} else {
|
} else {
|
||||||
dispatch(setPage(PAGE_SETTINGS))
|
dispatch(setPage(PAGE_SETTINGS))
|
||||||
toast.error('需要先设置ApiKey!')
|
toast.error('需要先设置ApiKey!')
|
||||||
}
|
}
|
||||||
}, [autoTranslate, dispatch, envData.apiKey])
|
}, [autoTranslate, dispatch, envData.aiType, envData.apiKey, envData.geminiApiKey])
|
||||||
|
|
||||||
const onEnableAutoScroll = useCallback(() => {
|
const onEnableAutoScroll = useCallback(() => {
|
||||||
dispatch(setAutoScroll(true))
|
dispatch(setAutoScroll(true))
|
||||||
@@ -117,10 +176,45 @@ const Body = () => {
|
|||||||
}
|
}
|
||||||
}, [curSummaryType, segments, title])
|
}, [curSummaryType, segments, title])
|
||||||
|
|
||||||
|
const onSearchTextChange = useCallback((e: any) => {
|
||||||
|
const searchText = e.target.value
|
||||||
|
dispatch(setSearchText(searchText))
|
||||||
|
}, [dispatch])
|
||||||
|
|
||||||
|
const onClearSearchText = useCallback(() => {
|
||||||
|
dispatch(setSearchText(''))
|
||||||
|
}, [dispatch])
|
||||||
|
|
||||||
|
const onAsk = useCallback(() => {
|
||||||
|
if ((envData.askEnabled??ASK_ENABLED_DEFAULT) && searchText) {
|
||||||
|
const apiKey = envData.aiType === 'gemini'?envData.geminiApiKey:envData.apiKey
|
||||||
|
if (apiKey) {
|
||||||
|
if (segments != null && segments.length > 0) {
|
||||||
|
dispatch(setAskQuestion(searchText))
|
||||||
|
addAskTask(segments[0], searchText).catch(console.error)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dispatch(setPage(PAGE_SETTINGS))
|
||||||
|
toast.error('需要先设置ApiKey!')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [addAskTask, dispatch, envData.aiType, envData.apiKey, envData.askEnabled, envData.geminiApiKey, searchText, segments])
|
||||||
|
|
||||||
|
const onSetAsk = useCallback(() => {
|
||||||
|
dispatch(setSearchText(askQuestion??''))
|
||||||
|
}, [askQuestion, dispatch])
|
||||||
|
|
||||||
|
const onAskFold = useCallback(() => {
|
||||||
|
dispatch(setAskFold(!askFold))
|
||||||
|
}, [askFold, dispatch])
|
||||||
|
|
||||||
|
// service
|
||||||
|
useKeyService()
|
||||||
|
|
||||||
// 自动滚动
|
// 自动滚动
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (checkAutoScroll && curOffsetTop && autoScroll && !needScroll) {
|
if (checkAutoScroll && curOffsetTop && autoScroll && !needScroll) {
|
||||||
if (bodyRef.current.scrollTop <= curOffsetTop - bodyRef.current.offsetTop - (totalHeight-120) + (floatKeyPointsSegIdx != null ? 100 : 0) ||
|
if (bodyRef.current.scrollTop <= curOffsetTop - bodyRef.current.offsetTop - (totalHeight-160) + (floatKeyPointsSegIdx != null ? 100 : 0) ||
|
||||||
bodyRef.current.scrollTop >= curOffsetTop - bodyRef.current.offsetTop - 40 - 10
|
bodyRef.current.scrollTop >= curOffsetTop - bodyRef.current.offsetTop - 40 - 10
|
||||||
) {
|
) {
|
||||||
dispatch(setNeedScroll(true))
|
dispatch(setNeedScroll(true))
|
||||||
@@ -131,6 +225,7 @@ const Body = () => {
|
|||||||
}, [autoScroll, checkAutoScroll, curOffsetTop, dispatch, floatKeyPointsSegIdx, needScroll, totalHeight])
|
}, [autoScroll, checkAutoScroll, curOffsetTop, dispatch, floatKeyPointsSegIdx, needScroll, totalHeight])
|
||||||
|
|
||||||
return <div className='relative'>
|
return <div className='relative'>
|
||||||
|
{/* title */}
|
||||||
<div className='absolute top-1 left-6 flex-center gap-1'>
|
<div className='absolute top-1 left-6 flex-center gap-1'>
|
||||||
<AiOutlineAim className='cursor-pointer' onClick={posCallback} title='滚动到视频位置'/>
|
<AiOutlineAim className='cursor-pointer' onClick={posCallback} title='滚动到视频位置'/>
|
||||||
{segments != null && segments.length > 0 &&
|
{segments != null && segments.length > 0 &&
|
||||||
@@ -158,25 +253,186 @@ const Body = () => {
|
|||||||
<IoWarning className='text-warning'/>
|
<IoWarning className='text-warning'/>
|
||||||
</div>}
|
</div>}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* search */}
|
||||||
|
{showSearchInput && <div className='px-2 py-1 flex flex-col relative'>
|
||||||
|
<input type='text' className='input input-xs bg-base-200' placeholder={searchPlaceholder} value={searchText} onChange={onSearchTextChange}/>
|
||||||
|
{searchText && <button className='absolute top-1 right-2 btn btn-ghost btn-xs btn-circle text-base-content/75' onClick={onClearSearchText}><AiOutlineCloseCircle/></button>}
|
||||||
|
</div>}
|
||||||
|
|
||||||
|
{/* 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'
|
||||||
data-tip='开启自动滚动'
|
data-tip='开启自动滚动'
|
||||||
onClick={onEnableAutoScroll}>
|
onClick={onEnableAutoScroll}>
|
||||||
<FaRegArrowAltCircleDown className={autoScroll ? 'text-accent' : ''}/>
|
<FaRegArrowAltCircleDown className={autoScroll ? 'text-accent' : ''}/>
|
||||||
</div>}
|
</div>}
|
||||||
|
|
||||||
|
{/* body */}
|
||||||
<div ref={bodyRef} onWheel={onWheel}
|
<div ref={bodyRef} onWheel={onWheel}
|
||||||
className={classNames('flex flex-col gap-1.5 overflow-y-auto select-text scroll-smooth', floatKeyPointsSegIdx != null && 'pb-[100px]')}
|
className={classNames('flex flex-col gap-1.5 overflow-y-auto select-text scroll-smooth', floatKeyPointsSegIdx != null && 'pb-[100px]')}
|
||||||
style={{
|
style={{
|
||||||
height: `${totalHeight - HEADER_HEIGHT - TITLE_HEIGHT}px`
|
height: `${totalHeight - HEADER_HEIGHT - TITLE_HEIGHT - RECOMMEND_HEIGHT - (showSearchInput ? SEARCH_BAR_HEIGHT : 0)}px`
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{segments?.map((segment, segmentIdx) => <SegmentCard key={segment.startIdx} segment={segment} segmentIdx={segmentIdx} bodyRef={bodyRef}/>)}
|
{/* ask */}
|
||||||
<div className='flex flex-col items-center text-center pt-1 pb-2'>
|
{(envData.askEnabled ?? ASK_ENABLED_DEFAULT) && (searchText || askQuestion) &&
|
||||||
<div className='font-semibold text-accent'>💡<span className='underline underline-offset-4'>提示</span>💡</div>
|
<div className='shadow bg-base-200 my-0.5 mx-1.5 p-1.5 rounded flex flex-col justify-center items-center'>
|
||||||
<div className='text-sm desc px-2'>可以尝试将<span className='text-amber-600 font-semibold'>概览</span>生成的内容粘贴到<span className='text-secondary/75 font-semibold'>视频评论</span>里,发布后看看有什么效果🥳</div>
|
<div className='w-full relative flex justify-center min-h-[20px]'>
|
||||||
{(segments?.length??0) > 0 && <button className='mt-1.5 btn btn-xs btn-info' onClick={onCopy}>点击复制生成的{SUMMARIZE_TYPES[curSummaryType].name}<RiFileCopy2Line/></button>}
|
<div className='absolute left-0 top-0 bottom-0 text-xs select-none flex-center desc'>
|
||||||
|
{askFold
|
||||||
|
? <BsPlusSquare className='cursor-pointer' onClick={onAskFold}/> :
|
||||||
|
<BsDashSquare className='cursor-pointer' onClick={onAskFold}/>}
|
||||||
|
</div>
|
||||||
|
<div className="tabs">
|
||||||
|
<a className="tab tab-lifted tab-xs tab-disabled cursor-default"></a>
|
||||||
|
<a className='tab tab-lifted tab-xs tab-active'><FaQuestion/>提问</a>
|
||||||
|
<a className="tab tab-lifted tab-xs tab-disabled cursor-default"></a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{!askFold && askQuestion &&
|
||||||
|
<div className='link link-hover text-sm font-medium max-w-[90%]' onClick={onSetAsk}>{askQuestion}</div>}
|
||||||
|
{!askFold && askContent &&
|
||||||
|
<div className={classNames('font-medium max-w-[90%] mt-1', fontSize === 'large' ? 'text-sm' : 'text-xs')}>
|
||||||
|
<Markdown content={askContent}/>
|
||||||
|
</div>}
|
||||||
|
{!askFold && <button disabled={askStatus === 'pending'}
|
||||||
|
className={classNames('btn btn-link btn-xs', askStatus === 'pending' && 'loading')}
|
||||||
|
onClick={onAsk}>{askStatus === 'init' ? '点击提问' : (askStatus === 'pending' ? '生成中' : '重新生成')}</button>}
|
||||||
|
{!askFold && askStatus === 'init' && <div className='desc-lighter text-xs'>提问举例:这个视频说了什么</div>}
|
||||||
|
{!askFold && askError && <div className='text-xs text-error'>{askError}</div>}
|
||||||
|
</div>}
|
||||||
|
|
||||||
|
{/* segments */}
|
||||||
|
{segments?.map((segment, segmentIdx) => <SegmentCard key={segment.startIdx} segment={segment}
|
||||||
|
segmentIdx={segmentIdx} bodyRef={bodyRef}/>)}
|
||||||
|
|
||||||
|
{/* tip */}
|
||||||
|
<div className='text-sm font-semibold text-center'>快捷键提示</div>
|
||||||
|
<ul className='list-disc text-sm desc pl-5'>
|
||||||
|
<li>单击字幕跳转,双击字幕跳转+切换暂停。</li>
|
||||||
|
<li>alt+单击字幕复制单条字幕。</li>
|
||||||
|
<li>上下方向键来移动当前字幕(可先点击字幕使焦点在字幕列表内)。</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
{/* <div className='flex flex-col items-center text-center pt-1 pb-2'> */}
|
||||||
|
{/* <div className='font-semibold text-accent'>💡<span className='underline underline-offset-4'>提示</span>💡</div> */}
|
||||||
|
{/* <div className='text-sm desc px-2'>可以尝试将<span className='text-amber-600 font-semibold'>概览</span>生成的内容粘贴到<span */}
|
||||||
|
{/* className='text-secondary/75 font-semibold'>视频评论</span>里,发布后看看有什么效果🥳 */}
|
||||||
|
{/* </div> */}
|
||||||
|
{/* {(segments?.length ?? 0) > 0 && <button className='mt-1.5 btn btn-xs btn-info' */}
|
||||||
|
{/* onClick={onCopy}>点击复制生成的{SUMMARIZE_TYPES[curSummaryType].name}<RiFileCopy2Line/> */}
|
||||||
|
{/* </button>} */}
|
||||||
|
{/* </div> */}
|
||||||
|
<div className='flex flex-col'>
|
||||||
|
<div className='flex flex-col items-center text-center py-2 mx-4 border-t border-t-base-300'>
|
||||||
|
<div className='font-semibold text-accent flex items-center gap-1'><img src='/bibigpt.png'
|
||||||
|
alt='BibiGPT logo'
|
||||||
|
className='w-8 h-8'/>BibiGPT
|
||||||
|
</div>
|
||||||
|
<div className='text-sm px-2 desc'>这是<span className='text-amber-600 font-semibold text-base'>网页</span>版的字幕列表,支持<span
|
||||||
|
className='font-semibold'>任意</span>视频提取字幕总结(包括没有字幕的视频)
|
||||||
|
</div>
|
||||||
|
<div className='flex gap-2'>
|
||||||
|
<a title='BibiGPT' href='https://bibigpt.co/r/bilibili'
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault()
|
||||||
|
openUrl('https://bibigpt.co/r/bilibili')
|
||||||
|
}} className='link text-sm text-accent'>✨ BibiGPT ✨</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col items-center text-center py-2 mx-4 border-t border-t-base-300'>
|
||||||
|
<div className='font-semibold text-accent flex items-center gap-1'><img src='/youtube-caption.png'
|
||||||
|
alt='youtube caption logo'
|
||||||
|
className='w-8 h-8'/>YouTube Caption
|
||||||
|
</div>
|
||||||
|
<div className='text-sm px-2 desc'>这是<span className='text-amber-600 font-semibold text-base'>YouTube</span>版的字幕列表
|
||||||
|
</div>
|
||||||
|
<div className='flex gap-2'>
|
||||||
|
<a title='Chrome商店' href='https://chromewebstore.google.com/detail/fiaeclpicddpifeflpmlgmbjgaedladf'
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault()
|
||||||
|
openUrl('https://chromewebstore.google.com/detail/fiaeclpicddpifeflpmlgmbjgaedladf')
|
||||||
|
}} className='link text-sm text-accent'>Chrome商店</a>
|
||||||
|
<a title='Edge商店'
|
||||||
|
href='https://microsoftedge.microsoft.com/addons/detail/galeejdehabppfgooagmkclpppnbccpc'
|
||||||
|
onClick={e => {
|
||||||
|
e.preventDefault()
|
||||||
|
openUrl('https://microsoftedge.microsoft.com/addons/detail/galeejdehabppfgooagmkclpppnbccpc')
|
||||||
|
}} className='link text-sm text-accent'>Edge商店</a>
|
||||||
|
<a title='Crx搜搜(国内可访问)'
|
||||||
|
href='https://www.crxsoso.com/webstore/detail/fiaeclpicddpifeflpmlgmbjgaedladf'
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault()
|
||||||
|
openUrl('https://www.crxsoso.com/webstore/detail/fiaeclpicddpifeflpmlgmbjgaedladf')
|
||||||
|
}} className='link text-sm text-accent'>Crx搜搜(国内可访问)</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className='flex flex-col items-center text-center py-2 mx-4 border-t border-t-base-300'>
|
||||||
|
<div className='font-semibold text-accent flex items-center gap-1'><img src='/immersive-summary.png'
|
||||||
|
alt='Immersive Summary logo'
|
||||||
|
className='w-8 h-8'/>Immersive Summary
|
||||||
|
</div>
|
||||||
|
<div className='text-sm px-2 desc'>沉浸式总结,多种方式总结网页文章。</div>
|
||||||
|
<div className='flex gap-2'>
|
||||||
|
<a title='Chrome商店' href='https://chromewebstore.google.com/detail/mcijpllinkhflgpkggimnafkbmpiijah'
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault()
|
||||||
|
openUrl('https://chromewebstore.google.com/detail/mcijpllinkhflgpkggimnafkbmpiijah')
|
||||||
|
}} className='link text-sm text-accent'>Chrome商店</a>
|
||||||
|
<a title='Crx搜搜(国内可访问)'
|
||||||
|
href='https://www.crxsoso.com/webstore/detail/mcijpllinkhflgpkggimnafkbmpiijah'
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault()
|
||||||
|
openUrl('https://www.crxsoso.com/webstore/detail/mcijpllinkhflgpkggimnafkbmpiijah')
|
||||||
|
}} className='link text-sm text-accent'>Crx搜搜(国内可访问)</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* recommend */}
|
||||||
|
<div className='p-0.5' style={{
|
||||||
|
height: `${RECOMMEND_HEIGHT}px`
|
||||||
|
}}>
|
||||||
|
{recommendIdx === 0 && <div className='flex items-center gap-1.5 rounded shadow-sm bg-base-200/10'>
|
||||||
|
<a className='link link-accent link-hover font-semibold text-sm flex items-center' onClick={(e) => {
|
||||||
|
e.preventDefault()
|
||||||
|
openUrl('https://bibigpt.co/r/bilibili')
|
||||||
|
}}><img src='/bibigpt.png'
|
||||||
|
alt='BibiGPT logo'
|
||||||
|
className='w-8 h-8'/>✨ BibiGPT ✨</a>
|
||||||
|
<span className='text-sm desc'>支持任意视频的网页版总结。</span>
|
||||||
|
</div>}
|
||||||
|
{recommendIdx === 1 && <div className='flex items-center gap-1 rounded shadow-sm bg-base-200/10'>
|
||||||
|
<a className='link link-accent link-hover font-semibold text-sm flex items-center' onClick={(e) => {
|
||||||
|
e.preventDefault()
|
||||||
|
openUrl('https://chromewebstore.google.com/detail/fiaeclpicddpifeflpmlgmbjgaedladf')
|
||||||
|
}}><img src='/youtube-caption.png'
|
||||||
|
alt='youtube caption logo'
|
||||||
|
className='w-8 h-8'/>YouTube Caption</a>
|
||||||
|
<span className='text-sm desc'>YouTube版的字幕列表。</span>
|
||||||
|
</div>}
|
||||||
|
{recommendIdx === 2 && <div className='flex items-center gap-1 rounded shadow-sm bg-base-200/10'>
|
||||||
|
<a className='link link-accent link-hover font-semibold text-sm flex items-center' onClick={(e) => {
|
||||||
|
e.preventDefault()
|
||||||
|
openUrl('https://chromewebstore.google.com/detail/mcijpllinkhflgpkggimnafkbmpiijah')
|
||||||
|
}}><img src='/immersive-summary.png'
|
||||||
|
alt='Immersive Summary logo'
|
||||||
|
className='w-8 h-8'/>Immersive Summary</a>
|
||||||
|
<span className='text-sm desc'>沉浸式总结网页文章。</span>
|
||||||
|
</div>}
|
||||||
|
{recommendIdx === 3 && <div className='flex items-center gap-1 rounded shadow-sm bg-base-200/10'>
|
||||||
|
<a className='link link-accent link-hover font-semibold text-sm flex items-center' onClick={(e) => {
|
||||||
|
e.preventDefault()
|
||||||
|
openUrl('https://api.openai-up.com/register?aff=varM')
|
||||||
|
}}><img src='/openai-up.ico'
|
||||||
|
alt='Openai Up logo'
|
||||||
|
className='w-8 h-8'/>Openai代理</a>
|
||||||
|
<span className='text-sm desc flex items-center'>目前价格不到官方的6折<FaGripfire
|
||||||
|
className='text-amber-600'/></span>
|
||||||
|
</div>}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,17 +4,14 @@ import {getDisplay, getTransText} from '../util/biz_util'
|
|||||||
import classNames from 'classnames'
|
import classNames from 'classnames'
|
||||||
|
|
||||||
const CompactSegmentItem = (props: {
|
const CompactSegmentItem = (props: {
|
||||||
item: {
|
item: TranscriptItem
|
||||||
from: number
|
|
||||||
to: number
|
|
||||||
content: string
|
|
||||||
}
|
|
||||||
idx: number
|
idx: number
|
||||||
isIn: boolean
|
isIn: boolean
|
||||||
last: boolean
|
last: boolean
|
||||||
moveCallback: (event: any) => void
|
moveCallback: (event: any) => void
|
||||||
|
move2Callback: (event: any) => void
|
||||||
}) => {
|
}) => {
|
||||||
const {item, idx, last, isIn, moveCallback} = props
|
const {item, idx, last, isIn, moveCallback, move2Callback} = props
|
||||||
const transResult = useAppSelector(state => state.env.transResults[idx])
|
const transResult = useAppSelector(state => state.env.transResults[idx])
|
||||||
const envData = useAppSelector(state => state.env.envData)
|
const envData = useAppSelector(state => state.env.envData)
|
||||||
const fontSize = useAppSelector(state => state.env.envData.fontSize)
|
const fontSize = useAppSelector(state => state.env.envData.fontSize)
|
||||||
@@ -23,10 +20,10 @@ const CompactSegmentItem = (props: {
|
|||||||
const display = useMemo(() => getDisplay(envData.transDisplay, item.content, transText), [envData.transDisplay, item.content, transText])
|
const display = useMemo(() => getDisplay(envData.transDisplay, item.content, transText), [envData.transDisplay, item.content, transText])
|
||||||
|
|
||||||
return <div className={classNames('inline', fontSize === 'large'?'text-sm':'text-xs')}>
|
return <div className={classNames('inline', fontSize === 'large'?'text-sm':'text-xs')}>
|
||||||
<span className={'pl-1 pr-0.5 py-0.5 cursor-pointer rounded-sm hover:bg-base-200'} onClick={moveCallback}>
|
<span className={'pl-1 pr-0.5 py-0.5 cursor-pointer rounded-sm hover:bg-base-200'} onClick={moveCallback} onDoubleClick={move2Callback}>
|
||||||
<text className={classNames('font-medium', isIn ? 'text-primary underline' : '')}>{display.main}</text>
|
<text className={classNames('font-medium', isIn ? 'text-primary underline' : '')}>{display.main}</text>
|
||||||
{display.sub && <text className='desc'>({display.sub})</text>}</span>
|
{display.sub && <text className='desc'>({display.sub})</text>}</span>
|
||||||
<span>{!last && ', '}</span>
|
<span className='text-base-content/75'>{!last && ','}</span>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -11,7 +11,7 @@ import {
|
|||||||
import Popover from '../components/Popover'
|
import Popover from '../components/Popover'
|
||||||
import {Placement} from '@popperjs/core/lib/enums'
|
import {Placement} from '@popperjs/core/lib/enums'
|
||||||
import {useAppDispatch, useAppSelector} from '../hooks/redux'
|
import {useAppDispatch, useAppSelector} from '../hooks/redux'
|
||||||
import {setDownloadType, setEnvData, setPage} from '../redux/envReducer'
|
import {setEnvData, setPage, setTempData} from '../redux/envReducer'
|
||||||
import {EventBusContext} from '../Router'
|
import {EventBusContext} from '../Router'
|
||||||
import {EVENT_EXPAND, PAGE_SETTINGS} from '../const'
|
import {EVENT_EXPAND, PAGE_SETTINGS} from '../const'
|
||||||
import {formatSrtTime, formatTime, formatVttTime} from '../util/util'
|
import {formatSrtTime, formatTime, formatVttTime} from '../util/util'
|
||||||
@@ -62,10 +62,11 @@ const MoreBtn = (props: Props) => {
|
|||||||
const data = useAppSelector(state => state.env.data)
|
const data = useAppSelector(state => state.env.data)
|
||||||
const envReady = useAppSelector(state => state.env.envReady)
|
const envReady = useAppSelector(state => state.env.envReady)
|
||||||
const envData = useAppSelector(state => state.env.envData)
|
const envData = useAppSelector(state => state.env.envData)
|
||||||
const downloadType = useAppSelector(state => state.env.downloadType)
|
const downloadType = useAppSelector(state => state.env.tempData.downloadType)
|
||||||
const [moreVisible, setMoreVisible] = useState(false)
|
const [moreVisible, setMoreVisible] = useState(false)
|
||||||
const eventBus = useContext(EventBusContext)
|
const eventBus = useContext(EventBusContext)
|
||||||
const segments = useAppSelector(state => state.env.segments)
|
const segments = useAppSelector(state => state.env.segments)
|
||||||
|
const url = useAppSelector(state => state.env.url)
|
||||||
const title = useAppSelector(state => state.env.title)
|
const title = useAppSelector(state => state.env.title)
|
||||||
const curSummaryType = useAppSelector(state => state.env.tempData.curSummaryType)
|
const curSummaryType = useAppSelector(state => state.env.tempData.curSummaryType)
|
||||||
|
|
||||||
@@ -76,19 +77,19 @@ const MoreBtn = (props: Props) => {
|
|||||||
|
|
||||||
let s, fileName
|
let s, fileName
|
||||||
if (!downloadType || downloadType === 'text') {
|
if (!downloadType || downloadType === 'text') {
|
||||||
s = ''
|
s = `${title??'无标题'}\n${url??'无链接'}\n\n`
|
||||||
for (const item of data.body) {
|
for (const item of data.body) {
|
||||||
s += item.content + '\n'
|
s += item.content + '\n'
|
||||||
}
|
}
|
||||||
fileName = 'download.txt'
|
fileName = 'download.txt'
|
||||||
} else if (downloadType === 'textWithTime') {
|
} else if (downloadType === 'textWithTime') {
|
||||||
s = ''
|
s = `${title??'无标题'}\n${url??'无链接'}\n\n`
|
||||||
for (const item of data.body) {
|
for (const item of data.body) {
|
||||||
s += formatTime(item.from) + ' ' + item.content + '\n'
|
s += formatTime(item.from) + ' ' + item.content + '\n'
|
||||||
}
|
}
|
||||||
fileName = 'download.txt'
|
fileName = 'download.txt'
|
||||||
} else if (downloadType === 'article') {
|
} else if (downloadType === 'article') {
|
||||||
s = ''
|
s = `${title??'无标题'}\n${url??'无链接'}\n\n`
|
||||||
for (const item of data.body) {
|
for (const item of data.body) {
|
||||||
s += item.content + ', '
|
s += item.content + ', '
|
||||||
}
|
}
|
||||||
@@ -138,9 +139,10 @@ const MoreBtn = (props: Props) => {
|
|||||||
s = JSON.stringify(data)
|
s = JSON.stringify(data)
|
||||||
fileName = 'download.json'
|
fileName = 'download.json'
|
||||||
} else if (downloadType === 'summarize') {
|
} else if (downloadType === 'summarize') {
|
||||||
|
s = `${title??'无标题'}\n${url??'无链接'}\n\n`
|
||||||
const [success, content] = getSummarize(title, segments, curSummaryType)
|
const [success, content] = getSummarize(title, segments, curSummaryType)
|
||||||
if (!success) return
|
if (!success) return
|
||||||
s = content
|
s += content
|
||||||
fileName = '总结.txt'
|
fileName = '总结.txt'
|
||||||
} else {
|
} else {
|
||||||
return
|
return
|
||||||
@@ -153,7 +155,7 @@ const MoreBtn = (props: Props) => {
|
|||||||
}).catch(console.error)
|
}).catch(console.error)
|
||||||
}
|
}
|
||||||
setMoreVisible(false)
|
setMoreVisible(false)
|
||||||
}, [curSummaryType, data, downloadType, segments, title])
|
}, [curSummaryType, data, downloadType, segments, title, url])
|
||||||
|
|
||||||
const downloadAudioCallback = useCallback(() => {
|
const downloadAudioCallback = useCallback(() => {
|
||||||
window.parent.postMessage({
|
window.parent.postMessage({
|
||||||
@@ -162,7 +164,9 @@ const MoreBtn = (props: Props) => {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const selectCallback = useCallback((e: any) => {
|
const selectCallback = useCallback((e: any) => {
|
||||||
dispatch(setDownloadType(e.target.value))
|
dispatch(setTempData({
|
||||||
|
downloadType: e.target.value,
|
||||||
|
}))
|
||||||
}, [dispatch])
|
}, [dispatch])
|
||||||
|
|
||||||
const preventCallback = useCallback((e: any) => {
|
const preventCallback = useCallback((e: any) => {
|
||||||
@@ -259,6 +263,27 @@ const MoreBtn = (props: Props) => {
|
|||||||
微信公众号(IndieKKY)
|
微信公众号(IndieKKY)
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
{/* <li className='hover:bg-accent'> */}
|
||||||
|
{/* <a className='flex items-center' onClick={(e) => { */}
|
||||||
|
{/* e.preventDefault() */}
|
||||||
|
{/* e.stopPropagation() */}
|
||||||
|
{/* openUrl('https://bibigpt.co/r/bilibili') */}
|
||||||
|
{/* }}> */}
|
||||||
|
{/* <img alt='BibiGPT' src='/bibigpt.png' className='w-[20px] h-[20px] bg-white rounded-sm p-0.5'/> */}
|
||||||
|
{/* BibiGPT */}
|
||||||
|
{/* </a> */}
|
||||||
|
{/* </li> */}
|
||||||
|
{/* <li className='hover:bg-accent'> */}
|
||||||
|
{/* <a className='flex items-center' onClick={(e) => { */}
|
||||||
|
{/* e.preventDefault() */}
|
||||||
|
{/* e.stopPropagation() */}
|
||||||
|
{/* openUrl('https://chromewebstore.google.com/detail/fiaeclpicddpifeflpmlgmbjgaedladf') */}
|
||||||
|
{/* }}> */}
|
||||||
|
{/* <img alt='youtube subtitle' src='/youtube-caption.png' */}
|
||||||
|
{/* className='w-[20px] h-[20px] bg-white rounded-sm p-0.5'/> */}
|
||||||
|
{/* Youtube Caption */}
|
||||||
|
{/* </a> */}
|
||||||
|
{/* </li> */}
|
||||||
<li className='hover:bg-accent'>
|
<li className='hover:bg-accent'>
|
||||||
<a className='flex items-center' onClick={(e) => {
|
<a className='flex items-center' onClick={(e) => {
|
||||||
dispatch(setPage(PAGE_SETTINGS))
|
dispatch(setPage(PAGE_SETTINGS))
|
||||||
@@ -272,7 +297,7 @@ const MoreBtn = (props: Props) => {
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</Popover>}
|
</Popover>}
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|
||||||
export default MoreBtn
|
export default MoreBtn
|
||||||
|
@@ -5,16 +5,13 @@ import {getDisplay, getTransText} from '../util/biz_util'
|
|||||||
import classNames from 'classnames'
|
import classNames from 'classnames'
|
||||||
|
|
||||||
const NormalSegmentItem = (props: {
|
const NormalSegmentItem = (props: {
|
||||||
item: {
|
item: TranscriptItem
|
||||||
from: number
|
|
||||||
to: number
|
|
||||||
content: string
|
|
||||||
}
|
|
||||||
idx: number
|
idx: number
|
||||||
isIn: boolean
|
isIn: boolean
|
||||||
moveCallback: (event: any) => void
|
moveCallback: (event: any) => void
|
||||||
|
move2Callback: (event: any) => void
|
||||||
}) => {
|
}) => {
|
||||||
const {item, idx, isIn, moveCallback} = props
|
const {item, idx, isIn, moveCallback, move2Callback} = props
|
||||||
const transResult = useAppSelector(state => state.env.transResults[idx])
|
const transResult = useAppSelector(state => state.env.transResults[idx])
|
||||||
const envData = useAppSelector(state => state.env.envData)
|
const envData = useAppSelector(state => state.env.envData)
|
||||||
const fontSize = useAppSelector(state => state.env.envData.fontSize)
|
const fontSize = useAppSelector(state => state.env.envData.fontSize)
|
||||||
@@ -23,7 +20,7 @@ const NormalSegmentItem = (props: {
|
|||||||
const display = useMemo(() => getDisplay(envData.transDisplay, item.content, transText), [envData.transDisplay, item.content, transText])
|
const display = useMemo(() => getDisplay(envData.transDisplay, item.content, transText), [envData.transDisplay, item.content, transText])
|
||||||
|
|
||||||
return <div className={classNames('flex py-0.5 cursor-pointer rounded-sm hover:bg-base-200', fontSize === 'large'?'text-sm':'text-xs')}
|
return <div className={classNames('flex py-0.5 cursor-pointer rounded-sm hover:bg-base-200', fontSize === 'large'?'text-sm':'text-xs')}
|
||||||
onClick={moveCallback}>
|
onClick={moveCallback} onDoubleClick={move2Callback}>
|
||||||
<div className='desc w-[66px] flex justify-center'>{formatTime(item.from)}</div>
|
<div className='desc w-[66px] flex justify-center'>{formatTime(item.from)}</div>
|
||||||
<div className={'flex-1'}>
|
<div className={'flex-1'}>
|
||||||
<div className={classNames('font-medium', isIn ? 'text-primary underline' : '')}>{display.main}</div>
|
<div className={classNames('font-medium', isIn ? 'text-primary underline' : '')}>{display.main}</div>
|
||||||
|
@@ -46,7 +46,7 @@ const SummarizeItemOverview = (props: {
|
|||||||
if (event.altKey) { // 复制
|
if (event.altKey) { // 复制
|
||||||
navigator.clipboard.writeText(overviewItem.key).catch(console.error)
|
navigator.clipboard.writeText(overviewItem.key).catch(console.error)
|
||||||
} else {
|
} else {
|
||||||
move(time)
|
move(time, false)
|
||||||
}
|
}
|
||||||
}, [overviewItem.key, move, time])
|
}, [overviewItem.key, move, time])
|
||||||
|
|
||||||
@@ -66,19 +66,20 @@ const Summarize = (props: {
|
|||||||
const {segment, segmentIdx, summary, float} = props
|
const {segment, segmentIdx, summary, float} = props
|
||||||
|
|
||||||
const dispatch = useAppDispatch()
|
const dispatch = useAppDispatch()
|
||||||
const apiKey = useAppSelector(state => state.env.envData.apiKey)
|
const envData = useAppSelector(state => state.env.envData)
|
||||||
const fontSize = useAppSelector(state => state.env.envData.fontSize)
|
const fontSize = useAppSelector(state => state.env.envData.fontSize)
|
||||||
const curSummaryType = useAppSelector(state => state.env.tempData.curSummaryType)
|
const curSummaryType = useAppSelector(state => state.env.tempData.curSummaryType)
|
||||||
const {addSummarizeTask} = useTranslate()
|
const {addSummarizeTask} = useTranslate()
|
||||||
|
|
||||||
const onGenerate = useCallback(() => {
|
const onGenerate = useCallback(() => {
|
||||||
|
const apiKey = envData.aiType === 'gemini'?envData.geminiApiKey:envData.apiKey
|
||||||
if (apiKey) {
|
if (apiKey) {
|
||||||
addSummarizeTask(curSummaryType, segment).catch(console.error)
|
addSummarizeTask(curSummaryType, segment).catch(console.error)
|
||||||
} else {
|
} else {
|
||||||
dispatch(setPage(PAGE_SETTINGS))
|
dispatch(setPage(PAGE_SETTINGS))
|
||||||
toast.error('需要先设置ApiKey!')
|
toast.error('需要先设置ApiKey!')
|
||||||
}
|
}
|
||||||
}, [addSummarizeTask, apiKey, curSummaryType, dispatch, segment])
|
}, [addSummarizeTask, curSummaryType, dispatch, envData.aiType, envData.apiKey, envData.geminiApiKey, segment])
|
||||||
|
|
||||||
const onCopy = useCallback(() => {
|
const onCopy = useCallback(() => {
|
||||||
if (summary != null) {
|
if (summary != null) {
|
||||||
@@ -138,7 +139,7 @@ const SegmentCard = (props: {
|
|||||||
const summarizeFloat = useAppSelector(state => state.env.envData.summarizeFloat)
|
const summarizeFloat = useAppSelector(state => state.env.envData.summarizeFloat)
|
||||||
const fold = useAppSelector(state => state.env.fold)
|
const fold = useAppSelector(state => state.env.fold)
|
||||||
const page = useAppSelector(state => state.env.page)
|
const page = useAppSelector(state => state.env.page)
|
||||||
const compact = useAppSelector(state => state.env.compact)
|
const compact = useAppSelector(state => state.env.tempData.compact)
|
||||||
const floatKeyPointsSegIdx = useAppSelector(state => state.env.floatKeyPointsSegIdx)
|
const floatKeyPointsSegIdx = useAppSelector(state => state.env.floatKeyPointsSegIdx)
|
||||||
const showCurrent = useMemo(() => curIdx != null && segment.startIdx <= curIdx && curIdx <= segment.endIdx, [curIdx, segment.endIdx, segment.startIdx])
|
const showCurrent = useMemo(() => curIdx != null && segment.startIdx <= curIdx && curIdx <= segment.endIdx, [curIdx, segment.endIdx, segment.startIdx])
|
||||||
const curSummaryType = useAppSelector(state => state.env.tempData.curSummaryType)
|
const curSummaryType = useAppSelector(state => state.env.tempData.curSummaryType)
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import React, {useCallback, useEffect, useRef} from 'react'
|
import React, {useCallback, useEffect, useMemo, useRef} from 'react'
|
||||||
import {useAppDispatch, useAppSelector} from '../hooks/redux'
|
import {useAppDispatch, useAppSelector} from '../hooks/redux'
|
||||||
import useSubtitle from '../hooks/useSubtitle'
|
import useSubtitle from '../hooks/useSubtitle'
|
||||||
import {setCheckAutoScroll, setCurOffsetTop, setNeedScroll} from '../redux/envReducer'
|
import {setCheckAutoScroll, setCurOffsetTop, setNeedScroll} from '../redux/envReducer'
|
||||||
@@ -7,27 +7,41 @@ import CompactSegmentItem from './CompactSegmentItem'
|
|||||||
|
|
||||||
const SegmentItem = (props: {
|
const SegmentItem = (props: {
|
||||||
bodyRef: any
|
bodyRef: any
|
||||||
item: {
|
item: TranscriptItem
|
||||||
from: number
|
|
||||||
to: number
|
|
||||||
content: string
|
|
||||||
}
|
|
||||||
idx: number
|
idx: number
|
||||||
isIn: boolean
|
isIn: boolean
|
||||||
needScroll?: boolean
|
needScroll?: boolean
|
||||||
last: boolean
|
last: boolean
|
||||||
}) => {
|
}) => {
|
||||||
const dispatch = useAppDispatch()
|
|
||||||
const {bodyRef, item, idx, isIn, needScroll, last} = props
|
const {bodyRef, item, idx, isIn, needScroll, last} = props
|
||||||
|
const dispatch = useAppDispatch()
|
||||||
const ref = useRef<any>()
|
const ref = useRef<any>()
|
||||||
const {move} = useSubtitle()
|
const {move} = useSubtitle()
|
||||||
const compact = useAppSelector(state => state.env.compact)
|
|
||||||
|
const compact = useAppSelector(state => state.env.tempData.compact)
|
||||||
|
const searchText = useAppSelector(state => state.env.searchText)
|
||||||
|
const searchResult = useAppSelector(state => state.env.searchResult)
|
||||||
|
const display = useMemo(() => {
|
||||||
|
if (searchText) {
|
||||||
|
return searchResult.has(item.idx) ? 'inline' : 'none'
|
||||||
|
} else {
|
||||||
|
return 'inline'
|
||||||
|
}
|
||||||
|
}, [item.idx, searchResult, searchText])
|
||||||
|
|
||||||
const moveCallback = useCallback((event: any) => {
|
const moveCallback = useCallback((event: any) => {
|
||||||
if (event.altKey) { // 复制
|
if (event.altKey) { // 复制
|
||||||
navigator.clipboard.writeText(item.content).catch(console.error)
|
navigator.clipboard.writeText(item.content).catch(console.error)
|
||||||
} else {
|
} else {
|
||||||
move(item.from)
|
move(item.from, false)
|
||||||
|
}
|
||||||
|
}, [item.content, item.from, move])
|
||||||
|
|
||||||
|
const move2Callback = useCallback((event: any) => {
|
||||||
|
if (event.altKey) { // 复制
|
||||||
|
navigator.clipboard.writeText(item.content).catch(console.error)
|
||||||
|
} else {
|
||||||
|
move(item.from, true)
|
||||||
}
|
}
|
||||||
}, [item.content, item.from, move])
|
}, [item.content, item.from, move])
|
||||||
|
|
||||||
@@ -47,7 +61,9 @@ const SegmentItem = (props: {
|
|||||||
}
|
}
|
||||||
}, [dispatch, isIn])
|
}, [dispatch, isIn])
|
||||||
|
|
||||||
return <span ref={ref}>
|
return <span ref={ref} style={{
|
||||||
|
display
|
||||||
|
}}>
|
||||||
{compact
|
{compact
|
||||||
? <CompactSegmentItem
|
? <CompactSegmentItem
|
||||||
item={item}
|
item={item}
|
||||||
@@ -55,6 +71,7 @@ const SegmentItem = (props: {
|
|||||||
isIn={isIn}
|
isIn={isIn}
|
||||||
last={last}
|
last={last}
|
||||||
moveCallback={moveCallback}
|
moveCallback={moveCallback}
|
||||||
|
move2Callback={move2Callback}
|
||||||
/>
|
/>
|
||||||
:
|
:
|
||||||
<NormalSegmentItem
|
<NormalSegmentItem
|
||||||
@@ -62,6 +79,7 @@ const SegmentItem = (props: {
|
|||||||
idx={idx}
|
idx={idx}
|
||||||
isIn={isIn}
|
isIn={isIn}
|
||||||
moveCallback={moveCallback}
|
moveCallback={moveCallback}
|
||||||
|
move2Callback={move2Callback}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
</span>
|
</span>
|
||||||
|
@@ -2,23 +2,25 @@ import React, {PropsWithChildren, useCallback, useMemo, useState} from 'react'
|
|||||||
import {setEnvData, setPage} from '../redux/envReducer'
|
import {setEnvData, setPage} from '../redux/envReducer'
|
||||||
import {useAppDispatch, useAppSelector} from '../hooks/redux'
|
import {useAppDispatch, useAppSelector} from '../hooks/redux'
|
||||||
import {
|
import {
|
||||||
|
ASK_ENABLED_DEFAULT,
|
||||||
|
GEMINI_TOKENS,
|
||||||
HEADER_HEIGHT,
|
HEADER_HEIGHT,
|
||||||
LANGUAGE_DEFAULT,
|
LANGUAGE_DEFAULT,
|
||||||
LANGUAGES,
|
LANGUAGES,
|
||||||
MODEL_DEFAULT,
|
MODEL_DEFAULT,
|
||||||
|
MODEL_MAP,
|
||||||
MODELS,
|
MODELS,
|
||||||
PAGE_MAIN,
|
PAGE_MAIN,
|
||||||
PROMPT_DEFAULTS,
|
PROMPT_DEFAULTS,
|
||||||
PROMPT_TYPES,
|
PROMPT_TYPES,
|
||||||
SERVER_URL_THIRD,
|
|
||||||
SUMMARIZE_LANGUAGE_DEFAULT,
|
SUMMARIZE_LANGUAGE_DEFAULT,
|
||||||
TRANSLATE_FETCH_DEFAULT,
|
TRANSLATE_FETCH_DEFAULT,
|
||||||
TRANSLATE_FETCH_MAX,
|
TRANSLATE_FETCH_MAX,
|
||||||
TRANSLATE_FETCH_MIN,
|
TRANSLATE_FETCH_MIN,
|
||||||
TRANSLATE_FETCH_STEP,
|
TRANSLATE_FETCH_STEP,
|
||||||
WORDS_DEFAULT,
|
WORDS_RATE,
|
||||||
} from '../const'
|
} from '../const'
|
||||||
import {IoWarning} from 'react-icons/all'
|
import {FaGripfire, IoWarning} from 'react-icons/all'
|
||||||
import classNames from 'classnames'
|
import classNames from 'classnames'
|
||||||
import toast from 'react-hot-toast'
|
import toast from 'react-hot-toast'
|
||||||
import {useBoolean, useEventTarget} from 'ahooks'
|
import {useBoolean, useEventTarget} from 'ahooks'
|
||||||
@@ -58,17 +60,22 @@ const Settings = () => {
|
|||||||
// const {value: autoScrollValue, onChange: setAutoScrollValue} = useEventChecked(envData.autoScroll)
|
// const {value: autoScrollValue, onChange: setAutoScrollValue} = useEventChecked(envData.autoScroll)
|
||||||
const {value: translateEnableValue, onChange: setTranslateEnableValue} = useEventChecked(envData.translateEnable)
|
const {value: translateEnableValue, onChange: setTranslateEnableValue} = useEventChecked(envData.translateEnable)
|
||||||
const {value: summarizeEnableValue, onChange: setSummarizeEnableValue} = useEventChecked(envData.summarizeEnable)
|
const {value: summarizeEnableValue, onChange: setSummarizeEnableValue} = useEventChecked(envData.summarizeEnable)
|
||||||
|
const {value: searchEnabledValue, onChange: setSearchEnabledValue} = useEventChecked(envData.searchEnabled)
|
||||||
|
const {value: askEnabledValue, onChange: setAskEnabledValue} = useEventChecked(envData.askEnabled??ASK_ENABLED_DEFAULT)
|
||||||
|
const {value: cnSearchEnabledValue, onChange: setCnSearchEnabledValue} = useEventChecked(envData.cnSearchEnabled)
|
||||||
const {value: summarizeFloatValue, onChange: setSummarizeFloatValue} = useEventChecked(envData.summarizeFloat)
|
const {value: summarizeFloatValue, onChange: setSummarizeFloatValue} = useEventChecked(envData.summarizeFloat)
|
||||||
const [apiKeyValue, { onChange: onChangeApiKeyValue }] = useEventTarget({initialValue: envData.apiKey??''})
|
const [apiKeyValue, { onChange: onChangeApiKeyValue }] = useEventTarget({initialValue: envData.apiKey??''})
|
||||||
const [serverUrlValue, setServerUrlValue] = useState(envData.serverUrl)
|
const [serverUrlValue, setServerUrlValue] = useState(envData.serverUrl)
|
||||||
|
const [geminiApiKeyValue, { onChange: onChangeGeminiApiKeyValue }] = useEventTarget({initialValue: envData.geminiApiKey??''})
|
||||||
const [languageValue, { onChange: onChangeLanguageValue }] = useEventTarget({initialValue: envData.language??LANGUAGE_DEFAULT})
|
const [languageValue, { onChange: onChangeLanguageValue }] = useEventTarget({initialValue: envData.language??LANGUAGE_DEFAULT})
|
||||||
const [modelValue, { onChange: onChangeModelValue }] = useEventTarget({initialValue: envData.model??MODEL_DEFAULT})
|
const [modelValue, { onChange: onChangeModelValue }] = useEventTarget({initialValue: envData.model??MODEL_DEFAULT})
|
||||||
const [summarizeLanguageValue, { onChange: onChangeSummarizeLanguageValue }] = useEventTarget({initialValue: envData.summarizeLanguage??SUMMARIZE_LANGUAGE_DEFAULT})
|
const [summarizeLanguageValue, { onChange: onChangeSummarizeLanguageValue }] = useEventTarget({initialValue: envData.summarizeLanguage??SUMMARIZE_LANGUAGE_DEFAULT})
|
||||||
const [hideOnDisableAutoTranslateValue, setHideOnDisableAutoTranslateValue] = useState(envData.hideOnDisableAutoTranslate)
|
const [hideOnDisableAutoTranslateValue, setHideOnDisableAutoTranslateValue] = useState(envData.hideOnDisableAutoTranslate)
|
||||||
const [themeValue, setThemeValue] = useState(envData.theme)
|
const [themeValue, setThemeValue] = useState(envData.theme)
|
||||||
const [fontSizeValue, setFontSizeValue] = useState(envData.fontSize)
|
const [fontSizeValue, setFontSizeValue] = useState(envData.fontSize)
|
||||||
|
const [aiTypeValue, setAiTypeValue] = useState(envData.aiType)
|
||||||
const [transDisplayValue, setTransDisplayValue] = useState(envData.transDisplay)
|
const [transDisplayValue, setTransDisplayValue] = useState(envData.transDisplay)
|
||||||
const [wordsValue, setWordsValue] = useState<number | undefined>(envData.words??WORDS_DEFAULT)
|
const [wordsValue, setWordsValue] = useState<number | undefined>(envData.words)
|
||||||
const [fetchAmountValue, setFetchAmountValue] = useState(envData.fetchAmount??TRANSLATE_FETCH_DEFAULT)
|
const [fetchAmountValue, setFetchAmountValue] = useState(envData.fetchAmount??TRANSLATE_FETCH_DEFAULT)
|
||||||
const [moreFold, {toggle: toggleMoreFold}] = useBoolean(true)
|
const [moreFold, {toggle: toggleMoreFold}] = useBoolean(true)
|
||||||
const [promptsFold, {toggle: togglePromptsFold}] = useBoolean(true)
|
const [promptsFold, {toggle: togglePromptsFold}] = useBoolean(true)
|
||||||
@@ -89,6 +96,12 @@ const Settings = () => {
|
|||||||
}
|
}
|
||||||
return list
|
return list
|
||||||
}, [])
|
}, [])
|
||||||
|
const apiKeySetted = useMemo(() => {
|
||||||
|
if (aiTypeValue === 'gemini') {
|
||||||
|
return !!geminiApiKeyValue
|
||||||
|
}
|
||||||
|
return !!apiKeyValue
|
||||||
|
}, [aiTypeValue, apiKeyValue, geminiApiKeyValue])
|
||||||
|
|
||||||
const onChangeHideOnDisableAutoTranslate = useCallback((e: any) => {
|
const onChangeHideOnDisableAutoTranslate = useCallback((e: any) => {
|
||||||
setHideOnDisableAutoTranslateValue(e.target.checked)
|
setHideOnDisableAutoTranslateValue(e.target.checked)
|
||||||
@@ -97,9 +110,11 @@ const Settings = () => {
|
|||||||
const onSave = useCallback(() => {
|
const onSave = useCallback(() => {
|
||||||
dispatch(setEnvData({
|
dispatch(setEnvData({
|
||||||
autoExpand: autoExpandValue,
|
autoExpand: autoExpandValue,
|
||||||
|
aiType: aiTypeValue,
|
||||||
apiKey: apiKeyValue,
|
apiKey: apiKeyValue,
|
||||||
serverUrl: serverUrlValue,
|
serverUrl: serverUrlValue,
|
||||||
model: modelValue,
|
model: modelValue,
|
||||||
|
geminiApiKey: geminiApiKeyValue,
|
||||||
translateEnable: translateEnableValue,
|
translateEnable: translateEnableValue,
|
||||||
language: languageValue,
|
language: languageValue,
|
||||||
hideOnDisableAutoTranslate: hideOnDisableAutoTranslateValue,
|
hideOnDisableAutoTranslate: hideOnDisableAutoTranslateValue,
|
||||||
@@ -112,10 +127,13 @@ const Settings = () => {
|
|||||||
fetchAmount: fetchAmountValue,
|
fetchAmount: fetchAmountValue,
|
||||||
fontSize: fontSizeValue,
|
fontSize: fontSizeValue,
|
||||||
prompts: promptsValue,
|
prompts: promptsValue,
|
||||||
|
searchEnabled: searchEnabledValue,
|
||||||
|
cnSearchEnabled: cnSearchEnabledValue,
|
||||||
|
askEnabled: askEnabledValue,
|
||||||
}))
|
}))
|
||||||
dispatch(setPage(PAGE_MAIN))
|
dispatch(setPage(PAGE_MAIN))
|
||||||
toast.success('保存成功')
|
toast.success('保存成功')
|
||||||
}, [modelValue, promptsValue, fontSizeValue, apiKeyValue, autoExpandValue, dispatch, fetchAmountValue, hideOnDisableAutoTranslateValue, languageValue, serverUrlValue, summarizeEnableValue, summarizeFloatValue, summarizeLanguageValue, themeValue, transDisplayValue, translateEnableValue, wordsValue])
|
}, [dispatch, autoExpandValue, aiTypeValue, apiKeyValue, serverUrlValue, modelValue, geminiApiKeyValue, translateEnableValue, languageValue, hideOnDisableAutoTranslateValue, themeValue, transDisplayValue, summarizeEnableValue, summarizeFloatValue, summarizeLanguageValue, wordsValue, fetchAmountValue, fontSizeValue, promptsValue, searchEnabledValue, cnSearchEnabledValue, askEnabledValue])
|
||||||
|
|
||||||
const onCancel = useCallback(() => {
|
const onCancel = useCallback(() => {
|
||||||
dispatch(setPage(PAGE_MAIN))
|
dispatch(setPage(PAGE_MAIN))
|
||||||
@@ -161,6 +179,14 @@ const Settings = () => {
|
|||||||
setFontSizeValue('large')
|
setFontSizeValue('large')
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
const onSelOpenai = useCallback(() => {
|
||||||
|
setAiTypeValue('openai')
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const onSelGemini = useCallback(() => {
|
||||||
|
setAiTypeValue('gemini')
|
||||||
|
}, [])
|
||||||
|
|
||||||
return <div className='text-sm overflow-y-auto' style={{
|
return <div className='text-sm overflow-y-auto' style={{
|
||||||
height: fold?undefined:`${totalHeight-HEADER_HEIGHT}px`,
|
height: fold?undefined:`${totalHeight-HEADER_HEIGHT}px`,
|
||||||
}}>
|
}}>
|
||||||
@@ -183,38 +209,51 @@ const Settings = () => {
|
|||||||
<button onClick={onSelFontSize2} className={classNames('btn btn-xs no-animation', fontSizeValue === 'large'?'btn-active':'')}>加大</button>
|
<button onClick={onSelFontSize2} className={classNames('btn btn-xs no-animation', fontSizeValue === 'large'?'btn-active':'')}>加大</button>
|
||||||
</div>
|
</div>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
<FormItem title='AI类型' tip='OPENAI质量更高'>
|
||||||
|
<div className="btn-group">
|
||||||
|
<button onClick={onSelOpenai} className={classNames('btn btn-xs no-animation', (!aiTypeValue || aiTypeValue === 'openai')?'btn-active':'')}>OpenAI</button>
|
||||||
|
<button onClick={onSelGemini} className={classNames('btn btn-xs no-animation', aiTypeValue === 'gemini'?'btn-active':'')}>Gemini</button>
|
||||||
|
</div>
|
||||||
|
</FormItem>
|
||||||
</Section>
|
</Section>
|
||||||
<Section title='openai配置'>
|
|
||||||
|
{(!aiTypeValue || aiTypeValue === 'openai') && <Section title='openai配置'>
|
||||||
<FormItem title='ApiKey' htmlFor='apiKey'>
|
<FormItem title='ApiKey' htmlFor='apiKey'>
|
||||||
<input id='apiKey' type='text' className='input input-sm input-bordered w-full' placeholder='sk-xxx' value={apiKeyValue} onChange={onChangeApiKeyValue}/>
|
<input id='apiKey' type='text' className='input input-sm input-bordered w-full' placeholder='sk-xxx'
|
||||||
|
value={apiKeyValue} onChange={onChangeApiKeyValue}/>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
<FormItem title='服务器' htmlFor='serverUrl'>
|
<FormItem title='服务器' htmlFor='serverUrl'>
|
||||||
<input id='serverUrl' type='text' className='input input-sm input-bordered w-full' placeholder='服务器地址,默认使用官方地址' value={serverUrlValue} onChange={e => setServerUrlValue(e.target.value)}/>
|
<input id='serverUrl' type='text' className='input input-sm input-bordered w-full'
|
||||||
|
placeholder='默认使用官方地址' value={serverUrlValue}
|
||||||
|
onChange={e => setServerUrlValue(e.target.value)}/>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
<div className='flex justify-center'>
|
<div>
|
||||||
<a className='link text-xs' onClick={toggleMoreFold}>{moreFold?'点击查看说明':'点击折叠说明'}</a>
|
<div className='desc text-xs text-center'>
|
||||||
|
<div className='flex justify-center font-semibold'>【官方地址】</div>
|
||||||
|
<div>官方网址:<a className='link link-primary' href='https://platform.openai.com/' target='_blank'
|
||||||
|
rel="noreferrer">点击访问</a></div>
|
||||||
|
<div>服务器地址:<a className='link link-primary'
|
||||||
|
onClick={() => setServerUrlValue('https://api.openai.com')}
|
||||||
|
rel='noreferrer'>点击设置</a></div>
|
||||||
|
<div className='flex justify-center font-semibold'>【第三方代理】</div>
|
||||||
|
<div>代理网址:<a className='link link-primary' href='https://api.openai-up.com/register?aff=varM'
|
||||||
|
target='_blank'
|
||||||
|
rel="noreferrer">点击访问</a></div>
|
||||||
|
<div>服务器地址:<a className='link link-primary'
|
||||||
|
onClick={() => setServerUrlValue('https://api.openai-up.com')}
|
||||||
|
rel='noreferrer'>点击设置</a></div>
|
||||||
|
<div className='text-amber-600 flex justify-center items-center'><FaGripfire/>目前价格不到官方价格的6折<FaGripfire/></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{!moreFold && <div>
|
<FormItem title='模型选择' htmlFor='modelSel' tip='注意,不同模型有不同价格与token限制'>
|
||||||
<ul className='pl-3 list-decimal desc text-xs'>
|
<select id='modelSel' className="select select-sm select-bordered" value={modelValue}
|
||||||
<li>官方服务器需要科学上网才能访问</li>
|
onChange={onChangeModelValue}>
|
||||||
<li>官方网址:<a className='link' href='https://platform.openai.com/' target='_blank' rel="noreferrer">openai.com</a></li>
|
|
||||||
<li>支持官方代理(使用官方ApiKey):<a className='link' onClick={() => setServerUrlValue(SERVER_URL_THIRD)} rel='noreferrer'>点击设置</a></li>
|
|
||||||
<li>支持代理(配合ApiKey):<a className='link' href='https://api2d.com/' target='_blank' rel="noreferrer">api2d</a> | <a className='link' onClick={() => setServerUrlValue('https://openai.api2d.net')} rel='noreferrer'>点击设置</a></li>
|
|
||||||
<li>支持代理(配合ApiKey):<a className='link' href='https://openaimax.com/' target='_blank' rel="noreferrer">OpenAI-Max</a> | <a className='link' onClick={() => setServerUrlValue('https://api.openaimax.com')} rel='noreferrer'>点击设置</a></li>
|
|
||||||
<li>支持代理(配合ApiKey):<a className='link' href='https://openai-sb.com/' target='_blank' rel="noreferrer">OpenAI-SB</a> | <a className='link' onClick={() => setServerUrlValue('https://api.openai-sb.com')} rel='noreferrer'>点击设置</a></li>
|
|
||||||
<li>支持代理(配合ApiKey):<a className='link' href='https://www.ohmygpt.com/' target='_blank' rel="noreferrer">OhMyGPT</a> | <a className='link' onClick={() => setServerUrlValue('https://api.ohmygpt.com')} rel='noreferrer'>点击设置</a></li>
|
|
||||||
<li>支持代理(配合ApiKey):<a className='link' href='https://aiproxy.io/' target='_blank' rel="noreferrer">AIProxy</a> | <a className='link' onClick={() => setServerUrlValue('https://api.aiproxy.io')} rel='noreferrer'>点击设置</a></li>
|
|
||||||
<li>支持代理(配合ApiKey):<a className='link' href='https://key-rental.bowen.cool/' target='_blank' rel="noreferrer">Key Rental</a> | <a className='link' onClick={() => setServerUrlValue('https://key-rental-api.bowen.cool/openai')} rel='noreferrer'>点击设置</a></li>
|
|
||||||
<li>支持其他第三方代理,有问题可加群交流</li>
|
|
||||||
</ul>
|
|
||||||
</div>}
|
|
||||||
<FormItem title='模型选择' htmlFor='modelSel' tip='注意,不同模型有不同价格'>
|
|
||||||
<select id='modelSel' className="select select-sm select-bordered" value={modelValue} onChange={onChangeModelValue}>
|
|
||||||
{MODELS.map(model => <option key={model.code} value={model.code}>{model.name}</option>)}
|
{MODELS.map(model => <option key={model.code} value={model.code}>{model.name}</option>)}
|
||||||
</select>
|
</select>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
<div className='flex justify-center'>
|
<div className='flex justify-center'>
|
||||||
<a className='link text-xs' onClick={togglePromptsFold}>{promptsFold?'点击查看提示词':'点击折叠提示词'}</a>
|
<a className='link text-xs'
|
||||||
|
onClick={togglePromptsFold}>{promptsFold ? '点击查看提示词' : '点击折叠提示词'}</a>
|
||||||
</div>
|
</div>
|
||||||
{!promptsFold && <div>
|
{!promptsFold && <div>
|
||||||
{PROMPT_TYPES.map((item, idx) => <FormItem key={item.type} title={<div>
|
{PROMPT_TYPES.map((item, idx) => <FormItem key={item.type} title={<div>
|
||||||
@@ -223,22 +262,65 @@ const Settings = () => {
|
|||||||
setPromptsValue({
|
setPromptsValue({
|
||||||
...promptsValue,
|
...promptsValue,
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
[item.type]: PROMPT_DEFAULTS[item.type]??''
|
[item.type]: PROMPT_DEFAULTS[item.type] ?? ''
|
||||||
})
|
})
|
||||||
}}>点击填充默认</div>
|
}}>点击填充默认
|
||||||
|
</div>
|
||||||
</div>} htmlFor={`prompt-${item.type}`}>
|
</div>} htmlFor={`prompt-${item.type}`}>
|
||||||
<textarea id={`prompt-${item.type}`} className='mt-2 textarea input-bordered w-full' placeholder='留空使用默认提示词' value={promptsValue[item.type]??''} onChange={(e) => {
|
<textarea id={`prompt-${item.type}`} className='mt-2 textarea input-bordered w-full'
|
||||||
setPromptsValue({
|
placeholder='留空使用默认提示词' value={promptsValue[item.type] ?? ''} onChange={(e) => {
|
||||||
...promptsValue,
|
setPromptsValue({
|
||||||
[item.type]: e.target.value
|
...promptsValue,
|
||||||
})
|
[item.type]: e.target.value
|
||||||
}}/>
|
})
|
||||||
|
}}/>
|
||||||
</FormItem>)}
|
</FormItem>)}
|
||||||
</div>}
|
</div>}
|
||||||
</Section>
|
</Section>}
|
||||||
|
|
||||||
|
{aiTypeValue === 'gemini' && <Section title='gemini配置'>
|
||||||
|
<FormItem title='ApiKey' htmlFor='geminiApiKey'>
|
||||||
|
<input id='geminiApiKey' type='text' className='input input-sm input-bordered w-full' placeholder='xxx'
|
||||||
|
value={geminiApiKeyValue} onChange={onChangeGeminiApiKeyValue}/>
|
||||||
|
</FormItem>
|
||||||
|
<div>
|
||||||
|
<div className='desc text-xs'>
|
||||||
|
<div>官方网址:<a className='link link-primary' href='https://makersuite.google.com/app/apikey' target='_blank'
|
||||||
|
rel="noreferrer">Google AI Studio</a> (目前免费)
|
||||||
|
</div>
|
||||||
|
<div className='text-xs text-error flex items-center'><IoWarning className='text-sm text-warning'/>谷歌模型安全要求比较高,有些视频可能无法生成总结!</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className='flex justify-center'>
|
||||||
|
<a className='link text-xs'
|
||||||
|
onClick={togglePromptsFold}>{promptsFold ? '点击查看提示词' : '点击折叠提示词'}</a>
|
||||||
|
</div>
|
||||||
|
{!promptsFold && <div>
|
||||||
|
{PROMPT_TYPES.map((item, idx) => <FormItem key={item.type} title={<div>
|
||||||
|
<div>{item.name}</div>
|
||||||
|
<div className='link text-xs' onClick={() => {
|
||||||
|
setPromptsValue({
|
||||||
|
...promptsValue,
|
||||||
|
// @ts-expect-error
|
||||||
|
[item.type]: PROMPT_DEFAULTS[item.type] ?? ''
|
||||||
|
})
|
||||||
|
}}>点击填充默认
|
||||||
|
</div>
|
||||||
|
</div>} htmlFor={`prompt-${item.type}`}>
|
||||||
|
<textarea id={`prompt-${item.type}`} className='mt-2 textarea input-bordered w-full'
|
||||||
|
placeholder='留空使用默认提示词' value={promptsValue[item.type] ?? ''} onChange={(e) => {
|
||||||
|
setPromptsValue({
|
||||||
|
...promptsValue,
|
||||||
|
[item.type]: e.target.value
|
||||||
|
})
|
||||||
|
}}/>
|
||||||
|
</FormItem>)}
|
||||||
|
</div>}
|
||||||
|
</Section>}
|
||||||
|
|
||||||
<Section title={<div className='flex items-center'>
|
<Section title={<div className='flex items-center'>
|
||||||
翻译配置
|
翻译配置
|
||||||
{!apiKeyValue && <div className='tooltip tooltip-right ml-1' data-tip='未设置ApiKey无法使用'>
|
{!apiKeySetted && <div className='tooltip tooltip-right ml-1' data-tip='未设置ApiKey无法使用'>
|
||||||
<IoWarning className='text-sm text-warning'/>
|
<IoWarning className='text-sm text-warning'/>
|
||||||
</div>}
|
</div>}
|
||||||
</div>}>
|
</div>}>
|
||||||
@@ -273,7 +355,7 @@ const Settings = () => {
|
|||||||
</Section>
|
</Section>
|
||||||
<Section title={<div className='flex items-center'>
|
<Section title={<div className='flex items-center'>
|
||||||
总结配置
|
总结配置
|
||||||
{!apiKeyValue && <div className='tooltip tooltip-right ml-1' data-tip='未设置ApiKey无法使用'>
|
{!apiKeySetted && <div className='tooltip tooltip-right ml-1' data-tip='未设置ApiKey无法使用'>
|
||||||
<IoWarning className='text-sm text-warning'/>
|
<IoWarning className='text-sm text-warning'/>
|
||||||
</div>}
|
</div>}
|
||||||
</div>}>
|
</div>}>
|
||||||
@@ -292,13 +374,37 @@ const Settings = () => {
|
|||||||
</FormItem>
|
</FormItem>
|
||||||
<FormItem htmlFor='words' title='分段字数' tip='注意,不同模型有不同字数限制'>
|
<FormItem htmlFor='words' title='分段字数' tip='注意,不同模型有不同字数限制'>
|
||||||
<div className='flex-1 flex flex-col'>
|
<div className='flex-1 flex flex-col'>
|
||||||
<input id='words' type='number' className='input input-sm input-bordered w-full' placeholder='默认2000' value={wordsValue} onChange={e => setWordsValue(e.target.value?parseInt(e.target.value):undefined)}/>
|
<input id='words' type='number' className='input input-sm input-bordered w-full' placeholder={`默认为上限x${WORDS_RATE}`} value={wordsValue??''} onChange={e => setWordsValue(e.target.value?parseInt(e.target.value):undefined)}/>
|
||||||
{/* <input type="range" min={WORDS_MIN} max={WORDS_MAX} step={WORDS_STEP} value={wordsValue} className="range range-primary" onChange={onWordsChange} /> */}
|
{/* <input type="range" min={WORDS_MIN} max={WORDS_MAX} step={WORDS_STEP} value={wordsValue} className="range range-primary" onChange={onWordsChange} /> */}
|
||||||
{/* <div className="w-full flex justify-between text-xs px-2"> */}
|
{/* <div className="w-full flex justify-between text-xs px-2"> */}
|
||||||
{/* {wordsList.map(words => <span key={words}>{words}</span>)} */}
|
{/* {wordsList.map(words => <span key={words}>{words}</span>)} */}
|
||||||
{/* </div> */}
|
{/* </div> */}
|
||||||
</div>
|
</div>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
<div className='desc text-xs'>
|
||||||
|
当前选择的模型的分段字数上限是<span className='font-semibold font-mono'>{aiTypeValue === 'gemini'?GEMINI_TOKENS:(MODEL_MAP[modelValue??MODEL_DEFAULT]?.tokens??'未知')}</span>
|
||||||
|
(太接近上限总结会报错)
|
||||||
|
</div>
|
||||||
|
</Section>
|
||||||
|
<Section title={<div className='flex items-center'>
|
||||||
|
搜索配置
|
||||||
|
</div>}>
|
||||||
|
<FormItem title='启用搜索' htmlFor='searchEnabled' tip='是否启用字幕搜索功能'>
|
||||||
|
<input id='searchEnabled' type='checkbox' className='toggle toggle-primary' checked={searchEnabledValue}
|
||||||
|
onChange={setSearchEnabledValue}/>
|
||||||
|
</FormItem>
|
||||||
|
<FormItem title='拼音搜索' htmlFor='cnSearchEnabled' tip='是否启用中文拼音搜索'>
|
||||||
|
<input id='cnSearchEnabled' type='checkbox' className='toggle toggle-primary' checked={cnSearchEnabledValue}
|
||||||
|
onChange={setCnSearchEnabledValue}/>
|
||||||
|
</FormItem>
|
||||||
|
</Section>
|
||||||
|
<Section title={<div className='flex items-center'>
|
||||||
|
提问配置
|
||||||
|
</div>}>
|
||||||
|
<FormItem title='启用提问' htmlFor='askEnabled' tip='是否启用字幕提问功能'>
|
||||||
|
<input id='askEnabled' type='checkbox' className='toggle toggle-primary' checked={askEnabledValue}
|
||||||
|
onChange={setAskEnabledValue}/>
|
||||||
|
</FormItem>
|
||||||
</Section>
|
</Section>
|
||||||
<div className='flex justify-center gap-5'>
|
<div className='flex justify-center gap-5'>
|
||||||
<button className='btn btn-primary btn-sm' onClick={onSave}>保存</button>
|
<button className='btn btn-primary btn-sm' onClick={onSave}>保存</button>
|
||||||
|
@@ -102,6 +102,7 @@ const refreshVideoInfo = async () => {
|
|||||||
//send setVideoInfo
|
//send setVideoInfo
|
||||||
iframe.contentWindow.postMessage({
|
iframe.contentWindow.postMessage({
|
||||||
type: 'setVideoInfo',
|
type: 'setVideoInfo',
|
||||||
|
url: location.origin + location.pathname,
|
||||||
title,
|
title,
|
||||||
aid,
|
aid,
|
||||||
pages,
|
pages,
|
||||||
@@ -157,6 +158,9 @@ window.addEventListener("message", (event) => {
|
|||||||
const video = getVideoElement()
|
const video = getVideoElement()
|
||||||
if (video) {
|
if (video) {
|
||||||
video.currentTime = data.time
|
video.currentTime = data.time
|
||||||
|
if (data.togglePause) {
|
||||||
|
video.paused ? video.play() : video.pause()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,4 +1,12 @@
|
|||||||
import {getServerUrl} from '../util/biz_util'
|
const getServerUrl = (serverUrl?: string) => {
|
||||||
|
if (!serverUrl) {
|
||||||
|
return 'https://api.openai.com'
|
||||||
|
}
|
||||||
|
if (serverUrl.endsWith('/')) {
|
||||||
|
serverUrl = serverUrl.slice(0, -1)
|
||||||
|
}
|
||||||
|
return serverUrl
|
||||||
|
}
|
||||||
|
|
||||||
export const handleChatCompleteTask = async (task: Task) => {
|
export const handleChatCompleteTask = async (task: Task) => {
|
||||||
const data = task.def.data
|
const data = task.def.data
|
||||||
@@ -18,3 +26,16 @@ export const handleChatCompleteTask = async (task: Task) => {
|
|||||||
throw new Error(`${task.resp.error.code as string??''} ${task.resp.error.message as string ??''}`)
|
throw new Error(`${task.resp.error.code as string??''} ${task.resp.error.message as string ??''}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const handleGeminiChatCompleteTask = async (task: Task) => {
|
||||||
|
const data = task.def.data
|
||||||
|
const resp = await fetch('https://generativelanguage.googleapis.com/v1/models/gemini-pro:generateContent', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'x-goog-api-key': task.def.extra.geminiApiKey,
|
||||||
|
},
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
})
|
||||||
|
task.resp = await resp.json()
|
||||||
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import {TASK_EXPIRE_TIME} from '../const'
|
import {TASK_EXPIRE_TIME} from '../const'
|
||||||
import {handleChatCompleteTask} from './openaiService'
|
import {handleChatCompleteTask, handleGeminiChatCompleteTask} from './openaiService'
|
||||||
|
|
||||||
export const tasksMap = new Map<string, Task>()
|
export const tasksMap = new Map<string, Task>()
|
||||||
|
|
||||||
@@ -11,6 +11,9 @@ export const handleTask = async (task: Task) => {
|
|||||||
case 'chatComplete':
|
case 'chatComplete':
|
||||||
await handleChatCompleteTask(task)
|
await handleChatCompleteTask(task)
|
||||||
break
|
break
|
||||||
|
case 'geminiChatComplete':
|
||||||
|
await handleGeminiChatCompleteTask(task)
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||||
throw new Error(`任务类型不支持: ${task.def.type}`)
|
throw new Error(`任务类型不支持: ${task.def.type}`)
|
||||||
|
46
src/components/Markdown.tsx
Normal file
46
src/components/Markdown.tsx
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import classNames from 'classnames'
|
||||||
|
import ReactMarkdown from 'react-markdown'
|
||||||
|
import toast from 'react-hot-toast'
|
||||||
|
|
||||||
|
function CopyBtn(props: {
|
||||||
|
content: string
|
||||||
|
}) {
|
||||||
|
const {content} = props
|
||||||
|
return <div className='flex justify-center mt-1'>
|
||||||
|
<button className="btn btn-xs px-10 btn-primary normal-case" onClick={() => {
|
||||||
|
navigator.clipboard.writeText(content).then(() => {
|
||||||
|
toast.success('Copied!')
|
||||||
|
}).catch(console.error)
|
||||||
|
}}>Copy
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
function Markdown(props: {
|
||||||
|
content: string
|
||||||
|
codeBlockClass?: string
|
||||||
|
}) {
|
||||||
|
const {content, codeBlockClass} = props
|
||||||
|
|
||||||
|
return <ReactMarkdown
|
||||||
|
className='markdown prose prose-sm dark:prose-invert prose-h1:text-center prose-h1:font-bold prose-h1:underline-offset-4 overflow-y-auto scrollbar-hide'
|
||||||
|
linkTarget={'_blank'}
|
||||||
|
components={{
|
||||||
|
code({node, inline, className, children, ...props}) {
|
||||||
|
if (inline) {
|
||||||
|
return <code
|
||||||
|
className={classNames(className, 'md-inline-block kbd kbd-xs rounded text-base-content/80')} {...props}>
|
||||||
|
{children}
|
||||||
|
</code>
|
||||||
|
} else {
|
||||||
|
return <code className={classNames(className, 'relative', codeBlockClass)} {...props}>
|
||||||
|
{children}
|
||||||
|
{className?.includes('language-copy') && <CopyBtn content={children[0] as string}/>}
|
||||||
|
</code>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>{content}</ReactMarkdown>
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Markdown
|
@@ -9,6 +9,7 @@ export const PROMPT_TYPE_TRANSLATE = 'translate'
|
|||||||
export const PROMPT_TYPE_SUMMARIZE_OVERVIEW = 'summarize_overview'
|
export const PROMPT_TYPE_SUMMARIZE_OVERVIEW = 'summarize_overview'
|
||||||
export const PROMPT_TYPE_SUMMARIZE_KEYPOINT = 'summarize_keypoint'
|
export const PROMPT_TYPE_SUMMARIZE_KEYPOINT = 'summarize_keypoint'
|
||||||
export const PROMPT_TYPE_SUMMARIZE_BRIEF = 'summarize_brief'
|
export const PROMPT_TYPE_SUMMARIZE_BRIEF = 'summarize_brief'
|
||||||
|
export const PROMPT_TYPE_ASK = 'ask'
|
||||||
export const PROMPT_TYPES = [{
|
export const PROMPT_TYPES = [{
|
||||||
name: '翻译',
|
name: '翻译',
|
||||||
type: PROMPT_TYPE_TRANSLATE,
|
type: PROMPT_TYPE_TRANSLATE,
|
||||||
@@ -21,6 +22,9 @@ export const PROMPT_TYPES = [{
|
|||||||
}, {
|
}, {
|
||||||
name: '总结',
|
name: '总结',
|
||||||
type: PROMPT_TYPE_SUMMARIZE_BRIEF,
|
type: PROMPT_TYPE_SUMMARIZE_BRIEF,
|
||||||
|
}, {
|
||||||
|
name: '提问',
|
||||||
|
type: PROMPT_TYPE_ASK,
|
||||||
}]
|
}]
|
||||||
|
|
||||||
export const SUMMARIZE_TYPES = {
|
export const SUMMARIZE_TYPES = {
|
||||||
@@ -119,7 +123,20 @@ The video's subtitles:
|
|||||||
|
|
||||||
'''
|
'''
|
||||||
{{segment}}
|
{{segment}}
|
||||||
'''`
|
'''`,
|
||||||
|
[PROMPT_TYPE_ASK]: `You are a helpful assistant who answers question related to video subtitles.
|
||||||
|
Answer in language '{{language}}'.
|
||||||
|
|
||||||
|
The video's title: '''{{title}}'''.
|
||||||
|
The video's subtitles:
|
||||||
|
|
||||||
|
'''
|
||||||
|
{{segment}}
|
||||||
|
'''
|
||||||
|
|
||||||
|
Question: '''{{question}}'''
|
||||||
|
Answer:
|
||||||
|
`,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const EVENT_EXPAND = 'expand'
|
export const EVENT_EXPAND = 'expand'
|
||||||
@@ -141,26 +158,38 @@ export const TOTAL_HEIGHT_DEF = 520
|
|||||||
export const TOTAL_HEIGHT_MAX = 800
|
export const TOTAL_HEIGHT_MAX = 800
|
||||||
export const HEADER_HEIGHT = 44
|
export const HEADER_HEIGHT = 44
|
||||||
export const TITLE_HEIGHT = 24
|
export const TITLE_HEIGHT = 24
|
||||||
|
export const SEARCH_BAR_HEIGHT = 32
|
||||||
|
export const RECOMMEND_HEIGHT = 36
|
||||||
|
|
||||||
export const WORDS_DEFAULT = import.meta.env.VITE_ENV === 'web-dev'?500:2000
|
export const WORDS_RATE = 0.75
|
||||||
export const WORDS_MIN = 500
|
export const WORDS_MIN = 500
|
||||||
export const WORDS_MAX = 16000
|
export const WORDS_MAX = 16000
|
||||||
export const WORDS_STEP = 500
|
export const WORDS_STEP = 500
|
||||||
export const SUMMARIZE_THRESHOLD = 100
|
export const SUMMARIZE_THRESHOLD = 100
|
||||||
export const SUMMARIZE_LANGUAGE_DEFAULT = 'cn'
|
export const SUMMARIZE_LANGUAGE_DEFAULT = 'cn'
|
||||||
export const SUMMARIZE_ALL_THRESHOLD = 5
|
export const SUMMARIZE_ALL_THRESHOLD = 5
|
||||||
|
export const ASK_ENABLED_DEFAULT = true
|
||||||
export const SERVER_URL_OPENAI = 'https://api.openai.com'
|
export const SERVER_URL_OPENAI = 'https://api.openai.com'
|
||||||
export const SERVER_URL_THIRD = 'https://op.kongkongye.com'
|
|
||||||
|
|
||||||
export const MODELS = [{
|
export const MODELS = [{
|
||||||
code: 'gpt-3.5-turbo',
|
code: 'gpt-3.5-turbo',
|
||||||
name: 'gpt-3.5-turbo',
|
name: 'gpt-3.5-turbo',
|
||||||
|
tokens: 4096,
|
||||||
}, {
|
}, {
|
||||||
code: 'gpt-3.5-turbo-16k',
|
code: 'gpt-3.5-turbo-0125',
|
||||||
name: 'gpt-3.5-turbo-16k',
|
name: 'gpt-3.5-turbo-0125',
|
||||||
|
tokens: 16385,
|
||||||
|
}, {
|
||||||
|
code: 'gpt-3.5-turbo-1106',
|
||||||
|
name: 'gpt-3.5-turbo-1106',
|
||||||
|
tokens: 16385,
|
||||||
}]
|
}]
|
||||||
export const MODEL_DEFAULT = MODELS[0].code
|
export const GEMINI_TOKENS = 32768
|
||||||
|
export const MODEL_DEFAULT = MODELS[1].code
|
||||||
|
export const MODEL_MAP: {[key: string]: typeof MODELS[number]} = {}
|
||||||
|
for (const model of MODELS) {
|
||||||
|
MODEL_MAP[model.code] = model
|
||||||
|
}
|
||||||
|
|
||||||
export const LANGUAGES = [{
|
export const LANGUAGES = [{
|
||||||
code: 'en',
|
code: 'en',
|
||||||
|
59
src/hooks/useKeyService.ts
Normal file
59
src/hooks/useKeyService.ts
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import {useEffect} from 'react'
|
||||||
|
import {useMemoizedFn} from 'ahooks/es'
|
||||||
|
import {useAppSelector} from './redux'
|
||||||
|
import useSubtitle from './useSubtitle'
|
||||||
|
|
||||||
|
const useKeyService = () => {
|
||||||
|
const curIdx = useAppSelector(state => state.env.curIdx)
|
||||||
|
const data = useAppSelector(state => state.env.data)
|
||||||
|
const {move} = useSubtitle()
|
||||||
|
|
||||||
|
const onKeyDown = useMemoizedFn((e: KeyboardEvent) => {
|
||||||
|
// 有按其他控制键时,不触发
|
||||||
|
if (e.ctrlKey || e.metaKey || e.shiftKey) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let cursorInInput = false
|
||||||
|
if (document.activeElement != null) {
|
||||||
|
const tagName = document.activeElement.tagName
|
||||||
|
if (tagName === 'INPUT' || tagName === 'TEXTAREA') {
|
||||||
|
cursorInInput = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let prevent = false
|
||||||
|
|
||||||
|
// up arrow
|
||||||
|
if (e.key === 'ArrowUp') {
|
||||||
|
if (curIdx && (data != null) && !cursorInInput) {
|
||||||
|
prevent = true
|
||||||
|
const newCurIdx = Math.max(curIdx - 1, 0)
|
||||||
|
move(data.body[newCurIdx].from, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// down arrow
|
||||||
|
if (e.key === 'ArrowDown') {
|
||||||
|
if (curIdx !== undefined && (data != null) && !cursorInInput) {
|
||||||
|
prevent = true
|
||||||
|
const newCurIdx = Math.min(curIdx + 1, data.body.length - 1)
|
||||||
|
move(data.body[newCurIdx].from, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 阻止默认事件
|
||||||
|
if (prevent) {
|
||||||
|
e.preventDefault()
|
||||||
|
e.stopPropagation()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 检测快捷键
|
||||||
|
useEffect(() => {
|
||||||
|
document.addEventListener('keydown', onKeyDown)
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('keydown', onKeyDown)
|
||||||
|
}
|
||||||
|
}, [onKeyDown])
|
||||||
|
}
|
||||||
|
|
||||||
|
export default useKeyService
|
61
src/hooks/useSearchService.ts
Normal file
61
src/hooks/useSearchService.ts
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
import {useAppDispatch, useAppSelector} from './redux'
|
||||||
|
import {useEffect, useMemo} from 'react'
|
||||||
|
import {setSearchResult, setSearchText, } from '../redux/envReducer'
|
||||||
|
import {Search} from '../util/search'
|
||||||
|
|
||||||
|
interface Document {
|
||||||
|
idx: number
|
||||||
|
s: string // searchKeys
|
||||||
|
}
|
||||||
|
|
||||||
|
const useSearchService = () => {
|
||||||
|
const dispatch = useAppDispatch()
|
||||||
|
|
||||||
|
const envData = useAppSelector(state => state.env.envData)
|
||||||
|
const data = useAppSelector(state => state.env.data)
|
||||||
|
const searchText = useAppSelector(state => state.env.searchText)
|
||||||
|
|
||||||
|
const {reset, search} = useMemo(() => Search('idx', 's', 256, {
|
||||||
|
cnSearchEnabled: envData.cnSearchEnabled
|
||||||
|
}), [envData.cnSearchEnabled]) // 搜索实例
|
||||||
|
|
||||||
|
// reset search
|
||||||
|
useEffect(() => {
|
||||||
|
if (!envData.searchEnabled) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const startTime = Date.now()
|
||||||
|
const docs: Document[] = []
|
||||||
|
for (const item of data?.body??[]) {
|
||||||
|
docs.push({
|
||||||
|
idx: item.idx,
|
||||||
|
s: item.content,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
reset(docs)
|
||||||
|
// 清空搜索文本
|
||||||
|
dispatch(setSearchText(''))
|
||||||
|
// 日志
|
||||||
|
const endTime = Date.now()
|
||||||
|
console.debug(`[Search]reset ${docs.length} docs, cost ${endTime-startTime}ms`)
|
||||||
|
}, [data?.body, dispatch, envData.searchEnabled, reset])
|
||||||
|
|
||||||
|
// search text
|
||||||
|
useEffect(() => {
|
||||||
|
const searchResult: Set<number> = new Set()
|
||||||
|
|
||||||
|
if (envData.searchEnabled && searchText) {
|
||||||
|
// @ts-expect-error
|
||||||
|
const documents: Document[] | undefined = search(searchText)
|
||||||
|
if (documents != null) {
|
||||||
|
for (const document of documents) {
|
||||||
|
searchResult.add(document.idx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch(setSearchResult(searchResult))
|
||||||
|
}, [dispatch, envData.searchEnabled, search, searchText])
|
||||||
|
}
|
||||||
|
|
||||||
|
export default useSearchService
|
@@ -5,8 +5,8 @@ import {setNeedScroll} from '../redux/envReducer'
|
|||||||
const useSubtitle = () => {
|
const useSubtitle = () => {
|
||||||
const dispatch = useAppDispatch()
|
const dispatch = useAppDispatch()
|
||||||
|
|
||||||
const move = useCallback((time: number) => {
|
const move = useCallback((time: number, togglePause: boolean) => {
|
||||||
window.parent.postMessage({type: 'move', time}, '*')
|
window.parent.postMessage({type: 'move', time, togglePause}, '*')
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const scrollIntoView = useCallback((ref: React.RefObject<HTMLDivElement>) => {
|
const scrollIntoView = useCallback((ref: React.RefObject<HTMLDivElement>) => {
|
||||||
|
@@ -12,9 +12,19 @@ import {
|
|||||||
setSegments,
|
setSegments,
|
||||||
setTitle,
|
setTitle,
|
||||||
setTotalHeight,
|
setTotalHeight,
|
||||||
|
setUrl,
|
||||||
} from '../redux/envReducer'
|
} from '../redux/envReducer'
|
||||||
import {EventBusContext} from '../Router'
|
import {EventBusContext} from '../Router'
|
||||||
import {EVENT_EXPAND, TOTAL_HEIGHT_MAX, TOTAL_HEIGHT_MIN, WORDS_DEFAULT, WORDS_MAX, WORDS_MIN} from '../const'
|
import {
|
||||||
|
EVENT_EXPAND,
|
||||||
|
GEMINI_TOKENS,
|
||||||
|
MODEL_DEFAULT,
|
||||||
|
MODEL_MAP,
|
||||||
|
TOTAL_HEIGHT_MAX,
|
||||||
|
TOTAL_HEIGHT_MIN,
|
||||||
|
WORDS_MIN,
|
||||||
|
WORDS_RATE
|
||||||
|
} from '../const'
|
||||||
import {useInterval} from 'ahooks'
|
import {useInterval} from 'ahooks'
|
||||||
import {getWholeText} from '../util/biz_util'
|
import {getWholeText} from '../util/biz_util'
|
||||||
|
|
||||||
@@ -46,6 +56,7 @@ const useSubtitleService = () => {
|
|||||||
|
|
||||||
if (data.type === 'setVideoInfo') {
|
if (data.type === 'setVideoInfo') {
|
||||||
dispatch(setInfos(data.infos))
|
dispatch(setInfos(data.infos))
|
||||||
|
dispatch(setUrl(data.url))
|
||||||
dispatch(setTitle(data.title))
|
dispatch(setTitle(data.title))
|
||||||
console.debug('video title: ', data.title)
|
console.debug('video title: ', data.title)
|
||||||
}
|
}
|
||||||
@@ -94,7 +105,7 @@ const useSubtitleService = () => {
|
|||||||
type: EVENT_EXPAND
|
type: EVENT_EXPAND
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}, [data, eventBus])
|
}, [data, eventBus, infos])
|
||||||
|
|
||||||
// 当前未展示 & (未折叠 | 自动展开) & 有列表 => 展示第一个
|
// 当前未展示 & (未折叠 | 自动展开) & 有列表 => 展示第一个
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -156,8 +167,15 @@ const useSubtitleService = () => {
|
|||||||
const items = data?.body
|
const items = data?.body
|
||||||
if (items != null) {
|
if (items != null) {
|
||||||
if (envData.summarizeEnable) { // 分段
|
if (envData.summarizeEnable) { // 分段
|
||||||
let size = envData.words??WORDS_DEFAULT
|
let size = envData.words
|
||||||
size = Math.min(Math.max(size, WORDS_MIN), WORDS_MAX)
|
if (!size) { // 默认
|
||||||
|
if (envData.aiType === 'gemini') {
|
||||||
|
size = GEMINI_TOKENS*WORDS_RATE
|
||||||
|
} else {
|
||||||
|
size = (MODEL_MAP[envData.model??MODEL_DEFAULT]?.tokens??4000)*WORDS_RATE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
size = Math.max(size, WORDS_MIN)
|
||||||
|
|
||||||
segments = []
|
segments = []
|
||||||
let transcriptItems: TranscriptItem[] = []
|
let transcriptItems: TranscriptItem[] = []
|
||||||
@@ -191,7 +209,7 @@ const useSubtitleService = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
dispatch(setSegments(segments))
|
dispatch(setSegments(segments))
|
||||||
}, [data?.body, dispatch, envData.summarizeEnable, envData.words])
|
}, [data?.body, dispatch, envData.aiType, envData.model, envData.summarizeEnable, envData.words])
|
||||||
|
|
||||||
// 每秒更新当前视频时间
|
// 每秒更新当前视频时间
|
||||||
useInterval(() => {
|
useInterval(() => {
|
||||||
|
@@ -4,6 +4,9 @@ import {
|
|||||||
addTaskId,
|
addTaskId,
|
||||||
addTransResults,
|
addTransResults,
|
||||||
delTaskId,
|
delTaskId,
|
||||||
|
setAskContent,
|
||||||
|
setAskError,
|
||||||
|
setAskStatus,
|
||||||
setLastSummarizeTime,
|
setLastSummarizeTime,
|
||||||
setLastTransTime,
|
setLastTransTime,
|
||||||
setSummaryContent,
|
setSummaryContent,
|
||||||
@@ -15,6 +18,7 @@ import {
|
|||||||
LANGUAGES_MAP,
|
LANGUAGES_MAP,
|
||||||
MODEL_DEFAULT,
|
MODEL_DEFAULT,
|
||||||
PROMPT_DEFAULTS,
|
PROMPT_DEFAULTS,
|
||||||
|
PROMPT_TYPE_ASK,
|
||||||
PROMPT_TYPE_TRANSLATE,
|
PROMPT_TYPE_TRANSLATE,
|
||||||
SUMMARIZE_LANGUAGE_DEFAULT,
|
SUMMARIZE_LANGUAGE_DEFAULT,
|
||||||
SUMMARIZE_THRESHOLD,
|
SUMMARIZE_THRESHOLD,
|
||||||
@@ -82,23 +86,39 @@ const useTranslate = () => {
|
|||||||
prompt = prompt.replaceAll('{{subtitles}}', lineStr)
|
prompt = prompt.replaceAll('{{subtitles}}', lineStr)
|
||||||
|
|
||||||
const taskDef: TaskDef = {
|
const taskDef: TaskDef = {
|
||||||
type: 'chatComplete',
|
type: envData.aiType === 'gemini'?'geminiChatComplete':'chatComplete',
|
||||||
serverUrl: envData.serverUrl,
|
serverUrl: envData.serverUrl,
|
||||||
data: {
|
data: envData.aiType === 'gemini'
|
||||||
model: envData.model??MODEL_DEFAULT,
|
?{
|
||||||
messages: [
|
contents: [
|
||||||
{
|
{
|
||||||
role: 'user',
|
parts: [
|
||||||
content: prompt,
|
{
|
||||||
|
text: prompt
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
generationConfig: {
|
||||||
|
maxOutputTokens: 2048
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
:{
|
||||||
temperature: 0,
|
model: envData.model??MODEL_DEFAULT,
|
||||||
n: 1,
|
messages: [
|
||||||
stream: false,
|
{
|
||||||
},
|
role: 'user',
|
||||||
|
content: prompt,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
temperature: 0.25,
|
||||||
|
n: 1,
|
||||||
|
stream: false,
|
||||||
|
},
|
||||||
extra: {
|
extra: {
|
||||||
type: 'translate',
|
type: 'translate',
|
||||||
apiKey: envData.apiKey,
|
apiKey: envData.apiKey,
|
||||||
|
geminiApiKey: envData.geminiApiKey,
|
||||||
startIdx,
|
startIdx,
|
||||||
size: lines.length,
|
size: lines.length,
|
||||||
}
|
}
|
||||||
@@ -117,10 +137,10 @@ const useTranslate = () => {
|
|||||||
dispatch(addTaskId(task.id))
|
dispatch(addTaskId(task.id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [data?.body, dispatch, envData.apiKey, envData.fetchAmount, envData.serverUrl, envData.prompts, title, language.name])
|
}, [data?.body, envData.fetchAmount, envData.prompts, envData.aiType, envData.serverUrl, envData.model, envData.apiKey, envData.geminiApiKey, language.name, title, dispatch])
|
||||||
|
|
||||||
const addSummarizeTask = useCallback(async (type: SummaryType, segment: Segment) => {
|
const addSummarizeTask = useCallback(async (type: SummaryType, segment: Segment) => {
|
||||||
if (segment.text.length >= SUMMARIZE_THRESHOLD && envData.apiKey) {
|
if (segment.text.length >= SUMMARIZE_THRESHOLD) {
|
||||||
let subtitles = ''
|
let subtitles = ''
|
||||||
for (const item of segment.items) {
|
for (const item of segment.items) {
|
||||||
subtitles += formatTime(item.from) + ' ' + item.content + '\n'
|
subtitles += formatTime(item.from) + ' ' + item.content + '\n'
|
||||||
@@ -135,25 +155,41 @@ const useTranslate = () => {
|
|||||||
prompt = prompt.replaceAll('{{segment}}', segment.text)
|
prompt = prompt.replaceAll('{{segment}}', segment.text)
|
||||||
|
|
||||||
const taskDef: TaskDef = {
|
const taskDef: TaskDef = {
|
||||||
type: 'chatComplete',
|
type: envData.aiType === 'gemini'?'geminiChatComplete':'chatComplete',
|
||||||
serverUrl: envData.serverUrl,
|
serverUrl: envData.serverUrl,
|
||||||
data: {
|
data: envData.aiType === 'gemini'
|
||||||
model: envData.model??MODEL_DEFAULT,
|
?{
|
||||||
messages: [
|
contents: [
|
||||||
{
|
{
|
||||||
role: 'user',
|
parts: [
|
||||||
content: prompt,
|
{
|
||||||
|
text: prompt
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
generationConfig: {
|
||||||
|
maxOutputTokens: 2048
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
:{
|
||||||
temperature: 0,
|
model: envData.model??MODEL_DEFAULT,
|
||||||
n: 1,
|
messages: [
|
||||||
stream: false,
|
{
|
||||||
},
|
role: 'user',
|
||||||
|
content: prompt,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
temperature: 0.5,
|
||||||
|
n: 1,
|
||||||
|
stream: false,
|
||||||
|
},
|
||||||
extra: {
|
extra: {
|
||||||
type: 'summarize',
|
type: 'summarize',
|
||||||
summaryType: type,
|
summaryType: type,
|
||||||
startIdx: segment.startIdx,
|
startIdx: segment.startIdx,
|
||||||
apiKey: envData.apiKey,
|
apiKey: envData.apiKey,
|
||||||
|
geminiApiKey: envData.geminiApiKey,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.debug('addSummarizeTask', taskDef)
|
console.debug('addSummarizeTask', taskDef)
|
||||||
@@ -162,7 +198,60 @@ const useTranslate = () => {
|
|||||||
const task = await chrome.runtime.sendMessage({type: 'addTask', taskDef})
|
const task = await chrome.runtime.sendMessage({type: 'addTask', taskDef})
|
||||||
dispatch(addTaskId(task.id))
|
dispatch(addTaskId(task.id))
|
||||||
}
|
}
|
||||||
}, [dispatch, envData.apiKey, envData.prompts, envData.serverUrl, summarizeLanguage.name, title])
|
}, [dispatch, envData.aiType, envData.apiKey, envData.geminiApiKey, envData.model, envData.prompts, envData.serverUrl, summarizeLanguage.name, title])
|
||||||
|
|
||||||
|
const addAskTask = useCallback(async (segment: Segment, question: string) => {
|
||||||
|
if (segment.text.length >= SUMMARIZE_THRESHOLD) {
|
||||||
|
let prompt: string = envData.prompts?.[PROMPT_TYPE_ASK]??PROMPT_DEFAULTS[PROMPT_TYPE_ASK]
|
||||||
|
// replace params
|
||||||
|
prompt = prompt.replaceAll('{{language}}', summarizeLanguage.name)
|
||||||
|
prompt = prompt.replaceAll('{{title}}', title??'')
|
||||||
|
prompt = prompt.replaceAll('{{segment}}', segment.text)
|
||||||
|
prompt = prompt.replaceAll('{{question}}', question)
|
||||||
|
|
||||||
|
const taskDef: TaskDef = {
|
||||||
|
type: envData.aiType === 'gemini'?'geminiChatComplete':'chatComplete',
|
||||||
|
serverUrl: envData.serverUrl,
|
||||||
|
data: envData.aiType === 'gemini'
|
||||||
|
?{
|
||||||
|
contents: [
|
||||||
|
{
|
||||||
|
parts: [
|
||||||
|
{
|
||||||
|
text: prompt
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
generationConfig: {
|
||||||
|
maxOutputTokens: 2048
|
||||||
|
}
|
||||||
|
}
|
||||||
|
:{
|
||||||
|
model: envData.model??MODEL_DEFAULT,
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
role: 'user',
|
||||||
|
content: prompt,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
temperature: 0.5,
|
||||||
|
n: 1,
|
||||||
|
stream: false,
|
||||||
|
},
|
||||||
|
extra: {
|
||||||
|
type: 'ask',
|
||||||
|
// startIdx: segment.startIdx,
|
||||||
|
apiKey: envData.apiKey,
|
||||||
|
geminiApiKey: envData.geminiApiKey,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.debug('addAskTask', taskDef)
|
||||||
|
dispatch(setAskStatus({status: 'pending'}))
|
||||||
|
const task = await chrome.runtime.sendMessage({type: 'addTask', taskDef})
|
||||||
|
dispatch(addTaskId(task.id))
|
||||||
|
}
|
||||||
|
}, [dispatch, envData.aiType, envData.apiKey, envData.geminiApiKey, envData.model, envData.prompts, envData.serverUrl, summarizeLanguage.name, title])
|
||||||
|
|
||||||
const handleTranslate = useMemoizedFn((task: Task, content: string) => {
|
const handleTranslate = useMemoizedFn((task: Task, content: string) => {
|
||||||
let map: {[key: string]: string} = {}
|
let map: {[key: string]: string} = {}
|
||||||
@@ -215,13 +304,20 @@ const useTranslate = () => {
|
|||||||
console.debug('setSummary', task.def.extra.startIdx, summaryType, obj, task.error)
|
console.debug('setSummary', task.def.extra.startIdx, summaryType, obj, task.error)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const handleAsk = useMemoizedFn((task: Task, content?: string) => {
|
||||||
|
dispatch(setAskContent({content}))
|
||||||
|
dispatch(setAskStatus({status: 'done'}))
|
||||||
|
dispatch(setAskError({error: task.error}))
|
||||||
|
console.debug('setAsk', content, task.error)
|
||||||
|
})
|
||||||
|
|
||||||
const getTask = useCallback(async (taskId: string) => {
|
const getTask = useCallback(async (taskId: string) => {
|
||||||
const taskResp = await chrome.runtime.sendMessage({type: 'getTask', taskId})
|
const taskResp = await chrome.runtime.sendMessage({type: 'getTask', taskId})
|
||||||
if (taskResp.code === 'ok') {
|
if (taskResp.code === 'ok') {
|
||||||
console.debug('getTask', taskResp.task)
|
console.debug('getTask', taskResp.task)
|
||||||
const task: Task = taskResp.task
|
const task: Task = taskResp.task
|
||||||
const taskType: string | undefined = task.def.extra?.type
|
const taskType: string | undefined = task.def.extra?.type
|
||||||
const content = task.resp?.choices?.[0]?.message?.content?.trim()
|
const content = envData.aiType === 'gemini'?task.resp?.candidates[0]?.content?.parts[0]?.text?.trim():task.resp?.choices?.[0]?.message?.content?.trim()
|
||||||
if (task.status === 'done') {
|
if (task.status === 'done') {
|
||||||
// 异常提示
|
// 异常提示
|
||||||
if (task.error) {
|
if (task.error) {
|
||||||
@@ -234,14 +330,16 @@ const useTranslate = () => {
|
|||||||
handleTranslate(task, content)
|
handleTranslate(task, content)
|
||||||
} else if (taskType === 'summarize') { // 总结
|
} else if (taskType === 'summarize') { // 总结
|
||||||
handleSummarize(task, content)
|
handleSummarize(task, content)
|
||||||
|
} else if (taskType === 'ask') { // 总结
|
||||||
|
handleAsk(task, content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dispatch(delTaskId(taskId))
|
dispatch(delTaskId(taskId))
|
||||||
}
|
}
|
||||||
}, [dispatch, handleSummarize, handleTranslate])
|
}, [dispatch, envData.aiType, handleAsk, handleSummarize, handleTranslate])
|
||||||
|
|
||||||
return {getFetch, getTask, addTask, addSummarizeTask}
|
return {getFetch, getTask, addTask, addSummarizeTask, addAskTask}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default useTranslate
|
export default useTranslate
|
||||||
|
@@ -17,7 +17,6 @@ interface EnvState {
|
|||||||
autoScroll?: boolean
|
autoScroll?: boolean
|
||||||
checkAutoScroll?: boolean
|
checkAutoScroll?: boolean
|
||||||
curOffsetTop?: number
|
curOffsetTop?: number
|
||||||
compact?: boolean // 是否紧凑视图
|
|
||||||
floatKeyPointsSegIdx?: number // segment的startIdx
|
floatKeyPointsSegIdx?: number // segment的startIdx
|
||||||
|
|
||||||
noVideo?: boolean
|
noVideo?: boolean
|
||||||
@@ -25,19 +24,29 @@ interface EnvState {
|
|||||||
curIdx?: number // 从0开始
|
curIdx?: number // 从0开始
|
||||||
needScroll?: boolean
|
needScroll?: boolean
|
||||||
currentTime?: number
|
currentTime?: number
|
||||||
downloadType?: string
|
|
||||||
infos?: any[]
|
infos?: any[]
|
||||||
curInfo?: any
|
curInfo?: any
|
||||||
curFetched?: boolean
|
curFetched?: boolean
|
||||||
data?: Transcript
|
data?: Transcript
|
||||||
uploadedTranscript?: Transcript
|
uploadedTranscript?: Transcript
|
||||||
segments?: Segment[]
|
segments?: Segment[]
|
||||||
|
url?: string
|
||||||
title?: string
|
title?: string
|
||||||
|
|
||||||
taskIds?: string[]
|
taskIds?: string[]
|
||||||
transResults: {[key: number]: TransResult}
|
transResults: { [key: number]: TransResult }
|
||||||
lastTransTime?: number
|
lastTransTime?: number
|
||||||
lastSummarizeTime?: number
|
lastSummarizeTime?: number
|
||||||
|
|
||||||
|
// ask
|
||||||
|
askFold?: boolean
|
||||||
|
askQuestion?: string
|
||||||
|
askStatus: SummaryStatus
|
||||||
|
askError?: string
|
||||||
|
askContent?: string
|
||||||
|
|
||||||
|
searchText: string
|
||||||
|
searchResult: Set<number>
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialState: EnvState = {
|
const initialState: EnvState = {
|
||||||
@@ -45,19 +54,25 @@ const initialState: EnvState = {
|
|||||||
serverUrl: SERVER_URL_OPENAI,
|
serverUrl: SERVER_URL_OPENAI,
|
||||||
translateEnable: true,
|
translateEnable: true,
|
||||||
summarizeEnable: true,
|
summarizeEnable: true,
|
||||||
|
autoExpand: true,
|
||||||
theme: 'light',
|
theme: 'light',
|
||||||
|
searchEnabled: true,
|
||||||
},
|
},
|
||||||
tempData: {
|
tempData: {
|
||||||
curSummaryType: 'overview',
|
curSummaryType: 'overview',
|
||||||
},
|
},
|
||||||
|
askStatus: 'init',
|
||||||
totalHeight: TOTAL_HEIGHT_DEF,
|
totalHeight: TOTAL_HEIGHT_DEF,
|
||||||
autoScroll: true,
|
autoScroll: true,
|
||||||
currentTime: import.meta.env.VITE_ENV === 'web-dev'? 30: undefined,
|
currentTime: import.meta.env.VITE_ENV === 'web-dev' ? 30 : undefined,
|
||||||
envReady: false,
|
envReady: false,
|
||||||
tempReady: false,
|
tempReady: false,
|
||||||
fold: true,
|
fold: true,
|
||||||
data: import.meta.env.VITE_ENV === 'web-dev'? getDevData(): undefined,
|
data: import.meta.env.VITE_ENV === 'web-dev' ? getDevData() : undefined,
|
||||||
transResults: {},
|
transResults: {},
|
||||||
|
|
||||||
|
searchText: '',
|
||||||
|
searchResult: new Set(),
|
||||||
}
|
}
|
||||||
|
|
||||||
export const slice = createSlice({
|
export const slice = createSlice({
|
||||||
@@ -73,7 +88,7 @@ export const slice = createSlice({
|
|||||||
setEnvReady: (state) => {
|
setEnvReady: (state) => {
|
||||||
state.envReady = true
|
state.envReady = true
|
||||||
},
|
},
|
||||||
setTempData: (state, action: PayloadAction<TempData>) => {
|
setTempData: (state, action: PayloadAction<Partial<TempData>>) => {
|
||||||
state.tempData = {
|
state.tempData = {
|
||||||
...state.tempData,
|
...state.tempData,
|
||||||
...action.payload,
|
...action.payload,
|
||||||
@@ -82,15 +97,18 @@ export const slice = createSlice({
|
|||||||
setTempReady: (state) => {
|
setTempReady: (state) => {
|
||||||
state.tempReady = true
|
state.tempReady = true
|
||||||
},
|
},
|
||||||
|
setSearchText: (state, action: PayloadAction<string>) => {
|
||||||
|
state.searchText = action.payload
|
||||||
|
},
|
||||||
|
setSearchResult: (state, action: PayloadAction<Set<number>>) => {
|
||||||
|
state.searchResult = action.payload
|
||||||
|
},
|
||||||
setFloatKeyPointsSegIdx: (state, action: PayloadAction<number | undefined>) => {
|
setFloatKeyPointsSegIdx: (state, action: PayloadAction<number | undefined>) => {
|
||||||
state.floatKeyPointsSegIdx = action.payload
|
state.floatKeyPointsSegIdx = action.payload
|
||||||
},
|
},
|
||||||
setFoldAll: (state, action: PayloadAction<boolean>) => {
|
setFoldAll: (state, action: PayloadAction<boolean>) => {
|
||||||
state.foldAll = action.payload
|
state.foldAll = action.payload
|
||||||
},
|
},
|
||||||
setCompact: (state, action: PayloadAction<boolean>) => {
|
|
||||||
state.compact = action.payload
|
|
||||||
},
|
|
||||||
setPage: (state, action: PayloadAction<string | undefined>) => {
|
setPage: (state, action: PayloadAction<string | undefined>) => {
|
||||||
state.page = action.payload
|
state.page = action.payload
|
||||||
},
|
},
|
||||||
@@ -107,12 +125,12 @@ export const slice = createSlice({
|
|||||||
state.lastSummarizeTime = action.payload
|
state.lastSummarizeTime = action.payload
|
||||||
},
|
},
|
||||||
addTaskId: (state, action: PayloadAction<string>) => {
|
addTaskId: (state, action: PayloadAction<string>) => {
|
||||||
state.taskIds = [...(state.taskIds??[]), action.payload]
|
state.taskIds = [...(state.taskIds ?? []), action.payload]
|
||||||
},
|
},
|
||||||
delTaskId: (state, action: PayloadAction<string>) => {
|
delTaskId: (state, action: PayloadAction<string>) => {
|
||||||
state.taskIds = state.taskIds?.filter(id => id !== action.payload)
|
state.taskIds = state.taskIds?.filter(id => id !== action.payload)
|
||||||
},
|
},
|
||||||
addTransResults: (state, action: PayloadAction<{[key: number]: TransResult}>) => {
|
addTransResults: (state, action: PayloadAction<{ [key: number]: TransResult }>) => {
|
||||||
// 不要覆盖TransResult里code为200的
|
// 不要覆盖TransResult里code为200的
|
||||||
for (const payloadKey in action.payload) {
|
for (const payloadKey in action.payload) {
|
||||||
const payloadItem = action.payload[payloadKey]
|
const payloadItem = action.payload[payloadKey]
|
||||||
@@ -186,6 +204,27 @@ export const slice = createSlice({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
setAskFold: (state, action: PayloadAction<boolean>) => {
|
||||||
|
state.askFold = action.payload
|
||||||
|
},
|
||||||
|
setAskQuestion: (state, action: PayloadAction<string | undefined>) => {
|
||||||
|
state.askQuestion = action.payload
|
||||||
|
},
|
||||||
|
setAskContent: (state, action: PayloadAction<{
|
||||||
|
content?: any
|
||||||
|
}>) => {
|
||||||
|
state.askContent = action.payload.content
|
||||||
|
},
|
||||||
|
setAskStatus: (state, action: PayloadAction<{
|
||||||
|
status: SummaryStatus
|
||||||
|
}>) => {
|
||||||
|
state.askStatus = action.payload.status
|
||||||
|
},
|
||||||
|
setAskError: (state, action: PayloadAction<{
|
||||||
|
error?: string
|
||||||
|
}>) => {
|
||||||
|
state.askError = action.payload.error
|
||||||
|
},
|
||||||
setSegmentFold: (state, action: PayloadAction<{
|
setSegmentFold: (state, action: PayloadAction<{
|
||||||
segmentStartIdx: number
|
segmentStartIdx: number
|
||||||
fold: boolean
|
fold: boolean
|
||||||
@@ -216,15 +255,15 @@ export const slice = createSlice({
|
|||||||
setNoVideo: (state, action: PayloadAction<boolean>) => {
|
setNoVideo: (state, action: PayloadAction<boolean>) => {
|
||||||
state.noVideo = action.payload
|
state.noVideo = action.payload
|
||||||
},
|
},
|
||||||
setDownloadType: (state, action: PayloadAction<string>) => {
|
|
||||||
state.downloadType = action.payload
|
|
||||||
},
|
|
||||||
setNeedScroll: (state, action: PayloadAction<boolean>) => {
|
setNeedScroll: (state, action: PayloadAction<boolean>) => {
|
||||||
state.needScroll = action.payload
|
state.needScroll = action.payload
|
||||||
},
|
},
|
||||||
setCurrentTime: (state, action: PayloadAction<number | undefined>) => {
|
setCurrentTime: (state, action: PayloadAction<number | undefined>) => {
|
||||||
state.currentTime = action.payload
|
state.currentTime = action.payload
|
||||||
},
|
},
|
||||||
|
setUrl: (state, action: PayloadAction<string | undefined>) => {
|
||||||
|
state.url = action.payload
|
||||||
|
},
|
||||||
setTitle: (state, action: PayloadAction<string | undefined>) => {
|
setTitle: (state, action: PayloadAction<string | undefined>) => {
|
||||||
state.title = action.payload
|
state.title = action.payload
|
||||||
},
|
},
|
||||||
@@ -252,6 +291,50 @@ export const slice = createSlice({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
export const { setTempReady, setTempData, setUploadedTranscript, setTotalHeight, setCheckAutoScroll, setCurOffsetTop, setFloatKeyPointsSegIdx, setFoldAll, setCompact, setSegmentFold, setSummaryContent, setSummaryStatus, setSummaryError, setTitle, setSegments, setLastSummarizeTime, setPage, setLastTransTime, clearTransResults, addTransResults, addTaskId, delTaskId, setTaskIds, setDownloadType, setAutoTranslate, setAutoScroll, setNoVideo, setNeedScroll, setCurIdx, setEnvData, setEnvReady, setCurrentTime, setInfos, setCurInfo, setCurFetched, setData, setFold } = slice.actions
|
export const {
|
||||||
|
setUrl,
|
||||||
|
setAskFold,
|
||||||
|
setAskQuestion,
|
||||||
|
setAskStatus,
|
||||||
|
setAskError,
|
||||||
|
setAskContent,
|
||||||
|
setTempReady,
|
||||||
|
setTempData,
|
||||||
|
setUploadedTranscript,
|
||||||
|
setTotalHeight,
|
||||||
|
setCheckAutoScroll,
|
||||||
|
setCurOffsetTop,
|
||||||
|
setFloatKeyPointsSegIdx,
|
||||||
|
setFoldAll,
|
||||||
|
setSegmentFold,
|
||||||
|
setSummaryContent,
|
||||||
|
setSummaryStatus,
|
||||||
|
setSummaryError,
|
||||||
|
setTitle,
|
||||||
|
setSegments,
|
||||||
|
setLastSummarizeTime,
|
||||||
|
setPage,
|
||||||
|
setLastTransTime,
|
||||||
|
clearTransResults,
|
||||||
|
addTransResults,
|
||||||
|
addTaskId,
|
||||||
|
delTaskId,
|
||||||
|
setTaskIds,
|
||||||
|
setAutoTranslate,
|
||||||
|
setAutoScroll,
|
||||||
|
setNoVideo,
|
||||||
|
setNeedScroll,
|
||||||
|
setCurIdx,
|
||||||
|
setEnvData,
|
||||||
|
setEnvReady,
|
||||||
|
setCurrentTime,
|
||||||
|
setInfos,
|
||||||
|
setCurInfo,
|
||||||
|
setCurFetched,
|
||||||
|
setData,
|
||||||
|
setFold,
|
||||||
|
setSearchText,
|
||||||
|
setSearchResult,
|
||||||
|
} = slice.actions
|
||||||
|
|
||||||
export default slice.reducer
|
export default slice.reducer
|
||||||
|
17
src/typings.d.ts
vendored
17
src/typings.d.ts
vendored
@@ -1,9 +1,15 @@
|
|||||||
interface EnvData {
|
interface EnvData {
|
||||||
autoExpand?: boolean
|
autoExpand?: boolean
|
||||||
flagDot?: boolean
|
flagDot?: boolean
|
||||||
|
|
||||||
|
aiType?: 'openai' | 'gemini'
|
||||||
|
// openai
|
||||||
apiKey?: string
|
apiKey?: string
|
||||||
serverUrl?: string
|
serverUrl?: string
|
||||||
model?: string
|
model?: string
|
||||||
|
// gemini
|
||||||
|
geminiApiKey?: string
|
||||||
|
|
||||||
translateEnable?: boolean
|
translateEnable?: boolean
|
||||||
language?: string
|
language?: string
|
||||||
hideOnDisableAutoTranslate?: boolean
|
hideOnDisableAutoTranslate?: boolean
|
||||||
@@ -16,6 +22,13 @@ interface EnvData {
|
|||||||
theme?: 'system' | 'light' | 'dark'
|
theme?: 'system' | 'light' | 'dark'
|
||||||
fontSize?: 'normal' | 'large'
|
fontSize?: 'normal' | 'large'
|
||||||
|
|
||||||
|
// search
|
||||||
|
searchEnabled?: boolean
|
||||||
|
cnSearchEnabled?: boolean
|
||||||
|
|
||||||
|
// ask
|
||||||
|
askEnabled?: boolean
|
||||||
|
|
||||||
prompts?: {
|
prompts?: {
|
||||||
[key: string]: string
|
[key: string]: string
|
||||||
}
|
}
|
||||||
@@ -23,10 +36,12 @@ interface EnvData {
|
|||||||
|
|
||||||
interface TempData {
|
interface TempData {
|
||||||
curSummaryType: SummaryType
|
curSummaryType: SummaryType
|
||||||
|
downloadType?: string
|
||||||
|
compact?: boolean // 是否紧凑视图
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TaskDef {
|
interface TaskDef {
|
||||||
type: 'chatComplete'
|
type: 'chatComplete' | 'geminiChatComplete'
|
||||||
serverUrl?: string
|
serverUrl?: string
|
||||||
data: any
|
data: any
|
||||||
extra?: any
|
extra?: any
|
||||||
|
@@ -203,18 +203,22 @@ export const parseTranscript = (filename: string, text: string | ArrayBuffer): T
|
|||||||
if (filename.toLowerCase().endsWith('.srt')) {
|
if (filename.toLowerCase().endsWith('.srt')) {
|
||||||
const lines = text.split('\n\n')
|
const lines = text.split('\n\n')
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
const lines = line.split('\n')
|
try {
|
||||||
if (lines.length >= 3) {
|
const linesInner = line.trim().split('\n')
|
||||||
const time = lines[1].split(' --> ')
|
if (linesInner.length >= 3) {
|
||||||
const from = parseTime(time[0])
|
const time = linesInner[1].split(' --> ')
|
||||||
const to = parseTime(time[1])
|
const from = parseTime(time[0])
|
||||||
const content = lines.slice(2).join('\n')
|
const to = parseTime(time[1])
|
||||||
items.push({
|
const content = linesInner.slice(2).join('\n')
|
||||||
from,
|
items.push({
|
||||||
to,
|
from,
|
||||||
content,
|
to,
|
||||||
idx: items.length,
|
content,
|
||||||
})
|
idx: items.length,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('parse error', line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -249,7 +253,15 @@ export const extractJsonObject = (content: string) => {
|
|||||||
const start = content.indexOf('```')
|
const start = content.indexOf('```')
|
||||||
const end = content.lastIndexOf('```')
|
const end = content.lastIndexOf('```')
|
||||||
if (start >= 0 && end >= 0) {
|
if (start >= 0 && end >= 0) {
|
||||||
content = content.slice(start + 3, end)
|
if (start === end) { // 异常情况
|
||||||
|
if (content.startsWith('```')) {
|
||||||
|
content = content.slice(3)
|
||||||
|
} else {
|
||||||
|
content = content.slice(0, -3)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
content = content.slice(start + 3, end)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// get content between { and }
|
// get content between { and }
|
||||||
const start2 = content.indexOf('{')
|
const start2 = content.indexOf('{')
|
||||||
@@ -265,7 +277,15 @@ export const extractJsonArray = (content: string) => {
|
|||||||
const start = content.indexOf('```')
|
const start = content.indexOf('```')
|
||||||
const end = content.lastIndexOf('```')
|
const end = content.lastIndexOf('```')
|
||||||
if (start >= 0 && end >= 0) {
|
if (start >= 0 && end >= 0) {
|
||||||
content = content.slice(start + 3, end)
|
if (start === end) { // 异常情况
|
||||||
|
if (content.startsWith('```')) {
|
||||||
|
content = content.slice(3)
|
||||||
|
} else {
|
||||||
|
content = content.slice(0, -3)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
content = content.slice(start + 3, end)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// get content between [ and ]
|
// get content between [ and ]
|
||||||
const start3 = content.indexOf('[')
|
const start3 = content.indexOf('[')
|
||||||
|
125
src/util/pinyin_util.ts
Normal file
125
src/util/pinyin_util.ts
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
import pinyin from 'tiny-pinyin'
|
||||||
|
import {uniq} from 'lodash-es'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pinyin的返回结果
|
||||||
|
*/
|
||||||
|
interface Ret {
|
||||||
|
type: 1 | 2 | 3
|
||||||
|
source: string
|
||||||
|
target: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Phase {
|
||||||
|
pinyin: boolean
|
||||||
|
list: Ret[]
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取Phase列表(中英文分离列表)
|
||||||
|
*/
|
||||||
|
export const getPhases = (str: string) => {
|
||||||
|
const rets = pinyin.parse(str)
|
||||||
|
|
||||||
|
const phases: Phase[] = []
|
||||||
|
let curPinyin_ = false
|
||||||
|
let curPhase_: Ret[] = []
|
||||||
|
const addCurrentPhase = () => {
|
||||||
|
if (curPhase_.length > 0) {
|
||||||
|
phases.push({
|
||||||
|
pinyin: curPinyin_,
|
||||||
|
list: curPhase_,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 遍历rets
|
||||||
|
for (const ret of rets) {
|
||||||
|
const newPinyin = ret.type === 2
|
||||||
|
// 如果跟旧的pinyin类型不同,先保存旧的
|
||||||
|
if (newPinyin !== curPinyin_) {
|
||||||
|
addCurrentPhase()
|
||||||
|
// 重置
|
||||||
|
curPinyin_ = newPinyin
|
||||||
|
curPhase_ = []
|
||||||
|
}
|
||||||
|
// 添加新的
|
||||||
|
curPhase_.push(ret)
|
||||||
|
}
|
||||||
|
// 最后一个
|
||||||
|
addCurrentPhase()
|
||||||
|
|
||||||
|
return phases
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取原子字符列表,如 tool tab 汉 字
|
||||||
|
*/
|
||||||
|
export const getAtoms = (str: string) => {
|
||||||
|
const phases = getPhases(str)
|
||||||
|
|
||||||
|
const atoms = []
|
||||||
|
for (const phase of phases) {
|
||||||
|
if (phase.pinyin) { // all words
|
||||||
|
atoms.push(...phase.list.map(e => e.source).filter(e => e))
|
||||||
|
} else { // split
|
||||||
|
atoms.push(...(phase.list.map((e: any) => e.source).join('').match(/\w+/g)??[]).filter((e: string) => e))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return atoms
|
||||||
|
}
|
||||||
|
|
||||||
|
const fixStrs = (atoms: string[]) => {
|
||||||
|
// 小写
|
||||||
|
atoms = atoms.map(e => e.toLowerCase())
|
||||||
|
|
||||||
|
// 去重
|
||||||
|
atoms = uniq(atoms)
|
||||||
|
|
||||||
|
// 返回
|
||||||
|
return atoms
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getWords = (str: string) => {
|
||||||
|
// 获取全部原子字符
|
||||||
|
const atoms = getAtoms(str)
|
||||||
|
// fix
|
||||||
|
return fixStrs(atoms)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 我的世界Minecraft => ['wodeshijie', 'deshijie', 'shijie', 'jie'] + ['wdsj', 'dsj', 'sj', 'j']
|
||||||
|
*
|
||||||
|
* 1. only handle pinyin, other is ignored
|
||||||
|
*/
|
||||||
|
export const getWordsPinyin = (str: string) => {
|
||||||
|
let result: string[] = []
|
||||||
|
|
||||||
|
for (const phase of getPhases(str)) {
|
||||||
|
// only handle pinyin
|
||||||
|
if (phase.pinyin) { // 我的世界
|
||||||
|
// 获取全部原子字符
|
||||||
|
// 我的世界 => [我, 的, 世, 界]
|
||||||
|
const atoms: string[] = []
|
||||||
|
atoms.push(...phase.list.map(e => e.source).filter(e => e))
|
||||||
|
// 获取全部子串
|
||||||
|
// [我, 的, 世, 界] => [我的世界, 的世界, 世界, 界]
|
||||||
|
const allSubStr = []
|
||||||
|
for (let i = 0; i < atoms.length; i++) {
|
||||||
|
allSubStr.push(atoms.slice(i).join(''))
|
||||||
|
}
|
||||||
|
// pinyin version
|
||||||
|
const pinyinList = allSubStr.map((e: string) => pinyin.convertToPinyin(e))
|
||||||
|
result.push(...pinyinList)
|
||||||
|
// pinyin first version
|
||||||
|
const pinyinFirstList = allSubStr.map((e: string) => pinyin.parse(e).map((e: any) => e.type === 2?e.target[0]:null).filter(e => !!e).join(''))
|
||||||
|
result.push(...pinyinFirstList)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fix
|
||||||
|
result = fixStrs(result)
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
65
src/util/search.ts
Normal file
65
src/util/search.ts
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
import * as JsSearch from 'js-search'
|
||||||
|
import {uniq} from 'lodash-es'
|
||||||
|
import {getWords, getWordsPinyin} from './pinyin_util'
|
||||||
|
|
||||||
|
const tokenize = (maxLength: number, content: string, options?: SearchOptions) => {
|
||||||
|
const result: string[] = []
|
||||||
|
|
||||||
|
// 最大长度
|
||||||
|
if (content.length > maxLength) {
|
||||||
|
content = content.substring(0, maxLength)
|
||||||
|
}
|
||||||
|
result.push(...getWords(content))
|
||||||
|
// check cn
|
||||||
|
if (options?.cnSearchEnabled) {
|
||||||
|
result.push(...getWordsPinyin(content))
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.debug('[Search] tokenize:', str, '=>', result)
|
||||||
|
|
||||||
|
return uniq(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SearchOptions {
|
||||||
|
cnSearchEnabled?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Search = (uidFieldName: string, index: string, maxLength: number, options?: SearchOptions) => {
|
||||||
|
let searchRef: JsSearch.Search | undefined// 搜索器
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重置索引
|
||||||
|
*/
|
||||||
|
const reset = (documents?: Object[]) => {
|
||||||
|
// 搜索器
|
||||||
|
searchRef = new JsSearch.Search(uidFieldName)
|
||||||
|
searchRef.tokenizer = {
|
||||||
|
tokenize: (str) => {
|
||||||
|
return tokenize(maxLength, str, options)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
searchRef.addIndex(index)
|
||||||
|
|
||||||
|
// 检测添加文档
|
||||||
|
if (documents != null) {
|
||||||
|
searchRef.addDocuments(documents)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加文档
|
||||||
|
*/
|
||||||
|
const add = (document: Object) => {
|
||||||
|
searchRef?.addDocument(document)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索
|
||||||
|
* @return 未去重
|
||||||
|
*/
|
||||||
|
const search = (text: string) => {
|
||||||
|
return searchRef?.search(text.toLowerCase())
|
||||||
|
}
|
||||||
|
|
||||||
|
return {reset, add, search}
|
||||||
|
}
|
@@ -18,11 +18,13 @@ module.exports = {
|
|||||||
light: {
|
light: {
|
||||||
...require("daisyui/src/colors/themes")["[data-theme=light]"],
|
...require("daisyui/src/colors/themes")["[data-theme=light]"],
|
||||||
"--rounded-btn": "0.15rem",
|
"--rounded-btn": "0.15rem",
|
||||||
|
"primary": "rgb(0, 174, 236)",
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
dark: {
|
dark: {
|
||||||
...require("daisyui/src/colors/themes")["[data-theme=dark]"],
|
...require("daisyui/src/colors/themes")["[data-theme=dark]"],
|
||||||
"--rounded-btn": "0.15rem",
|
"--rounded-btn": "0.15rem",
|
||||||
|
"primary": "rgb(0, 174, 236)",
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
base: true,
|
base: true,
|
||||||
|
66
vite.config.ts.timestamp-1705728659971.mjs
Normal file
66
vite.config.ts.timestamp-1705728659971.mjs
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
// vite.config.ts
|
||||||
|
import { defineConfig } from "vite";
|
||||||
|
import react from "@vitejs/plugin-react";
|
||||||
|
import { visualizer } from "rollup-plugin-visualizer";
|
||||||
|
import { crx } from "@crxjs/vite-plugin";
|
||||||
|
|
||||||
|
// manifest.json
|
||||||
|
var manifest_default = {
|
||||||
|
name: "\u54D4\u54E9\u54D4\u54E9\u5B57\u5E55\u5217\u8868",
|
||||||
|
description: "\u663E\u793AB\u7AD9\u89C6\u9891\u7684\u5B57\u5E55\u5217\u8868,\u53EF\u70B9\u51FB\u8DF3\u8F6C\u4E0E\u4E0B\u8F7D\u5B57\u5E55,\u5E76\u652F\u6301\u7FFB\u8BD1\u548C\u603B\u7ED3\u5B57\u5E55!",
|
||||||
|
version: "1.7.11",
|
||||||
|
manifest_version: 3,
|
||||||
|
permissions: [
|
||||||
|
"storage"
|
||||||
|
],
|
||||||
|
background: {
|
||||||
|
service_worker: "src/chrome/background.ts"
|
||||||
|
},
|
||||||
|
content_scripts: [
|
||||||
|
{
|
||||||
|
matches: ["https://www.bilibili.com/video/*", "https://www.bilibili.com/list/*"],
|
||||||
|
js: ["src/chrome/content-script.cjs"]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
icons: {
|
||||||
|
"16": "favicon-16x16.png",
|
||||||
|
"32": "favicon-32x32.png",
|
||||||
|
"48": "favicon-48x48.png",
|
||||||
|
"128": "favicon-128x128.png"
|
||||||
|
},
|
||||||
|
action: {
|
||||||
|
default_popup: "index.html",
|
||||||
|
default_icon: {
|
||||||
|
"16": "favicon-16x16.png",
|
||||||
|
"32": "favicon-32x32.png",
|
||||||
|
"48": "favicon-48x48.png",
|
||||||
|
"128": "favicon-128x128.png"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// vite.config.ts
|
||||||
|
var vite_config_default = ({ mode }) => {
|
||||||
|
const plugins = [
|
||||||
|
react(),
|
||||||
|
visualizer()
|
||||||
|
];
|
||||||
|
if (mode === "production_chrome") {
|
||||||
|
plugins.push(crx({
|
||||||
|
manifest: manifest_default
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
return defineConfig({
|
||||||
|
base: "/",
|
||||||
|
plugins,
|
||||||
|
css: {
|
||||||
|
modules: {
|
||||||
|
localsConvention: "camelCase"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
export {
|
||||||
|
vite_config_default as default
|
||||||
|
};
|
||||||
|
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsidml0ZS5jb25maWcudHMiXSwKICAic291cmNlc0NvbnRlbnQiOiBbImNvbnN0IF9fdml0ZV9pbmplY3RlZF9vcmlnaW5hbF9kaXJuYW1lID0gXCIvVXNlcnMvZmVuZ3l1ZXhpYW5nL2RhdGEvcHJvamVjdC9iaWxpYmlsaS1zdWJ0aXRsZVwiO2NvbnN0IF9fdml0ZV9pbmplY3RlZF9vcmlnaW5hbF9maWxlbmFtZSA9IFwiL1VzZXJzL2Zlbmd5dWV4aWFuZy9kYXRhL3Byb2plY3QvYmlsaWJpbGktc3VidGl0bGUvdml0ZS5jb25maWcudHNcIjtjb25zdCBfX3ZpdGVfaW5qZWN0ZWRfb3JpZ2luYWxfaW1wb3J0X21ldGFfdXJsID0gXCJmaWxlOi8vL1VzZXJzL2Zlbmd5dWV4aWFuZy9kYXRhL3Byb2plY3QvYmlsaWJpbGktc3VidGl0bGUvdml0ZS5jb25maWcudHNcIjtpbXBvcnQge2RlZmluZUNvbmZpZywgUGx1Z2luT3B0aW9ufSBmcm9tICd2aXRlJ1xuaW1wb3J0IHJlYWN0IGZyb20gJ0B2aXRlanMvcGx1Z2luLXJlYWN0J1xuaW1wb3J0IHt2aXN1YWxpemVyfSBmcm9tIFwicm9sbHVwLXBsdWdpbi12aXN1YWxpemVyXCI7XG5pbXBvcnQge2NyeH0gZnJvbSAnQGNyeGpzL3ZpdGUtcGx1Z2luJ1xuLy8gQHRzLWlnbm9yZVxuaW1wb3J0IG1hbmlmZXN0IGZyb20gJy4vbWFuaWZlc3QuanNvbidcblxuLy8gaHR0cHM6Ly92aXRlanMuZGV2L2NvbmZpZy9cbmV4cG9ydCBkZWZhdWx0ICh7bW9kZX0pID0+IHtcbiAgY29uc3QgcGx1Z2lucyA9IFtcbiAgICByZWFjdCgpLFxuICAgIHZpc3VhbGl6ZXIoKSBhcyBQbHVnaW5PcHRpb24sXG4gIF1cbiAgLy8gQHRzLWlnbm9yZVxuICBpZiAobW9kZSA9PT0gJ3Byb2R1Y3Rpb25fY2hyb21lJykge1xuICAgIHBsdWdpbnMucHVzaChjcngoe1xuICAgICAgbWFuaWZlc3QsXG4gICAgfSkpXG4gIH1cbiAgcmV0dXJuIGRlZmluZUNvbmZpZyh7XG4gICAgYmFzZTogJy8nLFxuICAgIHBsdWdpbnMsXG4gICAgY3NzOiB7XG4gICAgICBtb2R1bGVzOiB7XG4gICAgICAgIGxvY2Fsc0NvbnZlbnRpb246IFwiY2FtZWxDYXNlXCJcbiAgICAgIH1cbiAgICB9XG4gIH0pXG59XG4iXSwKICAibWFwcGluZ3MiOiAiO0FBQXdVLFNBQVEsb0JBQWlDO0FBQ2pYLE9BQU8sV0FBVztBQUNsQixTQUFRLGtCQUFpQjtBQUN6QixTQUFRLFdBQVU7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBS2xCLElBQU8sc0JBQVEsQ0FBQyxFQUFDLEtBQUksTUFBTTtBQUN6QixRQUFNLFVBQVU7QUFBQSxJQUNkLE1BQU07QUFBQSxJQUNOLFdBQVc7QUFBQSxFQUNiO0FBRUEsTUFBSSxTQUFTLHFCQUFxQjtBQUNoQyxZQUFRLEtBQUssSUFBSTtBQUFBLE1BQ2Y7QUFBQSxJQUNGLENBQUMsQ0FBQztBQUFBLEVBQ0o7QUFDQSxTQUFPLGFBQWE7QUFBQSxJQUNsQixNQUFNO0FBQUEsSUFDTjtBQUFBLElBQ0EsS0FBSztBQUFBLE1BQ0gsU0FBUztBQUFBLFFBQ1Asa0JBQWtCO0FBQUEsTUFDcEI7QUFBQSxJQUNGO0FBQUEsRUFDRixDQUFDO0FBQ0g7IiwKICAibmFtZXMiOiBbXQp9Cg==
|
Reference in New Issue
Block a user