class CaptionCapture { constructor() { this.isCapturing = false; // Flag to control capturing this.intervalId = null; // Store interval reference this.lastCaption = ""; // Store last seen caption } // Function to detect and get the caption text detectCaption() { return document.querySelector('div[jsname="tgaKEf"]')?.innerText || ""; } // Function to start capturing captions startCapturing() { if (this.isCapturing) { console.log("Caption capturing is already running."); return; } this.isCapturing = true; console.log("Caption capturing started."); this.intervalId = setInterval(() => { let currentCaption = this.detectCaption(); if (currentCaption && currentCaption !== this.lastCaption) { console.log(currentCaption); this.lastCaption = currentCaption; // Update last seen caption } }, 1000); // Runs every 1 second } // Function to stop capturing captions stopCapturing() { if (!this.isCapturing) { console.log("Caption capturing is not running."); return; } this.isCapturing = false; clearInterval(this.intervalId); console.log("Caption capturing stopped."); } } // Usage: const captionCapture = new CaptionCapture(); // Start capturing: captionCapture.startCapturing(); // Stop capturing: captionCapture.stopCapturing();