Categories
Work hacks

Teams captions monitor

Do you want to get notified when someone mentions you in Microsoft Teams? Mainly when you can miss it if you focus on something else!

First, turn on live captions in MS Teams.

Then, just type the following in the Javascript console in your browser

// Select the div element to be monitored
// This div may change later, so use devtools inspector to find DIV which wrapps all captions
var div = document.querySelector('div[data-tid="closed-captions-renderer"]');

// Variable to keep track of the last time the alert was shown
var lastAlertTime = 0;

// Set an interval to check the contents of the div every 500 milliseconds
setInterval(function() {
    // Get the current time
    var currentTime = Date.now();
    
    // Get the contents of the div
    var divContent = div.textContent;
    
    // Check if the div contains either "Michal" or "Michael"
    if (divContent.includes("Michal") || divContent.includes("Michael")) {
        // Check if more than 5 seconds have passed since the last alert
        if (currentTime - lastAlertTime > 5000) {
            // If more than 5 seconds have passed, show the alert, or do whatever you like! But alert should make browser tab focused.
            alert("They are searching for you!");
            
            // Update the last alert time
            lastAlertTime = currentTime;
        }
    }
}, 500);

Then you get a browser alert when someone mentions your name (Michal or Michael)