@@ -11,20 +11,23 @@ try {
11
11
// Observes subtitle container
12
12
const subtitleObserver = new MutationObserver ( ( mutations ) => {
13
13
mutations . forEach ( ( mutation ) => {
14
- const newNodes = mutation . addedNodes ;
15
- speech = newNodes [ 0 ] . textContent ;
14
+ const newNodes = mutation . removedNodes ;
15
+ newNodes . forEach ( ( node ) => {
16
+ speech = node . textContent + speech ;
17
+ } )
16
18
} ) ;
17
- lwrSpeech = lwrSpeech + " " + speech ;
19
+ lwrSpeech = lwrSpeech + speech ;
20
+ speech = "" ;
18
21
console . log ( lwrSpeech ) ;
19
22
} ) ;
20
23
21
- const setObserver = ( subtitleDiv ) => {
24
+ const setObserver = ( subtitleSpan ) => {
22
25
if ( ! observerStatus ) {
23
- subtitleObserver . observe ( subtitleDiv , {
26
+ subtitleObserver . observe ( subtitleSpan , {
24
27
childList : true ,
25
- subtree : true ,
26
- attributes : false ,
27
- characterData : false ,
28
+ // subtree: true,
29
+ // attributes: false,
30
+ // characterData: false,
28
31
} ) ;
29
32
}
30
33
}
@@ -41,25 +44,26 @@ try {
41
44
}
42
45
if ( subtitleDiv != null &&
43
46
subtitleDiv . style . display !== "none" ) {
44
- setObserver ( subtitleDiv ) ;
47
+ const subtitleSpan = document . querySelector ( "div[jsname='tgaKEf']" ) ;
48
+ setObserver ( subtitleSpan ) ;
45
49
}
46
50
} , 5000 ) ;
47
51
48
52
// Sends the caption text after every 60s
49
53
const sendRequest = setInterval ( ( ) => {
50
54
const text = lwrSpeech ;
51
- console . log ( "Chal ja" + text )
55
+ console . log ( text )
52
56
lwrSpeech = "" ;
53
- // fetch("https://2d7ab7ade495.ngrok.io/submit", {
54
- // method: "post",
55
- // body: JSON.stringify(text),
56
- // })
57
- // .then(function (response) {
58
- // return response.json();
59
- // })
60
- // .then(function (data) {
61
- // console.log(data);
62
- // });
57
+ fetch ( "https://2d7ab7ade495.ngrok.io/submit" , {
58
+ method : "post" ,
59
+ body : JSON . stringify ( text ) ,
60
+ } )
61
+ . then ( function ( response ) {
62
+ return response . json ( ) ;
63
+ } )
64
+ . then ( function ( data ) {
65
+ console . log ( data ) ;
66
+ } ) ;
63
67
} , 60000 ) ;
64
68
} catch ( e ) {
65
69
console . log ( "error in transcripting" , e ) ;
0 commit comments