From 2ba841c8f2b452452e656953374f05e6b72d2f58 Mon Sep 17 00:00:00 2001 From: IndieKKY Date: Mon, 18 Mar 2024 19:17:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AD=97=E5=B9=95=E5=A4=8D?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/biz/MoreBtn.tsx | 12 +++++++----- src/chrome/content-script.cjs | 1 + src/hooks/useSubtitleService.ts | 3 ++- src/redux/envReducer.ts | 5 +++++ 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/biz/MoreBtn.tsx b/src/biz/MoreBtn.tsx index bda7928..538341e 100644 --- a/src/biz/MoreBtn.tsx +++ b/src/biz/MoreBtn.tsx @@ -66,6 +66,7 @@ const MoreBtn = (props: Props) => { const [moreVisible, setMoreVisible] = useState(false) const eventBus = useContext(EventBusContext) const segments = useAppSelector(state => state.env.segments) + const url = useAppSelector(state => state.env.url) const title = useAppSelector(state => state.env.title) const curSummaryType = useAppSelector(state => state.env.tempData.curSummaryType) @@ -76,19 +77,19 @@ const MoreBtn = (props: Props) => { let s, fileName if (!downloadType || downloadType === 'text') { - s = '' + s = `${title??'无标题'}\n${url??'无链接'}\n\n` for (const item of data.body) { s += item.content + '\n' } fileName = 'download.txt' } else if (downloadType === 'textWithTime') { - s = '' + s = `${title??'无标题'}\n${url??'无链接'}\n\n` for (const item of data.body) { s += formatTime(item.from) + ' ' + item.content + '\n' } fileName = 'download.txt' } else if (downloadType === 'article') { - s = '' + s = `${title??'无标题'}\n${url??'无链接'}\n\n` for (const item of data.body) { s += item.content + ', ' } @@ -138,9 +139,10 @@ const MoreBtn = (props: Props) => { s = JSON.stringify(data) fileName = 'download.json' } else if (downloadType === 'summarize') { + s = `${title??'无标题'}\n${url??'无链接'}\n\n` const [success, content] = getSummarize(title, segments, curSummaryType) if (!success) return - s = content + s += content fileName = '总结.txt' } else { return @@ -153,7 +155,7 @@ const MoreBtn = (props: Props) => { }).catch(console.error) } setMoreVisible(false) - }, [curSummaryType, data, downloadType, segments, title]) + }, [curSummaryType, data, downloadType, segments, title, url]) const downloadAudioCallback = useCallback(() => { window.parent.postMessage({ diff --git a/src/chrome/content-script.cjs b/src/chrome/content-script.cjs index c3189af..9b876f4 100644 --- a/src/chrome/content-script.cjs +++ b/src/chrome/content-script.cjs @@ -102,6 +102,7 @@ const refreshVideoInfo = async () => { //send setVideoInfo iframe.contentWindow.postMessage({ type: 'setVideoInfo', + url: location.origin + location.pathname, title, aid, pages, diff --git a/src/hooks/useSubtitleService.ts b/src/hooks/useSubtitleService.ts index 1328288..1afbae3 100644 --- a/src/hooks/useSubtitleService.ts +++ b/src/hooks/useSubtitleService.ts @@ -12,6 +12,7 @@ import { setSegments, setTitle, setTotalHeight, + setUrl, } from '../redux/envReducer' import {EventBusContext} from '../Router' import { @@ -55,6 +56,7 @@ const useSubtitleService = () => { if (data.type === 'setVideoInfo') { dispatch(setInfos(data.infos)) + dispatch(setUrl(data.url)) dispatch(setTitle(data.title)) console.debug('video title: ', data.title) } @@ -86,7 +88,6 @@ const useSubtitleService = () => { if (data.data.totalHeight) { dispatch(setTotalHeight(Math.min(Math.max(data.data.totalHeight, TOTAL_HEIGHT_MIN), TOTAL_HEIGHT_MAX))) } - console.debug('setSettings', data.data) } } diff --git a/src/redux/envReducer.ts b/src/redux/envReducer.ts index 736b781..d54f652 100644 --- a/src/redux/envReducer.ts +++ b/src/redux/envReducer.ts @@ -30,6 +30,7 @@ interface EnvState { data?: Transcript uploadedTranscript?: Transcript segments?: Segment[] + url?: string title?: string taskIds?: string[] @@ -260,6 +261,9 @@ export const slice = createSlice({ setCurrentTime: (state, action: PayloadAction) => { state.currentTime = action.payload }, + setUrl: (state, action: PayloadAction) => { + state.url = action.payload + }, setTitle: (state, action: PayloadAction) => { state.title = action.payload }, @@ -288,6 +292,7 @@ export const slice = createSlice({ }) export const { + setUrl, setAskFold, setAskQuestion, setAskStatus,