MCPcopy Index your code
hub / github.com/RutvijDv/Meet-Script / whenSubtitleOn

Function whenSubtitleOn

content.js:83–131  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

81
82
83function whenSubtitleOn() {
84 chrome.storage.sync.set({
85 subtitleWarning: false,
86 meet_code: MEET_CODE
87 });
88 // DOM element containing all subtitles
89 const subtitleDiv = document.querySelector("div[jscontroller='TEjq6e']");
90
91
92 const subtitleObserver = new MutationObserver((mutations) => {
93
94 mutations.forEach((mutation) => {
95 if (mutation.target.classList && mutation.target.classList.contains("iTTPOb")) {
96 if (mutation.addedNodes.length) {
97 var newNodes = mutation.addedNodes;
98 var speaker = newNodes["0"]?.parentNode?.parentNode?.parentNode?.querySelector(".zs7s8d.jxFHg")?.textContent;
99 if (speaker) {
100 setTimeout(function () {
101 if (newNodes.length) {
102 if (last_speaker != speaker) {
103 script.push(speaker + " : " + newNodes["0"].innerText + "\r\n");
104 last_speaker = speaker;
105 } else {
106 var lastText = script.pop();
107 lastText = lastText.slice(0, -2);
108 lastText = lastText + newNodes["0"].innerText + "\r\n";
109 script.push(lastText);
110 }
111
112 chrome.storage.sync.set({
113 script: script,
114 })
115 }
116 }, 10000);
117 }
118
119 }
120 }
121 });
122 });
123
124 // Start observing subtitle div
125 subtitleObserver.observe(subtitleDiv, {
126 childList: true,
127 subtree: true,
128 attributes: false,
129 characterData: false,
130 });
131};

Callers 1

callStartsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected