You've already forked bilibili-subtitle
Compare commits
26 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
1bf8188980 | ||
![]() |
3a9a8d9d56 | ||
![]() |
78b5d7a18b | ||
![]() |
ff6dae7a21 | ||
![]() |
3adb541e99 | ||
![]() |
1ef7537251 | ||
![]() |
be6b94164d | ||
![]() |
1f1d48b56a | ||
![]() |
02b7a09f42 | ||
![]() |
9320928b34 | ||
![]() |
1fbdeaa8f6 | ||
![]() |
2f22a8c4a2 | ||
![]() |
baa15581ed | ||
![]() |
7e4733dfa8 | ||
![]() |
5c6dcab653 | ||
![]() |
975c524369 | ||
![]() |
4a6ebf0894 | ||
![]() |
64059f71e5 | ||
![]() |
be97b1d51a | ||
![]() |
19553de975 | ||
![]() |
39d3f9be8e | ||
![]() |
75235883a5 | ||
![]() |
aeac55cb6b | ||
![]() |
cf1bd97dec | ||
![]() |
915cd8022d | ||
![]() |
e7f3eef6dc |
1
.cursorrules
Normal file
1
.cursorrules
Normal file
@@ -0,0 +1 @@
|
|||||||
|
This chrome extension project use typescript, react, tailwindcss, daisyui.
|
@@ -1 +1 @@
|
|||||||
VITE_ENV=web-dev
|
VITE_ENV=web-dev
|
@@ -1,3 +1,3 @@
|
|||||||
NODE_ENV=production
|
NODE_ENV=production
|
||||||
|
|
||||||
VITE_ENV=chrome
|
VITE_ENV=chrome
|
@@ -27,6 +27,13 @@
|
|||||||
|
|
||||||
安装扩展后,在哔哩哔哩网站观看视频时,视频右侧会显示字幕列表面板。
|
安装扩展后,在哔哩哔哩网站观看视频时,视频右侧会显示字幕列表面板。
|
||||||
|
|
||||||
|
### 使用本地Ollama模型
|
||||||
|
如果你使用本地Ollama模型,需要配置环境变量:`OLLAMA_ORIGINS=chrome-extension://bciglihaegkdhoogebcdblfhppoilclp`,否则访问会出现403错误。
|
||||||
|
|
||||||
|
然后在插件配置里,apiKey随便填一个,服务器地址填`http://localhost:11434`,模型选自定义,然后填入自定义模型名如`llama2`。
|
||||||
|
|
||||||
|
但是测试发现llama2 7b模型比较弱,无法返回需要的json格式,因此总结很可能会无法解析响应而报错(但提问功能不需要解析响应格式,因此没问题)。
|
||||||
|
|
||||||
## 交流联系
|
## 交流联系
|
||||||
|
|
||||||
QQ群:194536885
|
QQ群:194536885
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "哔哩哔哩字幕列表",
|
"name": "哔哩哔哩字幕列表",
|
||||||
"description": "显示B站视频的字幕列表,可点击跳转与下载字幕,并支持翻译和总结字幕!",
|
"description": "显示B站视频的字幕列表,可点击跳转与下载字幕,并支持翻译和总结字幕!",
|
||||||
"version": "1.9.2",
|
"version": "1.10.5",
|
||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"storage"
|
"storage"
|
||||||
|
@@ -1,15 +1,14 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "bilibili-subtitle",
|
"name": "bilibili-subtitle",
|
||||||
"version": "1.9.2",
|
"version": "1.10.5",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "哔哩哔哩字幕列表",
|
"description": "哔哩哔哩字幕列表",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "tsc && vite build -m production_chrome",
|
"build_chrome": "tsc && vite build -m production_chrome && node fixChrome.cjs",
|
||||||
"build_chrome": "pnpm run build && node fixChrome.cjs",
|
"build_firefox": "tsc && vite build -m production_chrome && node fixFirefox.cjs",
|
||||||
"build_firefox": "pnpm run build && node fixFirefox.cjs",
|
|
||||||
"fix": "eslint --fix --quiet ."
|
"fix": "eslint --fix --quiet ."
|
||||||
},
|
},
|
||||||
"author": "IndieKKY",
|
"author": "IndieKKY",
|
||||||
|
5407
pnpm-lock.yaml
generated
5407
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
BIN
public/my-article-summarizer.png
Normal file
BIN
public/my-article-summarizer.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.4 KiB |
72
src/biz/Ask.tsx
Normal file
72
src/biz/Ask.tsx
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
import {AiOutlineCloseCircle, BsDashSquare, BsPlusSquare, FaQuestion} from 'react-icons/all'
|
||||||
|
import classNames from 'classnames'
|
||||||
|
import Markdown from '../components/Markdown'
|
||||||
|
import React, {useCallback} from 'react'
|
||||||
|
import {delAskInfo, mergeAskInfo, setPage} from '../redux/envReducer'
|
||||||
|
import {useAppDispatch, useAppSelector} from '../hooks/redux'
|
||||||
|
import {PAGE_SETTINGS} from '../const'
|
||||||
|
import toast from 'react-hot-toast'
|
||||||
|
import useTranslate from '../hooks/useTranslate'
|
||||||
|
|
||||||
|
const Ask = (props: {
|
||||||
|
ask: AskInfo
|
||||||
|
}) => {
|
||||||
|
const {ask} = props
|
||||||
|
const dispatch = useAppDispatch()
|
||||||
|
const envData = useAppSelector(state => state.env.envData)
|
||||||
|
const fontSize = useAppSelector(state => state.env.envData.fontSize)
|
||||||
|
const segments = useAppSelector(state => state.env.segments)
|
||||||
|
const {addAskTask} = useTranslate()
|
||||||
|
|
||||||
|
const onRegenerate = useCallback(() => {
|
||||||
|
const apiKey = envData.aiType === 'gemini'?envData.geminiApiKey:envData.apiKey
|
||||||
|
if (apiKey) {
|
||||||
|
if (segments != null && segments.length > 0) {
|
||||||
|
addAskTask(ask.id, segments[0], ask.question).catch(console.error)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dispatch(setPage(PAGE_SETTINGS))
|
||||||
|
toast.error('需要先设置ApiKey!')
|
||||||
|
}
|
||||||
|
}, [addAskTask, ask.id, ask.question, dispatch, envData.aiType, envData.apiKey, envData.geminiApiKey, segments])
|
||||||
|
|
||||||
|
const onAskFold = useCallback(() => {
|
||||||
|
dispatch(mergeAskInfo({
|
||||||
|
id: ask.id,
|
||||||
|
fold: !ask.fold
|
||||||
|
}))
|
||||||
|
}, [ask, dispatch])
|
||||||
|
|
||||||
|
const onClose = useCallback(() => {
|
||||||
|
dispatch(delAskInfo(ask.id))
|
||||||
|
}, [ask, dispatch])
|
||||||
|
|
||||||
|
return <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='w-full relative flex justify-center min-h-[20px]'>
|
||||||
|
<div className='absolute left-0 top-0 bottom-0 text-xs select-none flex-center desc'>
|
||||||
|
{ask.fold
|
||||||
|
? <BsPlusSquare className='cursor-pointer' onClick={onAskFold}/> :
|
||||||
|
<BsDashSquare className='cursor-pointer' onClick={onAskFold}/>}
|
||||||
|
</div>
|
||||||
|
<button className='absolute right-0 top-0 bottom-0 btn btn-ghost btn-xs btn-circle text-base-content/75' onClick={onClose}>
|
||||||
|
<AiOutlineCloseCircle/>
|
||||||
|
</button>
|
||||||
|
<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>
|
||||||
|
{!ask.fold && ask.question && <div className='text-sm font-medium max-w-[90%]'>{ask.question}</div>}
|
||||||
|
{!ask.fold && ask.content &&
|
||||||
|
<div className={classNames('font-medium max-w-[90%] mt-1', fontSize === 'large' ? 'text-sm' : 'text-xs')}>
|
||||||
|
<Markdown content={ask.content}/>
|
||||||
|
</div>}
|
||||||
|
{!ask.fold && <button disabled={ask.status !== 'done'}
|
||||||
|
className={classNames('btn btn-link btn-xs', ask.status === 'pending' && 'loading')}
|
||||||
|
onClick={onRegenerate}>{ask.status === 'pending' ? '生成中' : '重新生成'}</button>}
|
||||||
|
{!ask.fold && ask.error && <div className='text-xs text-error'>{ask.error}</div>}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Ask
|
274
src/biz/Body.tsx
274
src/biz/Body.tsx
@@ -1,7 +1,7 @@
|
|||||||
import React, {useCallback, useEffect, useMemo, useRef} from 'react'
|
import React, {useCallback, useEffect, useMemo, useRef} from 'react'
|
||||||
import {
|
import {
|
||||||
setAskFold,
|
addAskInfo,
|
||||||
setAskQuestion,
|
mergeAskInfo,
|
||||||
setAutoScroll,
|
setAutoScroll,
|
||||||
setAutoTranslate,
|
setAutoTranslate,
|
||||||
setCheckAutoScroll,
|
setCheckAutoScroll,
|
||||||
@@ -16,10 +16,6 @@ import {useAppDispatch, useAppSelector} from '../hooks/redux'
|
|||||||
import {
|
import {
|
||||||
AiOutlineAim,
|
AiOutlineAim,
|
||||||
AiOutlineCloseCircle,
|
AiOutlineCloseCircle,
|
||||||
BsDashSquare,
|
|
||||||
BsPlusSquare,
|
|
||||||
FaGripfire,
|
|
||||||
FaQuestion,
|
|
||||||
FaRegArrowAltCircleDown,
|
FaRegArrowAltCircleDown,
|
||||||
IoWarning,
|
IoWarning,
|
||||||
MdExpand,
|
MdExpand,
|
||||||
@@ -32,21 +28,21 @@ import {
|
|||||||
ASK_ENABLED_DEFAULT,
|
ASK_ENABLED_DEFAULT,
|
||||||
HEADER_HEIGHT,
|
HEADER_HEIGHT,
|
||||||
PAGE_SETTINGS,
|
PAGE_SETTINGS,
|
||||||
RECOMMEND_HEIGHT,
|
|
||||||
SEARCH_BAR_HEIGHT,
|
SEARCH_BAR_HEIGHT,
|
||||||
SUMMARIZE_ALL_THRESHOLD,
|
SUMMARIZE_ALL_THRESHOLD,
|
||||||
TITLE_HEIGHT
|
TITLE_HEIGHT
|
||||||
} from '../const'
|
} 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 {openUrl} from '@kky002/kky-util'
|
import {openUrl} from '@kky002/kky-util'
|
||||||
import Markdown from '../components/Markdown'
|
|
||||||
import {random} from 'lodash-es'
|
|
||||||
import useKeyService from '../hooks/useKeyService'
|
import useKeyService from '../hooks/useKeyService'
|
||||||
|
import Ask from './Ask'
|
||||||
|
import {v4} from 'uuid'
|
||||||
|
import RateExtension from '../components/RateExtension'
|
||||||
|
|
||||||
const Body = () => {
|
const Body = () => {
|
||||||
const dispatch = useAppDispatch()
|
const dispatch = useAppDispatch()
|
||||||
|
const inputting = useAppSelector(state => state.env.inputting)
|
||||||
const noVideo = useAppSelector(state => state.env.noVideo)
|
const noVideo = useAppSelector(state => state.env.noVideo)
|
||||||
const autoTranslate = useAppSelector(state => state.env.autoTranslate)
|
const autoTranslate = useAppSelector(state => state.env.autoTranslate)
|
||||||
const autoScroll = useAppSelector(state => state.env.autoScroll)
|
const autoScroll = useAppSelector(state => state.env.autoScroll)
|
||||||
@@ -58,22 +54,18 @@ const Body = () => {
|
|||||||
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, addAskTask} = useTranslate()
|
const {addSummarizeTask, addAskTask} = useTranslate()
|
||||||
const infos = useAppSelector(state => state.env.infos)
|
// 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)
|
||||||
const needScroll = useAppSelector(state => state.env.needScroll)
|
const needScroll = useAppSelector(state => state.env.needScroll)
|
||||||
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 fontSize = useAppSelector(state => state.env.envData.fontSize)
|
||||||
const searchText = useAppSelector(state => state.env.searchText)
|
const searchText = useAppSelector(state => state.env.searchText)
|
||||||
const recommendIdx = useMemo(() => random(0, 3), [])
|
const asks = useAppSelector(state => state.env.asks)
|
||||||
|
// const recommendIdx = useMemo(() => random(0, 3), [])
|
||||||
const showSearchInput = useMemo(() => {
|
const showSearchInput = useMemo(() => {
|
||||||
return (segments != null && segments.length > 0) && (envData.searchEnabled ? envData.searchEnabled : (envData.askEnabled ?? ASK_ENABLED_DEFAULT))
|
return (segments != null && segments.length > 0) && (envData.searchEnabled ? envData.searchEnabled : (envData.askEnabled ?? ASK_ENABLED_DEFAULT))
|
||||||
}, [envData.askEnabled, envData.searchEnabled, segments])
|
}, [envData.askEnabled, envData.searchEnabled, segments])
|
||||||
@@ -81,7 +73,7 @@ const Body = () => {
|
|||||||
let placeholder = ''
|
let placeholder = ''
|
||||||
if (envData.searchEnabled) {
|
if (envData.searchEnabled) {
|
||||||
if (envData.askEnabled??ASK_ENABLED_DEFAULT) {
|
if (envData.askEnabled??ASK_ENABLED_DEFAULT) {
|
||||||
placeholder = '搜索或提问字幕内容'
|
placeholder = '搜索或提问字幕内容(按Enter提问)'
|
||||||
} else {
|
} else {
|
||||||
placeholder = '搜索字幕内容'
|
placeholder = '搜索字幕内容'
|
||||||
}
|
}
|
||||||
@@ -137,14 +129,19 @@ const Body = () => {
|
|||||||
|
|
||||||
const onFoldAll = useCallback(() => {
|
const onFoldAll = useCallback(() => {
|
||||||
dispatch(setFoldAll(!foldAll))
|
dispatch(setFoldAll(!foldAll))
|
||||||
dispatch(setAskFold(!foldAll))
|
for (const ask of asks) {
|
||||||
|
dispatch(mergeAskInfo({
|
||||||
|
id: ask.id,
|
||||||
|
fold: !foldAll
|
||||||
|
}))
|
||||||
|
}
|
||||||
for (const segment of segments ?? []) {
|
for (const segment of segments ?? []) {
|
||||||
dispatch(setSegmentFold({
|
dispatch(setSegmentFold({
|
||||||
segmentStartIdx: segment.startIdx,
|
segmentStartIdx: segment.startIdx,
|
||||||
fold: !foldAll
|
fold: !foldAll
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}, [dispatch, foldAll, segments])
|
}, [asks, dispatch, foldAll, segments])
|
||||||
|
|
||||||
const toggleAutoTranslateCallback = useCallback(() => {
|
const toggleAutoTranslateCallback = useCallback(() => {
|
||||||
const apiKey = envData.aiType === 'gemini'?envData.geminiApiKey:envData.apiKey
|
const apiKey = envData.aiType === 'gemini'?envData.geminiApiKey:envData.apiKey
|
||||||
@@ -167,14 +164,14 @@ const Body = () => {
|
|||||||
}
|
}
|
||||||
}, [autoScroll, dispatch])
|
}, [autoScroll, dispatch])
|
||||||
|
|
||||||
const onCopy = useCallback(() => {
|
// const onCopy = useCallback(() => {
|
||||||
const [success, content] = getSummarize(title, segments, curSummaryType)
|
// const [success, content] = getSummarize(title, segments, curSummaryType)
|
||||||
if (success) {
|
// if (success) {
|
||||||
navigator.clipboard.writeText(content).then(() => {
|
// navigator.clipboard.writeText(content).then(() => {
|
||||||
toast.success('复制成功')
|
// toast.success('复制成功')
|
||||||
}).catch(console.error)
|
// }).catch(console.error)
|
||||||
}
|
// }
|
||||||
}, [curSummaryType, segments, title])
|
// }, [curSummaryType, segments, title])
|
||||||
|
|
||||||
const onSearchTextChange = useCallback((e: any) => {
|
const onSearchTextChange = useCallback((e: any) => {
|
||||||
const searchText = e.target.value
|
const searchText = e.target.value
|
||||||
@@ -190,8 +187,14 @@ const Body = () => {
|
|||||||
const apiKey = envData.aiType === 'gemini'?envData.geminiApiKey:envData.apiKey
|
const apiKey = envData.aiType === 'gemini'?envData.geminiApiKey:envData.apiKey
|
||||||
if (apiKey) {
|
if (apiKey) {
|
||||||
if (segments != null && segments.length > 0) {
|
if (segments != null && segments.length > 0) {
|
||||||
dispatch(setAskQuestion(searchText))
|
const id = v4()
|
||||||
addAskTask(segments[0], searchText).catch(console.error)
|
addAskTask(id, segments[0], searchText).catch(console.error)
|
||||||
|
// 添加ask
|
||||||
|
dispatch(addAskInfo({
|
||||||
|
id,
|
||||||
|
question: searchText,
|
||||||
|
status: 'pending',
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dispatch(setPage(PAGE_SETTINGS))
|
dispatch(setPage(PAGE_SETTINGS))
|
||||||
@@ -200,14 +203,6 @@ const Body = () => {
|
|||||||
}
|
}
|
||||||
}, [addAskTask, dispatch, envData.aiType, envData.apiKey, envData.askEnabled, envData.geminiApiKey, searchText, segments])
|
}, [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
|
// service
|
||||||
useKeyService()
|
useKeyService()
|
||||||
|
|
||||||
@@ -256,7 +251,17 @@ const Body = () => {
|
|||||||
|
|
||||||
{/* search */}
|
{/* search */}
|
||||||
{showSearchInput && <div className='px-2 py-1 flex flex-col relative'>
|
{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}/>
|
<input type='text' className='input input-xs bg-base-200' placeholder={searchPlaceholder} value={searchText} onChange={onSearchTextChange} onKeyDown={e => {
|
||||||
|
// enter
|
||||||
|
if (e.key === 'Enter') {
|
||||||
|
if (!inputting) {
|
||||||
|
e.preventDefault()
|
||||||
|
e.stopPropagation()
|
||||||
|
onAsk()
|
||||||
|
dispatch(setSearchText(''))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}/>
|
||||||
{searchText && <button className='absolute top-1 right-2 btn btn-ghost btn-xs btn-circle text-base-content/75' onClick={onClearSearchText}><AiOutlineCloseCircle/></button>}
|
{searchText && <button className='absolute top-1 right-2 btn btn-ghost btn-xs btn-circle text-base-content/75' onClick={onClearSearchText}><AiOutlineCloseCircle/></button>}
|
||||||
</div>}
|
</div>}
|
||||||
|
|
||||||
@@ -272,36 +277,11 @@ const 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 - RECOMMEND_HEIGHT - (showSearchInput ? SEARCH_BAR_HEIGHT : 0)}px`
|
height: `${totalHeight - HEADER_HEIGHT - TITLE_HEIGHT - (showSearchInput ? SEARCH_BAR_HEIGHT : 0)}px`
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{/* ask */}
|
{/* asks */}
|
||||||
{(envData.askEnabled ?? ASK_ENABLED_DEFAULT) && (searchText || askQuestion) &&
|
{asks.map(ask => <Ask key={ask.id} ask={ask}/>)}
|
||||||
<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='w-full relative flex justify-center min-h-[20px]'>
|
|
||||||
<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 */}
|
||||||
{segments?.map((segment, segmentIdx) => <SegmentCard key={segment.startIdx} segment={segment}
|
{segments?.map((segment, segmentIdx) => <SegmentCard key={segment.startIdx} segment={segment}
|
||||||
@@ -325,22 +305,22 @@ const Body = () => {
|
|||||||
{/* </button>} */}
|
{/* </button>} */}
|
||||||
{/* </div> */}
|
{/* </div> */}
|
||||||
<div className='flex flex-col'>
|
<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='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'
|
{/* <div className='font-semibold text-accent flex items-center gap-1'><img src='/bibigpt.png' */}
|
||||||
alt='BibiGPT logo'
|
{/* alt='BibiGPT logo' */}
|
||||||
className='w-8 h-8'/>BibiGPT
|
{/* className='w-8 h-8'/>BibiGPT */}
|
||||||
</div>
|
{/* </div> */}
|
||||||
<div className='text-sm px-2 desc'>这是<span className='text-amber-600 font-semibold text-base'>网页</span>版的字幕列表,支持<span
|
{/* <div className='text-sm px-2 desc'>这是<span className='text-amber-600 font-semibold text-base'>网页</span>版的字幕列表,支持<span */}
|
||||||
className='font-semibold'>任意</span>视频提取字幕总结(包括没有字幕的视频)
|
{/* className='font-semibold'>任意</span>视频提取字幕总结(包括没有字幕的视频) */}
|
||||||
</div>
|
{/* </div> */}
|
||||||
<div className='flex gap-2'>
|
{/* <div className='flex gap-2'> */}
|
||||||
<a title='BibiGPT' href='https://bibigpt.co/r/bilibili'
|
{/* <a title='BibiGPT' href='https://bibigpt.co/r/bilibili' */}
|
||||||
onClick={(e) => {
|
{/* onClick={(e) => { */}
|
||||||
e.preventDefault()
|
{/* e.preventDefault() */}
|
||||||
openUrl('https://bibigpt.co/r/bilibili')
|
{/* openUrl('https://bibigpt.co/r/bilibili') */}
|
||||||
}} className='link text-sm text-accent'>✨ BibiGPT ✨</a>
|
{/* }} className='link text-sm text-accent'>✨ BibiGPT ✨</a> */}
|
||||||
</div>
|
{/* </div> */}
|
||||||
</div>
|
{/* </div> */}
|
||||||
<div className='flex flex-col items-center text-center py-2 mx-4 border-t border-t-base-300'>
|
<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'
|
<div className='font-semibold text-accent flex items-center gap-1'><img src='/youtube-caption.png'
|
||||||
alt='youtube caption logo'
|
alt='youtube caption logo'
|
||||||
@@ -368,71 +348,71 @@ const Body = () => {
|
|||||||
}} className='link text-sm text-accent'>Crx搜搜(国内可访问)</a>
|
}} className='link text-sm text-accent'>Crx搜搜(国内可访问)</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className='flex flex-col items-center text-center py-2 mx-4 border-t border-t-base-300'>
|
{/* <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'
|
{/* <div className='font-semibold text-accent flex items-center gap-1'><img src='/my-article-summarizer.png' */}
|
||||||
alt='Immersive Summary logo'
|
{/* alt='My Article Summarizer logo' */}
|
||||||
className='w-8 h-8'/>Immersive Summary
|
{/* className='w-8 h-8'/>My Article Summarizer */}
|
||||||
</div>
|
{/* </div> */}
|
||||||
<div className='text-sm px-2 desc'>沉浸式总结,多种方式总结网页文章。</div>
|
{/* <div className='text-sm px-2 desc'>网页文章总结(有每日免费额度,无需apikey)。</div> */}
|
||||||
<div className='flex gap-2'>
|
{/* <div className='flex gap-2'> */}
|
||||||
<a title='Chrome商店' href='https://chromewebstore.google.com/detail/mcijpllinkhflgpkggimnafkbmpiijah'
|
{/* <a title='Chrome商店' href='https://chromewebstore.google.com/detail/my-article-summarizer/nanlpakfialleijdidafldapoifndngn' */}
|
||||||
onClick={(e) => {
|
{/* onClick={(e) => { */}
|
||||||
e.preventDefault()
|
{/* e.preventDefault() */}
|
||||||
openUrl('https://chromewebstore.google.com/detail/mcijpllinkhflgpkggimnafkbmpiijah')
|
{/* openUrl('https://chromewebstore.google.com/detail/my-article-summarizer/nanlpakfialleijdidafldapoifndngn') */}
|
||||||
}} className='link text-sm text-accent'>Chrome商店</a>
|
{/* }} className='link text-sm text-accent'>Chrome商店</a> */}
|
||||||
<a title='Crx搜搜(国内可访问)'
|
{/* <a title='Crx搜搜(国内可访问)' */}
|
||||||
href='https://www.crxsoso.com/webstore/detail/mcijpllinkhflgpkggimnafkbmpiijah'
|
{/* href='https://www.crxsoso.com/webstore/detail/nanlpakfialleijdidafldapoifndngn' */}
|
||||||
onClick={(e) => {
|
{/* onClick={(e) => { */}
|
||||||
e.preventDefault()
|
{/* e.preventDefault() */}
|
||||||
openUrl('https://www.crxsoso.com/webstore/detail/mcijpllinkhflgpkggimnafkbmpiijah')
|
{/* openUrl('https://www.crxsoso.com/webstore/detail/nanlpakfialleijdidafldapoifndngn') */}
|
||||||
}} className='link text-sm text-accent'>Crx搜搜(国内可访问)</a>
|
{/* }} className='link text-sm text-accent'>Crx搜搜(国内可访问)</a> */}
|
||||||
</div>
|
{/* </div> */}
|
||||||
</div>
|
{/* </div> */}
|
||||||
</div>
|
</div>
|
||||||
|
<div className='p-2'><RateExtension/></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* recommend */}
|
{/* recommend */}
|
||||||
<div className='p-0.5' style={{
|
{/* <div className='p-0.5' style={{ */}
|
||||||
height: `${RECOMMEND_HEIGHT}px`
|
{/* height: `${RECOMMEND_HEIGHT}px` */}
|
||||||
}}>
|
{/* }}> */}
|
||||||
{recommendIdx === 0 && <div className='flex items-center gap-1.5 rounded shadow-sm bg-base-200/10'>
|
{/* {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) => {
|
{/* <a className='link link-accent link-hover font-semibold text-sm flex items-center' onClick={(e) => { */}
|
||||||
e.preventDefault()
|
{/* e.preventDefault() */}
|
||||||
openUrl('https://bibigpt.co/r/bilibili')
|
{/* openUrl('https://bibigpt.co/r/bilibili') */}
|
||||||
}}><img src='/bibigpt.png'
|
{/* }}><img src='/bibigpt.png' */}
|
||||||
alt='BibiGPT logo'
|
{/* alt='BibiGPT logo' */}
|
||||||
className='w-8 h-8'/>✨ BibiGPT ✨</a>
|
{/* className='w-8 h-8'/>✨ BibiGPT ✨</a> */}
|
||||||
<span className='text-sm desc'>支持任意视频的网页版总结。</span>
|
{/* <span className='text-sm desc'>支持任意视频的网页版总结。</span> */}
|
||||||
</div>}
|
{/* </div>} */}
|
||||||
{recommendIdx === 1 && <div className='flex items-center gap-1 rounded shadow-sm bg-base-200/10'>
|
{/* {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) => {
|
{/* <a className='link link-accent link-hover font-semibold text-sm flex items-center' onClick={(e) => { */}
|
||||||
e.preventDefault()
|
{/* e.preventDefault() */}
|
||||||
openUrl('https://chromewebstore.google.com/detail/fiaeclpicddpifeflpmlgmbjgaedladf')
|
{/* openUrl('https://chromewebstore.google.com/detail/fiaeclpicddpifeflpmlgmbjgaedladf') */}
|
||||||
}}><img src='/youtube-caption.png'
|
{/* }}><img src='/youtube-caption.png' */}
|
||||||
alt='youtube caption logo'
|
{/* alt='youtube caption logo' */}
|
||||||
className='w-8 h-8'/>YouTube Caption</a>
|
{/* className='w-8 h-8'/>YouTube Caption</a> */}
|
||||||
<span className='text-sm desc'>YouTube版的字幕列表。</span>
|
{/* <span className='text-sm desc'>YouTube版的字幕列表。</span> */}
|
||||||
</div>}
|
{/* </div>} */}
|
||||||
{recommendIdx === 2 && <div className='flex items-center gap-1 rounded shadow-sm bg-base-200/10'>
|
{/* {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) => {
|
{/* <a className='link link-accent link-hover font-semibold text-sm flex items-center' onClick={(e) => { */}
|
||||||
e.preventDefault()
|
{/* e.preventDefault() */}
|
||||||
openUrl('https://chromewebstore.google.com/detail/mcijpllinkhflgpkggimnafkbmpiijah')
|
{/* openUrl('https://chromewebstore.google.com/detail/nanlpakfialleijdidafldapoifndngn') */}
|
||||||
}}><img src='/immersive-summary.png'
|
{/* }}><img src='/my-article-summarizer.png' */}
|
||||||
alt='Immersive Summary logo'
|
{/* alt='My Article Summarizer logo' */}
|
||||||
className='w-8 h-8'/>Immersive Summary</a>
|
{/* className='w-8 h-8'/>My Article Summarizer</a> */}
|
||||||
<span className='text-sm desc'>沉浸式总结网页文章。</span>
|
{/* <span className='text-sm desc'>网页文章总结。</span> */}
|
||||||
</div>}
|
{/* </div>} */}
|
||||||
{recommendIdx === 3 && <div className='flex items-center gap-1 rounded shadow-sm bg-base-200/10'>
|
{/* {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) => {
|
{/* <a className='link link-accent link-hover font-semibold text-sm flex items-center' onClick={(e) => { */}
|
||||||
e.preventDefault()
|
{/* e.preventDefault() */}
|
||||||
openUrl('https://api.openai-up.com/register?aff=varM')
|
{/* openUrl('https://api.openai-up.com/register?aff=varM') */}
|
||||||
}}><img src='/openai-up.ico'
|
{/* }}><img src='/openai-up.ico' */}
|
||||||
alt='Openai Up logo'
|
{/* alt='Openai Up logo' */}
|
||||||
className='w-8 h-8'/>Openai代理</a>
|
{/* className='w-8 h-8'/>Openai代理</a> */}
|
||||||
<span className='text-sm desc flex items-center'>目前价格不到官方的6折<FaGripfire
|
{/* <span className='text-sm desc flex items-center'>目前价格不到官方的6折<FaGripfire */}
|
||||||
className='text-amber-600'/></span>
|
{/* className='text-amber-600'/></span> */}
|
||||||
</div>}
|
{/* </div>} */}
|
||||||
</div>
|
{/* </div> */}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -75,26 +75,27 @@ const MoreBtn = (props: Props) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let s, fileName
|
let fileName = title
|
||||||
|
let s, suffix
|
||||||
if (!downloadType || downloadType === 'text') {
|
if (!downloadType || downloadType === 'text') {
|
||||||
s = `${title??'无标题'}\n${url??'无链接'}\n\n`
|
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'
|
suffix = 'txt'
|
||||||
} else if (downloadType === 'textWithTime') {
|
} else if (downloadType === 'textWithTime') {
|
||||||
s = `${title??'无标题'}\n${url??'无链接'}\n\n`
|
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'
|
suffix = 'txt'
|
||||||
} else if (downloadType === 'article') {
|
} else if (downloadType === 'article') {
|
||||||
s = `${title??'无标题'}\n${url??'无链接'}\n\n`
|
s = `${title??'无标题'}\n${url??'无链接'}\n\n`
|
||||||
for (const item of data.body) {
|
for (const item of data.body) {
|
||||||
s += item.content + ', '
|
s += item.content + ', '
|
||||||
}
|
}
|
||||||
s = s.substring(0, s.length - 1) // remove last ','
|
s = s.substring(0, s.length - 1) // remove last ','
|
||||||
fileName = 'download.txt'
|
suffix = 'txt'
|
||||||
} else if (downloadType === 'srt') {
|
} else if (downloadType === 'srt') {
|
||||||
/**
|
/**
|
||||||
* 1
|
* 1
|
||||||
@@ -113,7 +114,7 @@ const MoreBtn = (props: Props) => {
|
|||||||
s += ss
|
s += ss
|
||||||
}
|
}
|
||||||
s = s.substring(0, s.length - 1)// remove last '\n'
|
s = s.substring(0, s.length - 1)// remove last '\n'
|
||||||
fileName = 'download.srt'
|
suffix = 'srt'
|
||||||
} else if (downloadType === 'vtt') {
|
} else if (downloadType === 'vtt') {
|
||||||
/**
|
/**
|
||||||
* WEBVTT title
|
* WEBVTT title
|
||||||
@@ -134,21 +135,22 @@ const MoreBtn = (props: Props) => {
|
|||||||
s += ss
|
s += ss
|
||||||
}
|
}
|
||||||
s = s.substring(0, s.length - 1)// remove last '\n'
|
s = s.substring(0, s.length - 1)// remove last '\n'
|
||||||
fileName = 'download.vtt'
|
suffix = 'vtt'
|
||||||
} else if (downloadType === 'json') {
|
} else if (downloadType === 'json') {
|
||||||
s = JSON.stringify(data)
|
s = JSON.stringify(data)
|
||||||
fileName = 'download.json'
|
suffix = 'json'
|
||||||
} else if (downloadType === 'summarize') {
|
} else if (downloadType === 'summarize') {
|
||||||
s = `${title??'无标题'}\n${url??'无链接'}\n\n`
|
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 += ' - 总结'
|
||||||
|
suffix = 'txt'
|
||||||
} else {
|
} else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (download) {
|
if (download) {
|
||||||
downloadText(s, fileName)
|
downloadText(s, fileName+'.'+suffix)
|
||||||
} else {
|
} else {
|
||||||
navigator.clipboard.writeText(s).then(() => {
|
navigator.clipboard.writeText(s).then(() => {
|
||||||
toast.success('复制成功')
|
toast.success('复制成功')
|
||||||
|
@@ -5,7 +5,7 @@ import classNames from 'classnames'
|
|||||||
import {FaClipboardList} from 'react-icons/fa'
|
import {FaClipboardList} from 'react-icons/fa'
|
||||||
import {PAGE_MAIN, PAGE_SETTINGS, SUMMARIZE_THRESHOLD, SUMMARIZE_TYPES} from '../const'
|
import {PAGE_MAIN, PAGE_SETTINGS, SUMMARIZE_THRESHOLD, SUMMARIZE_TYPES} from '../const'
|
||||||
import useTranslate from '../hooks/useTranslate'
|
import useTranslate from '../hooks/useTranslate'
|
||||||
import {BsDashSquare, BsPlusSquare, CgFileDocument, GrOverview, RiFileCopy2Line} from 'react-icons/all'
|
import {BsDashSquare, BsPlusSquare, CgFileDocument, FaQuestion, GrOverview, RiFileCopy2Line} from 'react-icons/all'
|
||||||
import toast from 'react-hot-toast'
|
import toast from 'react-hot-toast'
|
||||||
import {getLastTime, getSummaryStr, isSummaryEmpty, parseStrTimeToSeconds} from '../util/biz_util'
|
import {getLastTime, getSummaryStr, isSummaryEmpty, parseStrTimeToSeconds} from '../util/biz_util'
|
||||||
import {useInViewport} from 'ahooks'
|
import {useInViewport} from 'ahooks'
|
||||||
@@ -107,6 +107,13 @@ const Summarize = (props: {
|
|||||||
<div className={classNames('font-medium max-w-[90%]', fontSize === 'large' ? 'text-sm' : 'text-xs')}>
|
<div className={classNames('font-medium max-w-[90%]', fontSize === 'large' ? 'text-sm' : 'text-xs')}>
|
||||||
{summary.content.summary}
|
{summary.content.summary}
|
||||||
</div>}
|
</div>}
|
||||||
|
{summary?.type === 'question' && (summary.content != null) &&
|
||||||
|
<div className={classNames('max-w-[90%] flex flex-col gap-1', fontSize === 'large' ? 'text-sm' : 'text-xs')}>
|
||||||
|
{summary.content.map((question: any, idx: number) => <div key={idx}>
|
||||||
|
<h2 className={classNames('font-semibold underline', fontSize === 'large' ? 'text-sm' : 'text-xs')}>{question.q}</h2>
|
||||||
|
<div className={classNames('font-normal', fontSize === 'large' ? 'text-sm' : 'text-xs')}>{question.a}</div>
|
||||||
|
</div>)}
|
||||||
|
</div>}
|
||||||
</div>
|
</div>
|
||||||
<div className='flex flex-col justify-center items-center'>
|
<div className='flex flex-col justify-center items-center'>
|
||||||
{segment.text.length < SUMMARIZE_THRESHOLD && <div className='desc-lighter text-xs'>文字过短,无法总结.</div>}
|
{segment.text.length < SUMMARIZE_THRESHOLD && <div className='desc-lighter text-xs'>文字过短,无法总结.</div>}
|
||||||
@@ -189,6 +196,12 @@ const SegmentCard = (props: {
|
|||||||
}))
|
}))
|
||||||
}, [dispatch])
|
}, [dispatch])
|
||||||
|
|
||||||
|
const onSelQuestion = useCallback(() => {
|
||||||
|
dispatch(setTempData({
|
||||||
|
curSummaryType: 'question'
|
||||||
|
}))
|
||||||
|
}, [dispatch])
|
||||||
|
|
||||||
return <div
|
return <div
|
||||||
className={classNames('border border-base-300 bg-base-200/25 rounded flex flex-col m-1.5 p-1.5 gap-1 shadow', showCurrent && 'shadow-primary')}>
|
className={classNames('border border-base-300 bg-base-200/25 rounded flex flex-col m-1.5 p-1.5 gap-1 shadow', showCurrent && 'shadow-primary')}>
|
||||||
<div className='relative flex justify-center min-h-[20px]'>
|
<div className='relative flex justify-center min-h-[20px]'>
|
||||||
@@ -203,6 +216,7 @@ const SegmentCard = (props: {
|
|||||||
<a className={classNames('tab tab-lifted tab-xs', curSummaryType === 'brief' && 'tab-active')} onClick={onSelBrief}><CgFileDocument/>总结</a>
|
<a className={classNames('tab tab-lifted tab-xs', curSummaryType === 'brief' && 'tab-active')} onClick={onSelBrief}><CgFileDocument/>总结</a>
|
||||||
<a className={classNames('tab tab-lifted tab-xs', curSummaryType === 'overview' && 'tab-active')} onClick={onSelOverview}><GrOverview/>概览</a>
|
<a className={classNames('tab tab-lifted tab-xs', curSummaryType === 'overview' && 'tab-active')} onClick={onSelOverview}><GrOverview/>概览</a>
|
||||||
<a className={classNames('tab tab-lifted tab-xs', curSummaryType === 'keypoint' && 'tab-active')} onClick={onSelKeypoint}><FaClipboardList/>要点</a>
|
<a className={classNames('tab tab-lifted tab-xs', curSummaryType === 'keypoint' && 'tab-active')} onClick={onSelKeypoint}><FaClipboardList/>要点</a>
|
||||||
|
<a className={classNames('tab tab-lifted tab-xs', curSummaryType === 'question' && 'tab-active')} onClick={onSelQuestion}><FaQuestion/>问题</a>
|
||||||
<a className="tab tab-lifted tab-xs tab-disabled cursor-default"></a>
|
<a className="tab tab-lifted tab-xs tab-disabled cursor-default"></a>
|
||||||
</div>}
|
</div>}
|
||||||
<div
|
<div
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import React, {PropsWithChildren, useCallback, useMemo, useState} from 'react'
|
import React, {PropsWithChildren, useCallback, useMemo, useState} from 'react'
|
||||||
import {setEnvData, setPage} from '../redux/envReducer'
|
import {setEnvData, setPage, setTempData} from '../redux/envReducer'
|
||||||
import {useAppDispatch, useAppSelector} from '../hooks/redux'
|
import {useAppDispatch, useAppSelector} from '../hooks/redux'
|
||||||
import {
|
import {
|
||||||
ASK_ENABLED_DEFAULT,
|
ASK_ENABLED_DEFAULT,
|
||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
LANGUAGES,
|
LANGUAGES,
|
||||||
MODEL_DEFAULT,
|
MODEL_DEFAULT,
|
||||||
MODEL_MAP,
|
MODEL_MAP,
|
||||||
|
MODEL_TIP,
|
||||||
MODELS,
|
MODELS,
|
||||||
PAGE_MAIN,
|
PAGE_MAIN,
|
||||||
PROMPT_DEFAULTS,
|
PROMPT_DEFAULTS,
|
||||||
@@ -22,7 +23,7 @@ import {
|
|||||||
TRANSLATE_FETCH_STEP,
|
TRANSLATE_FETCH_STEP,
|
||||||
WORDS_RATE,
|
WORDS_RATE,
|
||||||
} from '../const'
|
} from '../const'
|
||||||
import {FaGripfire, IoWarning} from 'react-icons/all'
|
import {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'
|
||||||
@@ -241,14 +242,14 @@ const Settings = () => {
|
|||||||
<div>服务器地址:<a className='link link-primary'
|
<div>服务器地址:<a className='link link-primary'
|
||||||
onClick={() => setServerUrlValue(DEFAULT_SERVER_URL_OPENAI)}
|
onClick={() => setServerUrlValue(DEFAULT_SERVER_URL_OPENAI)}
|
||||||
rel='noreferrer'>点击设置</a></div>
|
rel='noreferrer'>点击设置</a></div>
|
||||||
<div className='flex justify-center font-semibold'>【第三方代理】</div>
|
{/* <div className='flex justify-center font-semibold'>【第三方代理】</div> */}
|
||||||
<div>代理网址:<a className='link link-primary' href='https://api.openai-up.com/register?aff=varM'
|
{/* <div>代理网址:<a className='link link-primary' href='https://api.openai-up.com/register?aff=varM' */}
|
||||||
target='_blank'
|
{/* target='_blank' */}
|
||||||
rel="noreferrer">点击访问</a></div>
|
{/* rel="noreferrer">点击访问</a></div> */}
|
||||||
<div>服务器地址:<a className='link link-primary'
|
{/* <div>服务器地址:<a className='link link-primary' */}
|
||||||
onClick={() => setServerUrlValue('https://api.openai-up.com')}
|
{/* onClick={() => setServerUrlValue('https://api.openai-up.com')} */}
|
||||||
rel='noreferrer'>点击设置</a></div>
|
{/* rel='noreferrer'>点击设置</a></div> */}
|
||||||
<div className='text-amber-600 flex justify-center items-center'><FaGripfire/>目前价格不到官方价格的6折<FaGripfire/></div>
|
{/* <div className='text-amber-600 flex justify-center items-center'><FaGripfire/>目前价格不到官方价格的6折<FaGripfire/></div> */}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<FormItem title='模型选择' htmlFor='modelSel' tip='注意,不同模型有不同价格与token限制'>
|
<FormItem title='模型选择' htmlFor='modelSel' tip='注意,不同模型有不同价格与token限制'>
|
||||||
@@ -257,13 +258,18 @@ const Settings = () => {
|
|||||||
{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='desc text-xs'>
|
||||||
|
{MODEL_TIP}
|
||||||
|
</div>
|
||||||
{modelValue === 'custom' && <FormItem title='模型名' htmlFor='customModel'>
|
{modelValue === 'custom' && <FormItem title='模型名' htmlFor='customModel'>
|
||||||
<input id='customModel' type='text' className='input input-sm input-bordered w-full' placeholder='llama2'
|
<input id='customModel' type='text' className='input input-sm input-bordered w-full' placeholder='llama2'
|
||||||
value={customModelValue} onChange={onChangeCustomModelValue}/>
|
value={customModelValue} onChange={onChangeCustomModelValue}/>
|
||||||
</FormItem>}
|
</FormItem>}
|
||||||
{modelValue === 'custom' && <FormItem title='Token上限' htmlFor='customModelTokens'>
|
{modelValue === 'custom' && <FormItem title='Token上限' htmlFor='customModelTokens'>
|
||||||
<input id='customModelTokens' type='number' className='input input-sm input-bordered w-full' placeholder={''+CUSTOM_MODEL_TOKENS}
|
<input id='customModelTokens' type='number' className='input input-sm input-bordered w-full'
|
||||||
value={customModelTokensValue} onChange={e => setCustomModelTokensValue(e.target.value?parseInt(e.target.value):undefined)}/>
|
placeholder={'' + CUSTOM_MODEL_TOKENS}
|
||||||
|
value={customModelTokensValue}
|
||||||
|
onChange={e => setCustomModelTokensValue(e.target.value ? parseInt(e.target.value) : undefined)}/>
|
||||||
</FormItem>}
|
</FormItem>}
|
||||||
</Section>}
|
</Section>}
|
||||||
|
|
||||||
@@ -274,36 +280,16 @@ const Settings = () => {
|
|||||||
</FormItem>
|
</FormItem>
|
||||||
<div>
|
<div>
|
||||||
<div className='desc text-xs'>
|
<div className='desc text-xs'>
|
||||||
<div>官方网址:<a className='link link-primary' href='https://makersuite.google.com/app/apikey' target='_blank'
|
<div>官方网址:<a className='link link-primary' href='https://makersuite.google.com/app/apikey'
|
||||||
rel="noreferrer">Google AI Studio</a> (目前免费)
|
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 className='text-xs text-error flex items-center'><IoWarning className='text-sm text-warning'/>谷歌模型安全要求比较高,有些视频可能无法生成总结!</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Section>}
|
</Section>}
|
||||||
|
|
||||||
<Section title='提示词配置'>
|
|
||||||
{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>)}
|
|
||||||
</Section>
|
|
||||||
|
|
||||||
<Section title={<div className='flex items-center'>
|
<Section title={<div className='flex items-center'>
|
||||||
翻译配置
|
翻译配置
|
||||||
{!apiKeySetted && <div className='tooltip tooltip-right ml-1' data-tip='未设置ApiKey无法使用'>
|
{!apiKeySetted && <div className='tooltip tooltip-right ml-1' data-tip='未设置ApiKey无法使用'>
|
||||||
@@ -393,9 +379,41 @@ const Settings = () => {
|
|||||||
onChange={setAskEnabledValue}/>
|
onChange={setAskEnabledValue}/>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
</Section>
|
</Section>
|
||||||
|
|
||||||
|
<Section title='提示词配置'>
|
||||||
|
<div className='flex justify-center'>
|
||||||
|
<a className='text-xs link link-primary' onClick={togglePromptsFold}>点击{promptsFold ? '展开' : '折叠'}</a>
|
||||||
|
</div>
|
||||||
|
{!promptsFold && 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>)}
|
||||||
|
</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>
|
||||||
<button className='btn btn-sm' onClick={onCancel}>取消</button>
|
<button className='btn btn-sm' onClick={onCancel}>取消</button>
|
||||||
|
{/* <button className='btn btn-sm' onClick={() => {
|
||||||
|
dispatch(setTempData({
|
||||||
|
reviewed: undefined,
|
||||||
|
// reviewActions: 0
|
||||||
|
}))
|
||||||
|
}}>重置</button> */}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -24,7 +24,7 @@ const timerIframe = setInterval(function () {
|
|||||||
const iframe = document.createElement('iframe')
|
const iframe = document.createElement('iframe')
|
||||||
iframe.id = IFRAME_ID
|
iframe.id = IFRAME_ID
|
||||||
iframe.src = chrome.runtime.getURL('index.html')
|
iframe.src = chrome.runtime.getURL('index.html')
|
||||||
iframe.style = 'border: none; width: 100%; height: 44px;'
|
iframe.style = 'border: none; width: 100%; height: 44px;margin-bottom: 3px;'
|
||||||
iframe.allow = 'clipboard-read; clipboard-write;'
|
iframe.allow = 'clipboard-read; clipboard-write;'
|
||||||
if (vKey) {
|
if (vKey) {
|
||||||
iframe.dataset[vKey] = danmukuBox?.dataset[vKey]
|
iframe.dataset[vKey] = danmukuBox?.dataset[vKey]
|
||||||
|
58
src/components/RateExtension.tsx
Normal file
58
src/components/RateExtension.tsx
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import { FaStar } from 'react-icons/fa';
|
||||||
|
import { IoMdClose } from 'react-icons/io';
|
||||||
|
import { setTempData } from '../redux/envReducer';
|
||||||
|
import { useAppDispatch, useAppSelector } from '../hooks/redux';
|
||||||
|
import { openUrl } from '@kky002/kky-util';
|
||||||
|
import { isEdgeBrowser } from '../util/util';
|
||||||
|
|
||||||
|
const RateExtension: React.FC = () => {
|
||||||
|
const dispatch = useAppDispatch()
|
||||||
|
const [isHovered, setIsHovered] = useState(false);
|
||||||
|
const reviewed = useAppSelector(state => state.env.tempData.reviewed)
|
||||||
|
|
||||||
|
const handleRateClick = () => {
|
||||||
|
dispatch(setTempData({
|
||||||
|
reviewed: true
|
||||||
|
}))
|
||||||
|
// Chrome Web Store URL for your extension
|
||||||
|
if (isEdgeBrowser()) {
|
||||||
|
openUrl('https://microsoftedge.microsoft.com/addons/detail/lignnlhlpiefmcjkdkmfjdckhlaiajan')
|
||||||
|
} else {
|
||||||
|
openUrl('https://chrome.google.com/webstore/detail/bciglihaegkdhoogebcdblfhppoilclp/reviews')
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (reviewed === true || reviewed === undefined) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="relative bg-gradient-to-r from-primary to-secondary text-primary-content p-4 rounded-lg shadow-lg text-sm transition-all duration-300 ease-in-out hover:shadow-xl">
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
dispatch(setTempData({
|
||||||
|
reviewed: true
|
||||||
|
}))
|
||||||
|
}}
|
||||||
|
className="absolute top-2 right-2 text-primary-content opacity-70 hover:opacity-100 transition-opacity"
|
||||||
|
>
|
||||||
|
<IoMdClose size={20} />
|
||||||
|
</button>
|
||||||
|
<h3 className="text-lg font-bold mb-2 animate-pulse">喜欢这个扩展吗?</h3>
|
||||||
|
<p className="mb-3">如果觉得有用,请给我们评分!</p>
|
||||||
|
<button
|
||||||
|
onClick={handleRateClick}
|
||||||
|
onMouseEnter={() => setIsHovered(true)}
|
||||||
|
onMouseLeave={() => setIsHovered(false)}
|
||||||
|
className="btn btn-accent btn-sm gap-2 transition-all duration-300 ease-in-out hover:scale-105"
|
||||||
|
>
|
||||||
|
<FaStar className={`inline-block text-yellow-300 ${isHovered ? 'animate-spin' : ''}`} />
|
||||||
|
去评分
|
||||||
|
<span className="transition-transform duration-300 ease-in-out transform inline-block">
|
||||||
|
{isHovered ? '🚀' : '→'}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default RateExtension;
|
@@ -8,6 +8,7 @@ export const STORAGE_TEMP = 'bilibili-subtitle_temp'
|
|||||||
export const PROMPT_TYPE_TRANSLATE = 'translate'
|
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_QUESTION = 'summarize_question'
|
||||||
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_TYPE_ASK = 'ask'
|
||||||
export const PROMPT_TYPES = [{
|
export const PROMPT_TYPES = [{
|
||||||
@@ -22,6 +23,9 @@ export const PROMPT_TYPES = [{
|
|||||||
}, {
|
}, {
|
||||||
name: '总结',
|
name: '总结',
|
||||||
type: PROMPT_TYPE_SUMMARIZE_BRIEF,
|
type: PROMPT_TYPE_SUMMARIZE_BRIEF,
|
||||||
|
}, {
|
||||||
|
name: '问题',
|
||||||
|
type: PROMPT_TYPE_SUMMARIZE_QUESTION,
|
||||||
}, {
|
}, {
|
||||||
name: '提问',
|
name: '提问',
|
||||||
type: PROMPT_TYPE_ASK,
|
type: PROMPT_TYPE_ASK,
|
||||||
@@ -46,6 +50,12 @@ export const SUMMARIZE_TYPES = {
|
|||||||
downloadName: '💡视频要点💡',
|
downloadName: '💡视频要点💡',
|
||||||
promptType: PROMPT_TYPE_SUMMARIZE_KEYPOINT,
|
promptType: PROMPT_TYPE_SUMMARIZE_KEYPOINT,
|
||||||
},
|
},
|
||||||
|
question: {
|
||||||
|
name: '问题',
|
||||||
|
desc: '常见问题',
|
||||||
|
downloadName: '💡常见问题💡',
|
||||||
|
promptType: PROMPT_TYPE_SUMMARIZE_QUESTION,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PROMPT_DEFAULTS = {
|
export const PROMPT_DEFAULTS = {
|
||||||
@@ -124,6 +134,46 @@ The video's subtitles:
|
|||||||
'''
|
'''
|
||||||
{{segment}}
|
{{segment}}
|
||||||
'''`,
|
'''`,
|
||||||
|
[PROMPT_TYPE_SUMMARIZE_QUESTION]: `You are a helpful assistant that skilled at extracting questions from video subtitle.
|
||||||
|
|
||||||
|
## Context
|
||||||
|
|
||||||
|
The video's title: '''{{title}}'''.
|
||||||
|
The video's subtitles:
|
||||||
|
|
||||||
|
'''
|
||||||
|
{{segment}}
|
||||||
|
'''
|
||||||
|
|
||||||
|
## Command
|
||||||
|
|
||||||
|
Accurately extract key questions and their corresponding answers from the video subtitles based on the actual content provided. The number of questions should be between 3 and 5.
|
||||||
|
|
||||||
|
- Identify questions as sentences starting with interrogative words (e.g., "What", "How", "Why") and extract the following sentences that directly answer these questions.
|
||||||
|
- Include only those questions and answers that are relevant to the main points of the video, and ensure they cover different aspects of the video's content.
|
||||||
|
- If an answer spans multiple non-consecutive parts of the subtitles, concatenate them into a coherent response without adding any information not present in the subtitles.
|
||||||
|
- In cases where the number of potential Q&As exceeds 5, prioritize the most informative and directly answered ones.
|
||||||
|
- If clear questions and answers are not available in the subtitles, refrain from creating them and instead note the absence of direct Q&As.
|
||||||
|
- Answer in language '{{language}}'.
|
||||||
|
- Format the output in markdown json format, as specified.
|
||||||
|
|
||||||
|
## Output format
|
||||||
|
|
||||||
|
Provide an example to illustrate the expected output:
|
||||||
|
|
||||||
|
\`\`\`json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"q": "What is the main theme of the video?",
|
||||||
|
"a": "The main theme of the video is explained as..."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"q": "How is the topic developed?",
|
||||||
|
"a": "The topic is developed through various examples, including..."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
\`\`\`
|
||||||
|
`,
|
||||||
[PROMPT_TYPE_ASK]: `You are a helpful assistant who answers question related to video subtitles.
|
[PROMPT_TYPE_ASK]: `You are a helpful assistant who answers question related to video subtitles.
|
||||||
Answer in language '{{language}}'.
|
Answer in language '{{language}}'.
|
||||||
|
|
||||||
@@ -172,24 +222,21 @@ export const ASK_ENABLED_DEFAULT = true
|
|||||||
export const DEFAULT_SERVER_URL_OPENAI = 'https://api.openai.com'
|
export const DEFAULT_SERVER_URL_OPENAI = 'https://api.openai.com'
|
||||||
export const CUSTOM_MODEL_TOKENS = 16385
|
export const CUSTOM_MODEL_TOKENS = 16385
|
||||||
|
|
||||||
|
export const MODEL_TIP = '推荐gpt-4o-mini,能力强,价格低,token上限大'
|
||||||
export const MODELS = [{
|
export const MODELS = [{
|
||||||
code: 'gpt-3.5-turbo',
|
code: 'gpt-4o-mini',
|
||||||
name: 'gpt-3.5-turbo',
|
name: 'gpt-4o-mini',
|
||||||
tokens: 4096,
|
tokens: 128000,
|
||||||
}, {
|
}, {
|
||||||
code: 'gpt-3.5-turbo-0125',
|
code: 'gpt-3.5-turbo-0125',
|
||||||
name: 'gpt-3.5-turbo-0125',
|
name: 'gpt-3.5-turbo-0125',
|
||||||
tokens: 16385,
|
tokens: 16385,
|
||||||
}, {
|
|
||||||
code: 'gpt-3.5-turbo-1106',
|
|
||||||
name: 'gpt-3.5-turbo-1106',
|
|
||||||
tokens: 16385,
|
|
||||||
}, {
|
}, {
|
||||||
code: 'custom',
|
code: 'custom',
|
||||||
name: '自定义',
|
name: '自定义',
|
||||||
}]
|
}]
|
||||||
export const GEMINI_TOKENS = 32768
|
export const GEMINI_TOKENS = 32768
|
||||||
export const MODEL_DEFAULT = MODELS[1].code
|
export const MODEL_DEFAULT = MODELS[0].code
|
||||||
export const MODEL_MAP: {[key: string]: typeof MODELS[number]} = {}
|
export const MODEL_MAP: {[key: string]: typeof MODELS[number]} = {}
|
||||||
for (const model of MODELS) {
|
for (const model of MODELS) {
|
||||||
MODEL_MAP[model.code] = model
|
MODEL_MAP[model.code] = model
|
||||||
|
@@ -1,14 +1,39 @@
|
|||||||
import {useEffect} from 'react'
|
import {useEffect} from 'react'
|
||||||
import {useMemoizedFn} from 'ahooks/es'
|
import {useMemoizedFn} from 'ahooks/es'
|
||||||
import {useAppSelector} from './redux'
|
import {useAppDispatch, useAppSelector} from './redux'
|
||||||
import useSubtitle from './useSubtitle'
|
import useSubtitle from './useSubtitle'
|
||||||
|
import {setInputting} from '../redux/envReducer'
|
||||||
|
|
||||||
const useKeyService = () => {
|
const useKeyService = () => {
|
||||||
|
const dispatch = useAppDispatch()
|
||||||
|
const inputting = useAppSelector(state => state.env.inputting)
|
||||||
const curIdx = useAppSelector(state => state.env.curIdx)
|
const curIdx = useAppSelector(state => state.env.curIdx)
|
||||||
const data = useAppSelector(state => state.env.data)
|
const data = useAppSelector(state => state.env.data)
|
||||||
const {move} = useSubtitle()
|
const {move} = useSubtitle()
|
||||||
|
|
||||||
|
// 输入中
|
||||||
|
useEffect(() => {
|
||||||
|
const onInputtingStart = (e: CompositionEvent) => {
|
||||||
|
dispatch(setInputting(true))
|
||||||
|
}
|
||||||
|
const onInputtingEnd = (e: CompositionEvent) => {
|
||||||
|
dispatch(setInputting(false))
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('compositionstart', onInputtingStart)
|
||||||
|
document.addEventListener('compositionend', onInputtingEnd)
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('compositionstart', onInputtingStart)
|
||||||
|
document.removeEventListener('compositionend', onInputtingEnd)
|
||||||
|
}
|
||||||
|
}, [dispatch])
|
||||||
|
|
||||||
const onKeyDown = useMemoizedFn((e: KeyboardEvent) => {
|
const onKeyDown = useMemoizedFn((e: KeyboardEvent) => {
|
||||||
|
// 当前在输入中(如中文输入法)
|
||||||
|
if (inputting) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 有按其他控制键时,不触发
|
// 有按其他控制键时,不触发
|
||||||
if (e.ctrlKey || e.metaKey || e.shiftKey) {
|
if (e.ctrlKey || e.metaKey || e.shiftKey) {
|
||||||
return
|
return
|
||||||
|
@@ -1,13 +1,24 @@
|
|||||||
import {useAppDispatch} from './redux'
|
import {useAppDispatch, useAppSelector} from './redux'
|
||||||
import React, {useCallback} from 'react'
|
import React, {useCallback} from 'react'
|
||||||
import {setNeedScroll} from '../redux/envReducer'
|
import {setNeedScroll, setReviewAction, setTempData} from '../redux/envReducer'
|
||||||
|
|
||||||
const useSubtitle = () => {
|
const useSubtitle = () => {
|
||||||
const dispatch = useAppDispatch()
|
const dispatch = useAppDispatch()
|
||||||
|
const reviewed = useAppSelector(state => state.env.tempData.reviewed)
|
||||||
|
const reviewAction = useAppSelector(state => state.env.reviewAction)
|
||||||
|
const reviewActions = useAppSelector(state => state.env.tempData.reviewActions)
|
||||||
|
|
||||||
const move = useCallback((time: number, togglePause: boolean) => {
|
const move = useCallback((time: number, togglePause: boolean) => {
|
||||||
window.parent.postMessage({type: 'move', time, togglePause}, '*')
|
window.parent.postMessage({type: 'move', time, togglePause}, '*')
|
||||||
}, [])
|
|
||||||
|
//review action
|
||||||
|
if (reviewed === undefined && !reviewAction) {
|
||||||
|
dispatch(setReviewAction(true))
|
||||||
|
dispatch(setTempData({
|
||||||
|
reviewActions: (reviewActions ?? 0) + 1
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}, [dispatch, reviewAction, reviewActions, reviewed])
|
||||||
|
|
||||||
const scrollIntoView = useCallback((ref: React.RefObject<HTMLDivElement>) => {
|
const scrollIntoView = useCallback((ref: React.RefObject<HTMLDivElement>) => {
|
||||||
ref.current?.scrollIntoView({behavior: 'smooth', block: 'center'})
|
ref.current?.scrollIntoView({behavior: 'smooth', block: 'center'})
|
||||||
|
@@ -13,6 +13,7 @@ import {
|
|||||||
setTitle,
|
setTitle,
|
||||||
setTotalHeight,
|
setTotalHeight,
|
||||||
setUrl,
|
setUrl,
|
||||||
|
setTempData,
|
||||||
} from '../redux/envReducer'
|
} from '../redux/envReducer'
|
||||||
import {EventBusContext} from '../Router'
|
import {EventBusContext} from '../Router'
|
||||||
import {EVENT_EXPAND, GEMINI_TOKENS, TOTAL_HEIGHT_MAX, TOTAL_HEIGHT_MIN, WORDS_MIN, WORDS_RATE} from '../const'
|
import {EVENT_EXPAND, GEMINI_TOKENS, TOTAL_HEIGHT_MAX, TOTAL_HEIGHT_MIN, WORDS_MIN, WORDS_RATE} from '../const'
|
||||||
@@ -39,6 +40,17 @@ const useSubtitleService = () => {
|
|||||||
const transResults = useAppSelector(state => state.env.transResults)
|
const transResults = useAppSelector(state => state.env.transResults)
|
||||||
const hideOnDisableAutoTranslate = useAppSelector(state => state.env.envData.hideOnDisableAutoTranslate)
|
const hideOnDisableAutoTranslate = useAppSelector(state => state.env.envData.hideOnDisableAutoTranslate)
|
||||||
const autoTranslate = useAppSelector(state => state.env.autoTranslate)
|
const autoTranslate = useAppSelector(state => state.env.autoTranslate)
|
||||||
|
const reviewed = useAppSelector(state => state.env.tempData.reviewed)
|
||||||
|
const reviewActions = useAppSelector(state => state.env.tempData.reviewActions)
|
||||||
|
|
||||||
|
//如果reviewActions达到15次,则设置reviewed为false
|
||||||
|
useEffect(() => {
|
||||||
|
if (reviewed === undefined && reviewActions && reviewActions >= 15) {
|
||||||
|
dispatch(setTempData({
|
||||||
|
reviewed: false
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}, [reviewActions, dispatch, reviewed])
|
||||||
|
|
||||||
// 监听消息
|
// 监听消息
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@@ -4,14 +4,14 @@ import {
|
|||||||
addTaskId,
|
addTaskId,
|
||||||
addTransResults,
|
addTransResults,
|
||||||
delTaskId,
|
delTaskId,
|
||||||
setAskContent,
|
mergeAskInfo,
|
||||||
setAskError,
|
|
||||||
setAskStatus,
|
|
||||||
setLastSummarizeTime,
|
setLastSummarizeTime,
|
||||||
setLastTransTime,
|
setLastTransTime,
|
||||||
setSummaryContent,
|
setSummaryContent,
|
||||||
setSummaryError,
|
setSummaryError,
|
||||||
setSummaryStatus
|
setSummaryStatus,
|
||||||
|
setReviewAction,
|
||||||
|
setTempData
|
||||||
} from '../redux/envReducer'
|
} from '../redux/envReducer'
|
||||||
import {
|
import {
|
||||||
LANGUAGE_DEFAULT,
|
LANGUAGE_DEFAULT,
|
||||||
@@ -40,6 +40,9 @@ const useTranslate = () => {
|
|||||||
const language = LANGUAGES_MAP[envData.language??LANGUAGE_DEFAULT]
|
const language = LANGUAGES_MAP[envData.language??LANGUAGE_DEFAULT]
|
||||||
const summarizeLanguage = LANGUAGES_MAP[envData.summarizeLanguage??SUMMARIZE_LANGUAGE_DEFAULT]
|
const summarizeLanguage = LANGUAGES_MAP[envData.summarizeLanguage??SUMMARIZE_LANGUAGE_DEFAULT]
|
||||||
const title = useAppSelector(state => state.env.title)
|
const title = useAppSelector(state => state.env.title)
|
||||||
|
const reviewed = useAppSelector(state => state.env.tempData.reviewed)
|
||||||
|
const reviewAction = useAppSelector(state => state.env.reviewAction)
|
||||||
|
const reviewActions = useAppSelector(state => state.env.tempData.reviewActions)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取下一个需要翻译的行
|
* 获取下一个需要翻译的行
|
||||||
@@ -139,6 +142,14 @@ const useTranslate = () => {
|
|||||||
}, [data?.body, envData, language.name, title, dispatch])
|
}, [data?.body, envData, language.name, title, dispatch])
|
||||||
|
|
||||||
const addSummarizeTask = useCallback(async (type: SummaryType, segment: Segment) => {
|
const addSummarizeTask = useCallback(async (type: SummaryType, segment: Segment) => {
|
||||||
|
//review action
|
||||||
|
if (reviewed === undefined && !reviewAction) {
|
||||||
|
dispatch(setReviewAction(true))
|
||||||
|
dispatch(setTempData({
|
||||||
|
reviewActions: (reviewActions ?? 0) + 1
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
if (segment.text.length >= SUMMARIZE_THRESHOLD) {
|
if (segment.text.length >= SUMMARIZE_THRESHOLD) {
|
||||||
let subtitles = ''
|
let subtitles = ''
|
||||||
for (const item of segment.items) {
|
for (const item of segment.items) {
|
||||||
@@ -199,7 +210,7 @@ const useTranslate = () => {
|
|||||||
}
|
}
|
||||||
}, [dispatch, envData, summarizeLanguage.name, title])
|
}, [dispatch, envData, summarizeLanguage.name, title])
|
||||||
|
|
||||||
const addAskTask = useCallback(async (segment: Segment, question: string) => {
|
const addAskTask = useCallback(async (id: string, segment: Segment, question: string) => {
|
||||||
if (segment.text.length >= SUMMARIZE_THRESHOLD) {
|
if (segment.text.length >= SUMMARIZE_THRESHOLD) {
|
||||||
let prompt: string = envData.prompts?.[PROMPT_TYPE_ASK]??PROMPT_DEFAULTS[PROMPT_TYPE_ASK]
|
let prompt: string = envData.prompts?.[PROMPT_TYPE_ASK]??PROMPT_DEFAULTS[PROMPT_TYPE_ASK]
|
||||||
// replace params
|
// replace params
|
||||||
@@ -243,10 +254,14 @@ const useTranslate = () => {
|
|||||||
// startIdx: segment.startIdx,
|
// startIdx: segment.startIdx,
|
||||||
apiKey: envData.apiKey,
|
apiKey: envData.apiKey,
|
||||||
geminiApiKey: envData.geminiApiKey,
|
geminiApiKey: envData.geminiApiKey,
|
||||||
|
askId: id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.debug('addAskTask', taskDef)
|
console.debug('addAskTask', taskDef)
|
||||||
dispatch(setAskStatus({status: 'pending'}))
|
dispatch(mergeAskInfo({
|
||||||
|
id,
|
||||||
|
status: 'pending'
|
||||||
|
}))
|
||||||
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))
|
||||||
}
|
}
|
||||||
@@ -304,9 +319,13 @@ const useTranslate = () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const handleAsk = useMemoizedFn((task: Task, content?: string) => {
|
const handleAsk = useMemoizedFn((task: Task, content?: string) => {
|
||||||
dispatch(setAskContent({content}))
|
dispatch(mergeAskInfo({
|
||||||
dispatch(setAskStatus({status: 'done'}))
|
id: task.def.extra.askId,
|
||||||
dispatch(setAskError({error: task.error}))
|
content,
|
||||||
|
status: 'done',
|
||||||
|
error: task.error,
|
||||||
|
}))
|
||||||
|
|
||||||
console.debug('setAsk', content, task.error)
|
console.debug('setAsk', content, task.error)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import {createSlice, PayloadAction} from '@reduxjs/toolkit'
|
import {createSlice, PayloadAction} from '@reduxjs/toolkit'
|
||||||
import {find} from 'lodash-es'
|
import {find, findIndex} from 'lodash-es'
|
||||||
import {getDevData} from '../util/biz_util'
|
import {getDevData} from '../util/biz_util'
|
||||||
import {DEFAULT_SERVER_URL_OPENAI, TOTAL_HEIGHT_DEF} from '../const'
|
import {DEFAULT_SERVER_URL_OPENAI, TOTAL_HEIGHT_DEF} from '../const'
|
||||||
|
|
||||||
@@ -39,14 +39,18 @@ interface EnvState {
|
|||||||
lastSummarizeTime?: number
|
lastSummarizeTime?: number
|
||||||
|
|
||||||
// ask
|
// ask
|
||||||
askFold?: boolean
|
asks: AskInfo[]
|
||||||
askQuestion?: string
|
|
||||||
askStatus: SummaryStatus
|
/**
|
||||||
askError?: string
|
* 是否输入中(中文)
|
||||||
askContent?: string
|
*/
|
||||||
|
inputting: boolean
|
||||||
|
|
||||||
searchText: string
|
searchText: string
|
||||||
searchResult: Set<number>
|
searchResult: Set<number>
|
||||||
|
|
||||||
|
//当前视频是否计算过操作
|
||||||
|
reviewAction: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialState: EnvState = {
|
const initialState: EnvState = {
|
||||||
@@ -61,7 +65,6 @@ const initialState: EnvState = {
|
|||||||
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,
|
||||||
@@ -71,8 +74,14 @@ const initialState: EnvState = {
|
|||||||
data: import.meta.env.VITE_ENV === 'web-dev' ? getDevData() : undefined,
|
data: import.meta.env.VITE_ENV === 'web-dev' ? getDevData() : undefined,
|
||||||
transResults: {},
|
transResults: {},
|
||||||
|
|
||||||
|
inputting: false,
|
||||||
|
|
||||||
searchText: '',
|
searchText: '',
|
||||||
searchResult: new Set(),
|
searchResult: new Set(),
|
||||||
|
|
||||||
|
asks: [],
|
||||||
|
|
||||||
|
reviewAction: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const slice = createSlice({
|
export const slice = createSlice({
|
||||||
@@ -94,6 +103,9 @@ export const slice = createSlice({
|
|||||||
...action.payload,
|
...action.payload,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
setReviewAction: (state, action: PayloadAction<boolean>) => {
|
||||||
|
state.reviewAction = action.payload
|
||||||
|
},
|
||||||
setTempReady: (state) => {
|
setTempReady: (state) => {
|
||||||
state.tempReady = true
|
state.tempReady = true
|
||||||
},
|
},
|
||||||
@@ -204,26 +216,20 @@ export const slice = createSlice({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setAskFold: (state, action: PayloadAction<boolean>) => {
|
addAskInfo: (state, action: PayloadAction<AskInfo>) => {
|
||||||
state.askFold = action.payload
|
state.asks.push(action.payload)
|
||||||
},
|
},
|
||||||
setAskQuestion: (state, action: PayloadAction<string | undefined>) => {
|
delAskInfo: (state, action: PayloadAction<string>) => {
|
||||||
state.askQuestion = action.payload
|
state.asks = state.asks.filter(ask => ask.id !== action.payload)
|
||||||
},
|
},
|
||||||
setAskContent: (state, action: PayloadAction<{
|
mergeAskInfo: (state, action: PayloadAction<PartialOfAskInfo>) => {
|
||||||
content?: any
|
const idx = findIndex(state.asks, {id: action.payload.id})
|
||||||
}>) => {
|
if (idx >= 0) {
|
||||||
state.askContent = action.payload.content
|
state.asks[idx] = {
|
||||||
},
|
...state.asks[idx],
|
||||||
setAskStatus: (state, action: PayloadAction<{
|
...action.payload,
|
||||||
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
|
||||||
@@ -288,16 +294,14 @@ export const slice = createSlice({
|
|||||||
setFold: (state, action: PayloadAction<boolean>) => {
|
setFold: (state, action: PayloadAction<boolean>) => {
|
||||||
state.fold = action.payload
|
state.fold = action.payload
|
||||||
},
|
},
|
||||||
|
setInputting: (state, action: PayloadAction<boolean>) => {
|
||||||
|
state.inputting = action.payload
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
export const {
|
export const {
|
||||||
setUrl,
|
setUrl,
|
||||||
setAskFold,
|
|
||||||
setAskQuestion,
|
|
||||||
setAskStatus,
|
|
||||||
setAskError,
|
|
||||||
setAskContent,
|
|
||||||
setTempReady,
|
setTempReady,
|
||||||
setTempData,
|
setTempData,
|
||||||
setUploadedTranscript,
|
setUploadedTranscript,
|
||||||
@@ -323,6 +327,7 @@ export const {
|
|||||||
setAutoTranslate,
|
setAutoTranslate,
|
||||||
setAutoScroll,
|
setAutoScroll,
|
||||||
setNoVideo,
|
setNoVideo,
|
||||||
|
setReviewAction,
|
||||||
setNeedScroll,
|
setNeedScroll,
|
||||||
setCurIdx,
|
setCurIdx,
|
||||||
setEnvData,
|
setEnvData,
|
||||||
@@ -335,6 +340,10 @@ export const {
|
|||||||
setFold,
|
setFold,
|
||||||
setSearchText,
|
setSearchText,
|
||||||
setSearchResult,
|
setSearchResult,
|
||||||
|
setInputting,
|
||||||
|
addAskInfo,
|
||||||
|
delAskInfo,
|
||||||
|
mergeAskInfo,
|
||||||
} = slice.actions
|
} = slice.actions
|
||||||
|
|
||||||
export default slice.reducer
|
export default slice.reducer
|
||||||
|
15
src/typings.d.ts
vendored
15
src/typings.d.ts
vendored
@@ -40,6 +40,8 @@ interface TempData {
|
|||||||
curSummaryType: SummaryType
|
curSummaryType: SummaryType
|
||||||
downloadType?: string
|
downloadType?: string
|
||||||
compact?: boolean // 是否紧凑视图
|
compact?: boolean // 是否紧凑视图
|
||||||
|
reviewActions?: number // 点击或总结行为达到一定次数后,显示评分(一个视频最多只加1次)
|
||||||
|
reviewed?: boolean // 是否点击过评分,undefined: 不显示;true: 已点击;false: 未点击(需要显示)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TaskDef {
|
interface TaskDef {
|
||||||
@@ -105,6 +107,17 @@ interface Summary {
|
|||||||
content?: any
|
content?: any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface AskInfo {
|
||||||
|
id: string
|
||||||
|
fold?: boolean
|
||||||
|
question: string
|
||||||
|
status: SummaryStatus
|
||||||
|
error?: string
|
||||||
|
content?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type PartialOfAskInfo = Partial<PartOfAskInfo>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 概览
|
* 概览
|
||||||
*/
|
*/
|
||||||
@@ -129,4 +142,4 @@ interface BriefSummary extends Summary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SummaryStatus = 'init' | 'pending' | 'done'
|
type SummaryStatus = 'init' | 'pending' | 'done'
|
||||||
type SummaryType = 'overview' | 'keypoint' | 'brief'
|
type SummaryType = 'overview' | 'keypoint' | 'brief' | 'question'
|
||||||
|
@@ -88,6 +88,9 @@ export const isSummaryEmpty = (summary: Summary) => {
|
|||||||
} else if (summary.type === 'brief') {
|
} else if (summary.type === 'brief') {
|
||||||
const content: string[] = summary.content??''
|
const content: string[] = summary.content??''
|
||||||
return content.length === 0
|
return content.length === 0
|
||||||
|
} else if (summary.type === 'question') {
|
||||||
|
const content: any[] = summary.content??[]
|
||||||
|
return content.length === 0
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -109,6 +112,11 @@ export const getSummaryStr = (summary: Summary) => {
|
|||||||
summary: ''
|
summary: ''
|
||||||
}
|
}
|
||||||
s += content.summary + '\n'
|
s += content.summary + '\n'
|
||||||
|
} else if (summary.type === 'question') {
|
||||||
|
const content: Array<{ q: string, a: string }> = summary.content ?? []
|
||||||
|
s += content.map(item => {
|
||||||
|
return item.q + '\n' + item.a + '\n'
|
||||||
|
}).join('\n')
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,10 @@
|
|||||||
import {SyntheticEvent} from 'react'
|
import {SyntheticEvent} from 'react'
|
||||||
|
|
||||||
|
export const isEdgeBrowser = () => {
|
||||||
|
const userAgent = navigator.userAgent.toLowerCase();
|
||||||
|
return userAgent.includes('edg/') && !userAgent.includes('edge/');
|
||||||
|
}
|
||||||
|
|
||||||
export const formatTime = (time: number) => {
|
export const formatTime = (time: number) => {
|
||||||
if (!time) return '00:00'
|
if (!time) return '00:00'
|
||||||
|
|
||||||
|
@@ -12,7 +12,7 @@ export default ({mode}) => {
|
|||||||
visualizer() as PluginOption,
|
visualizer() as PluginOption,
|
||||||
]
|
]
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (mode === 'production_chrome') {
|
if (mode === 'production_chrome' || mode === 'production_edge') {
|
||||||
plugins.push(crx({
|
plugins.push(crx({
|
||||||
manifest,
|
manifest,
|
||||||
}))
|
}))
|
||||||
|
Reference in New Issue
Block a user