@@ -8,6 +8,10 @@ import type { Jimaku } from "./JimakuLine";
8
8
import { createPortal } from "react-dom" ;
9
9
import ButtonSwitchList from "./ButtonSwitchList" ;
10
10
import TailwindScope from "~components/TailwindScope" ;
11
+ import { toast } from "sonner/dist" ;
12
+ import { sendMessager } from "~utils/messaging" ;
13
+ import { sendForward } from "~background/forwards" ;
14
+ import { sleep } from "~utils/misc" ;
11
15
12
16
export type ButtonAreaProps = {
13
17
clearJimaku : VoidFunction
@@ -17,7 +21,7 @@ export type ButtonAreaProps = {
17
21
function ButtonArea ( { clearJimaku, jimakus } : ButtonAreaProps ) : JSX . Element {
18
22
19
23
const { settings, info } = useContext ( ContentContext )
20
- const { jimakuZone, buttonZone : btnStyle , jimakuPopupWindow } = useContext ( JimakuFeatureContext )
24
+ const { jimakuZone, buttonZone : btnStyle , jimakuPopupWindow, aiZone } = useContext ( JimakuFeatureContext )
21
25
22
26
const { order } = jimakuZone
23
27
const { enabledRecording } = settings [ "settings.features" ]
@@ -36,6 +40,16 @@ function ButtonArea({ clearJimaku, jimakus }: ButtonAreaProps): JSX.Element {
36
40
37
41
const [ show , setShow ] = useState ( ! info . isTheme )
38
42
43
+ const summerize = async ( ) => {
44
+ if ( jimakus . length < 10 ) {
45
+ toast . warning ( '至少需要有10条同传字幕才可总结。' )
46
+ return
47
+ }
48
+ await sendMessager ( 'open-tab' , { tab : 'summerizer' , params : { roomId : info . room } } )
49
+ await sleep ( 2000 )
50
+ sendForward ( 'pages' , 'jimaku-summarize' , jimakus . map ( j => j . text ) )
51
+ }
52
+
39
53
return (
40
54
< Fragment >
41
55
{ show && (
@@ -59,6 +73,11 @@ function ButtonArea({ clearJimaku, jimakus }: ButtonAreaProps): JSX.Element {
59
73
弹出同传视窗
60
74
</ JimakuButton >
61
75
}
76
+ { aiZone . enabled && (
77
+ < JimakuButton onClick = { summerize } >
78
+ 同传字幕AI总结
79
+ </ JimakuButton >
80
+ ) }
62
81
</ div >
63
82
) }
64
83
{ info . isTheme && document . querySelector ( upperHeaderArea ) !== null && createPortal (
0 commit comments