Skip to content

Commit 20a751f

Browse files
Improved transcripting of chrome-extension
1 parent 159adff commit 20a751f

File tree

4 files changed

+30
-26
lines changed

4 files changed

+30
-26
lines changed

Chrome-extension/captionreader.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,23 @@ try {
1111
// Observes subtitle container
1212
const subtitleObserver = new MutationObserver((mutations) => {
1313
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+
})
1618
});
17-
lwrSpeech=lwrSpeech+" "+speech;
19+
lwrSpeech=lwrSpeech+speech;
20+
speech="";
1821
console.log(lwrSpeech);
1922
});
2023

21-
const setObserver = (subtitleDiv) => {
24+
const setObserver = (subtitleSpan) => {
2225
if (!observerStatus){
23-
subtitleObserver.observe(subtitleDiv, {
26+
subtitleObserver.observe(subtitleSpan, {
2427
childList: true,
25-
subtree: true,
26-
attributes: false,
27-
characterData: false,
28+
// subtree: true,
29+
// attributes: false,
30+
// characterData: false,
2831
});
2932
}
3033
}
@@ -41,25 +44,26 @@ try {
4144
}
4245
if (subtitleDiv != null &&
4346
subtitleDiv.style.display !== "none"){
44-
setObserver(subtitleDiv);
47+
const subtitleSpan = document.querySelector("div[jsname='tgaKEf']");
48+
setObserver(subtitleSpan);
4549
}
4650
}, 5000);
4751

4852
// Sends the caption text after every 60s
4953
const sendRequest = setInterval(() => {
5054
const text = lwrSpeech;
51-
console.log("Chal ja"+text)
55+
console.log(text)
5256
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+
});
6367
}, 60000);
6468
} catch (e) {
6569
console.log("error in transcripting", e);

0 commit comments

Comments
 (0)