11let transcript = [ ]
22let personNameBuffer = "" , transcriptTextBuffer = ""
33let beforePersonName = "" , beforeTranscriptText = ""
4- let meetingStartTimeStamp = new Date ( ) . toLocaleString ( )
4+ const options = {
5+ year : 'numeric' ,
6+ month : '2-digit' ,
7+ day : '2-digit' ,
8+ hour : '2-digit' ,
9+ minute : '2-digit' ,
10+ hour12 : true
11+ } ;
12+ let meetingStartTimeStamp = new Date ( ) . toLocaleString ( "default" , options ) . replace ( / [ / : ] / g, '-' )
13+ let meetingTitle = document . title
514const extensionStatusJSON_bug = {
615 "status" : 400 ,
716 "message" : "<strong>Transcripto seems to have an error</strong> <br /> Please report it <a href='https://github.com/vivek-nexus/transcripto/issues' target='_blank'>here</a>."
@@ -19,6 +28,11 @@ checkExtensionStatus().then(() => {
1928 const captionsButton = contains ( ".material-icons-extended" , "closed_caption_off" ) [ 0 ]
2029
2130 console . log ( "Meeting started" )
31+ setTimeout ( ( ) => {
32+ // pick up meeting name after a delay
33+ meetingTitle = updateMeetingTitle ( )
34+ } , 5000 ) ;
35+
2236 chrome . storage . sync . get ( [ "operationMode" ] , function ( result ) {
2337 if ( result . operationMode == "manual" )
2438 console . log ( "Manual mode selected, leaving transcript off" )
@@ -36,7 +50,7 @@ checkExtensionStatus().then(() => {
3650 observer . observe ( targetNode , config )
3751 chrome . storage . sync . get ( [ "operationMode" ] , function ( result ) {
3852 if ( result . operationMode == "manual" )
39- showNotification ( { status : 400 , message : "<strong>Transcripto is not running</strong> <br /> Turn on captions, if needed" } )
53+ showNotification ( { status : 400 , message : "<strong>Transcripto is not running</strong> <br /> Turn on captions using the CC icon , if needed" } )
4054 else
4155 showNotification ( extensionStatusJSON )
4256 } )
@@ -45,28 +59,27 @@ checkExtensionStatus().then(() => {
4559 showNotification ( extensionStatusJSON_bug )
4660 }
4761
62+ window . addEventListener ( "beforeunload" , beforeUnloadCallback )
63+
4864 contains ( ".google-material-icons" , "call_end" ) [ 0 ] . parentElement . addEventListener ( "click" , ( ) => {
49- if ( personNameBuffer != "" || transcriptTextBuffer != "" ) {
50- transcript . push ( {
51- "personName" : personNameBuffer ,
52- "personTranscript" : transcriptTextBuffer
53- } )
54- chrome . storage . local . set ( { transcript : transcript } , function ( ) { } )
55- }
65+ window . removeEventListener ( "beforeunload" , beforeUnloadCallback )
5666 observer . disconnect ( ) ;
57- console . log ( `Transcript length ${ transcript . length } ` )
58- if ( transcript . length > 0 )
59- downloadTranscript ( )
60- } )
61-
62- window . addEventListener ( "beforeunload" , function ( ) {
63- transcript . push ( {
64- "personName" : personNameBuffer ,
65- "personTranscript" : transcriptTextBuffer
66- } )
67- chrome . runtime . sendMessage ( { transcript : transcript } , function ( response ) {
68- console . log ( response ) ;
69- } ) ;
67+ if ( ( personNameBuffer != "" ) && ( transcriptTextBuffer != "" ) )
68+ pushToTranscript ( )
69+ chrome . storage . local . set (
70+ {
71+ transcript : transcript ,
72+ meetingTitle : meetingTitle ,
73+ meetingStartTimeStamp : meetingStartTimeStamp
74+ } ,
75+ function ( ) {
76+ console . log ( `Transcript length ${ transcript . length } ` )
77+ if ( transcript . length > 0 ) {
78+ chrome . runtime . sendMessage ( { type : "download" } , function ( response ) {
79+ console . log ( response ) ;
80+ } ) ;
81+ }
82+ } )
7083 } )
7184 }
7285 else {
@@ -160,41 +173,19 @@ const commonCSS = `background: rgb(255 255 255 / 25%);
160173 box-shadow: rgba(0, 0, 0, 0.16) 0px 10px 36px 0px, rgba(0, 0, 0, 0.06) 0px 0px 0px 1px;` ;
161174
162175
163-
164- function downloadTranscript ( ) {
165- // Create an array to store lines of the text file
166- const lines = [ ] ;
167-
168- // Iterate through the transcript array and format each entry
169- transcript . forEach ( entry => {
170- lines . push ( entry . personName ) ;
171- lines . push ( entry . personTranscript ) ;
172- lines . push ( '' ) ; // Add an empty line between entries
173- } ) ;
174-
175- lines . push ( "---" )
176- lines . push ( "Transcript generated using Transcripto Chrome extension" )
177-
178- // Join the lines into a single string
179- const textContent = lines . join ( '\n' ) ;
180-
181- // Create a Blob from the text content
182- const blob = new Blob ( [ textContent ] , { type : 'text/plain' } ) ;
183-
184- // Create a download notification
185- let html = document . querySelector ( "html" ) ;
186- let obj = document . createElement ( "div" ) ;
187- let downloadLink = document . createElement ( "a" )
188- downloadLink . setAttribute ( "id" , "transcript-download-button" )
189-
190- obj . prepend ( downloadLink )
191- if ( html ) {
192- html . append ( obj )
193- downloadLink . href = URL . createObjectURL ( blob ) ;
194- downloadLink . download = `Transcript-${ document . querySelector ( 'div[data-meeting-title]' ) ? document . querySelector ( 'div[data-meeting-title]' ) . getAttribute ( "data-meeting-title" ) : document . title } ${ meetingStartTimeStamp } .txt` ;
195-
196- downloadLink . click ( ) ;
197- }
176+ function beforeUnloadCallback ( ) {
177+ if ( ( personNameBuffer != "" ) && ( transcriptTextBuffer != "" ) )
178+ pushToTranscript ( )
179+ chrome . runtime . sendMessage (
180+ {
181+ type : "save_and_download" ,
182+ transcript : transcript ,
183+ meetingTitle : meetingTitle ,
184+ meetingStartTimeStamp : meetingStartTimeStamp ,
185+ } ,
186+ function ( response ) {
187+ console . log ( response )
188+ } )
198189}
199190
200191function transcriber ( mutationsList , observer ) {
@@ -215,11 +206,8 @@ function transcriber(mutationsList, observer) {
215206 }
216207 else {
217208 if ( personNameBuffer != currentPersonName ) {
218- transcript . push ( {
219- "personName" : personNameBuffer ,
220- "personTranscript" : transcriptTextBuffer
221- } )
222- chrome . storage . local . set ( { transcript : transcript } , function ( ) { } )
209+ pushToTranscript ( )
210+ overWriteChromeStorage ( )
223211 beforeTranscriptText = currentTranscriptText
224212 personNameBuffer = currentPersonName ;
225213 transcriptTextBuffer = currentTranscriptText ;
@@ -233,23 +221,45 @@ function transcriber(mutationsList, observer) {
233221 else {
234222 console . log ( "No active transcript" )
235223 if ( ( personNameBuffer != "" ) && ( transcriptTextBuffer != "" ) ) {
236- transcript . push ( {
237- "personName" : personNameBuffer ,
238- "personTranscript" : transcriptTextBuffer
239- } )
240- chrome . storage . local . set ( { transcript : transcript } , function ( ) { } )
224+ pushToTranscript ( )
225+ overWriteChromeStorage ( )
241226 }
242227 beforePersonName = ""
243228 beforeTranscriptText = ""
244229 personNameBuffer = ""
245230 transcriptTextBuffer = ""
246231 }
247232 console . log ( transcriptTextBuffer )
248- console . log ( transcript )
233+ // console.log(transcript)
249234 } )
250235 } , 500 ) ;
251236}
252237
238+ function pushToTranscript ( ) {
239+ transcript . push ( {
240+ "personName" : personNameBuffer ,
241+ "personTranscript" : transcriptTextBuffer
242+ } )
243+ }
244+
245+ function overWriteChromeStorage ( ) {
246+ chrome . storage . local . set ( {
247+ transcript : transcript ,
248+ meetingTitle : meetingTitle ,
249+ meetingStartTimeStamp : meetingStartTimeStamp
250+ } , function ( ) { } )
251+ }
252+
253+ function updateMeetingTitle ( ) {
254+ if ( document . querySelector ( ".u6vdEc" ) ) {
255+ const title = document . querySelector ( ".u6vdEc" ) . textContent
256+ const invalidFilenameRegex = / [ ^ \w \- _ . ( ) ] / g;
257+ return title . replace ( invalidFilenameRegex , '_' )
258+ }
259+ else
260+ return document . title
261+ }
262+
253263async function checkExtensionStatus ( ) {
254264 // Set default value as 200
255265 chrome . storage . local . set ( {
0 commit comments