@@ -5,28 +5,29 @@ export const config: PlasmoContentScript = {
5
5
}
6
6
7
7
chrome . runtime . onMessage . addListener ( ( message , sender , sendResponse ) => {
8
- if ( message . type === "fetchFullChat" ) {
9
- const matches = document . querySelectorAll ( ".group.w-full" )
10
- const chat = Array . from ( matches )
8
+ if ( message . type === "fetchFullChat" ) sendResponse ( fetchFullChat ( ) )
9
+ } )
11
10
12
- const rawPrompts = chat . filter ( ( el , index ) => index % 2 === 0 )
13
- const rawAnswers = chat . filter ( ( el , index ) => index % 2 === 1 )
11
+ const fetchFullChat = ( ) => {
12
+ const matches = document . querySelectorAll ( ".group.w-full" )
13
+ const chat = Array . from ( matches )
14
14
15
- const prompts = rawPrompts . map (
16
- ( el ) => el . querySelector ( ".whitespace-pre-wrap" ) ?. textContent
17
- )
18
- const answers = rawAnswers . map (
19
- ( el ) =>
20
- (
21
- el . querySelector ( ".markdown" ) ??
22
- el . querySelector ( ".dark.text-orange-500" )
23
- ) ?. innerHTML
24
- )
15
+ const rawPrompts = chat . filter ( ( el , index ) => index % 2 === 0 )
16
+ const rawAnswers = chat . filter ( ( el , index ) => index % 2 === 1 )
25
17
26
- const url = window . location . href
27
- const title = document . title
18
+ const prompts = rawPrompts . map (
19
+ ( el ) => el . querySelector ( ".whitespace-pre-wrap" ) ?. textContent
20
+ )
21
+ const answers = rawAnswers . map (
22
+ ( el ) =>
23
+ (
24
+ el . querySelector ( ".markdown" ) ??
25
+ el . querySelector ( ".dark.text-orange-500" )
26
+ ) ?. innerHTML
27
+ )
28
28
29
- const res = { prompts, answers, url, title }
30
- sendResponse ( res )
31
- }
32
- } )
29
+ const url = window . location . href
30
+ const title = document . title
31
+
32
+ return { prompts, answers, url, title }
33
+ }
0 commit comments