@@ -20,11 +20,41 @@ chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
20
20
meetId = url . split ( '?' ) [ 0 ] . split ( '/' ) . pop ( ) ;
21
21
} ) ;
22
22
23
+ const reactToSelectedChats = ( ) => {
24
+ // remove the class selectedChatStart and selectedChatEnd from all the divs
25
+ const chatInstances = document . querySelectorAll ( ".youChatInstance, .interviewerChatInstance" ) ;
26
+ chatInstances . forEach ( chatInstance => {
27
+ chatInstance . classList . remove ( "selectedChatStart" ) ;
28
+ chatInstance . classList . remove ( "selectedChatEnd" ) ;
29
+ } ) ;
30
+ // find the startChat and endChat divs and add the class selectedChatStart and selectedChatEnd respectively
31
+ if ( startChat !== null ) {
32
+ const startChatInstance = document . querySelector ( `[ticid="${ chat [ startChat ] . ticId } "]` ) ;
33
+ startChatInstance . classList . add ( "selectedChatStart" ) ;
34
+ }
35
+ if ( endChat !== null ) {
36
+ const endChatInstance = document . querySelector ( `[ticid="${ chat [ endChat ] . ticId } "]` ) ;
37
+ endChatInstance . classList . add ( "selectedChatEnd" ) ;
38
+ }
39
+
40
+ startContentEx . innerText = startChat !== null ? chat [ startChat ] . content : "" ;
41
+ endContentEx . innerText = endChat !== null ? chat [ endChat ] . content : "" ;
42
+
43
+ if ( startChat !== null && endChat !== null ) {
44
+ generateResponseBtn . disabled = false ;
45
+ } else {
46
+ generateResponseBtn . disabled = true ;
47
+ }
48
+ }
49
+
23
50
const generateResponseBtn = document . getElementById ( "gernerateResponse" ) ;
24
51
// add event listener to the button of id gernerateResponse
25
52
generateResponseBtn . addEventListener ( "click" , function ( ) {
26
53
// send a message to the service worker of type "GENERATE_RESPONSE" with the startChat and endChat
27
54
chrome . runtime . sendMessage ( { type : "GET_RESPONSE" , data : { meetId, startChat, endChat } } ) ;
55
+ startChat = null ;
56
+ endChat = null ;
57
+ reactToSelectedChats ( ) ;
28
58
} )
29
59
30
60
@@ -34,31 +64,18 @@ const selectChatInstance = (targetChatInstanceElement) => {
34
64
const chatIndex = chat . findIndex ( chatInstance => chatInstance . ticId === targetTicId ) ;
35
65
if ( startChat === null ) {
36
66
startChat = chatIndex ;
37
- targetChatInstanceElement . classList . add ( "selectedChatStart" ) ;
38
67
} else if ( endChat === null ) {
39
- endChat = chatIndex ;
40
- targetChatInstanceElement . classList . add ( "selectedChatEnd" ) ;
41
- } else {
42
- // find startChat and endChat divs and remove their respective classes
43
- const startChatDiv = document . querySelector ( `[ticId="${ chat [ startChat ] . ticId } "]` ) ;
44
- const endChatDiv = document . querySelector ( `[ticId="${ chat [ endChat ] . ticId } "]` ) ;
45
- startChatDiv . classList . remove ( "selectedChatStart" ) ;
46
- endChatDiv . classList . remove ( "selectedChatEnd" ) ;
47
- startChat = null ;
48
- endChat = null ;
49
- }
50
-
51
- console . log ( "startChat" , startChat , "endChat" , endChat )
52
- // updated the startContentEx and endContentEx with the content of the chatInstance
53
- startContentEx . innerText = startChat !== null ? chat [ startChat ] . content : "" ;
54
- endContentEx . innerText = endChat !== null ? chat [ endChat ] . content : "" ;
55
- // if both start chat and end chat exist then enable the generateResponseBtn
56
- if ( startChat !== null && endChat !== null ) {
57
- generateResponseBtn . disabled = false ;
68
+ if ( chatIndex < startChat ) {
69
+ startChat = chatIndex ;
70
+ } else {
71
+ endChat = chatIndex ;
72
+ }
58
73
} else {
59
- generateResponseBtn . disabled = true ;
74
+ startChat = null
75
+ endChat = null
60
76
}
61
-
77
+
78
+ reactToSelectedChats ( ) ;
62
79
}
63
80
64
81
0 commit comments