| 81 | |
| 82 | |
| 83 | function 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 | }; |