Created
August 31, 2024 16:23
-
-
Save carcigenicate/9b721146a7ab923268616301f32edfff to your computer and use it in GitHub Desktop.
Preventing the Teams Web App from marking you as Away every five seconds.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Teams Activity | |
// @namespace http://tampermonkey.net/ | |
// @version 2024-08-29 | |
// @author Carcigenicate | |
// @match https://teams.microsoft.com/v2/ | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
const periodMs = 1000 * 60; | |
function interactWithPage() { | |
const targetElement = document.querySelector('button[aria-label="Chat"]'); | |
// 'mousemove' and { bubbles: true } both appear to be the best solution | |
targetElement.dispatchEvent(new Event('mousemove', { bubbles: true })); | |
} | |
window.onload = () => { | |
let intervalTimer; | |
let isEnabled = true; | |
const toggleButton = document.createElement('button'); | |
toggleButton.style.position = 'absolute'; | |
toggleButton.style.top = '1.5rem'; | |
toggleButton.style.right = '50rem'; | |
document.body.appendChild(toggleButton); | |
function enable() { | |
toggleButton.innerText = 'Enabled'; | |
toggleButton.style.backgroundColor = 'green'; | |
intervalTimer = setInterval(() => { | |
interactWithPage(); | |
}, periodMs); | |
toggleButton.onclick = disable; | |
} | |
function disable() { | |
toggleButton.innerText = 'Disabled'; | |
toggleButton.style.backgroundColor = 'red'; | |
if (intervalTimer) { | |
clearInterval(intervalTimer); | |
intervalTimer = undefined; | |
} | |
toggleButton.onclick = enable; | |
} | |
enable(); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was recently forced to switch to the web app, which annoyingly puts me as Away constantly; even as I'm using my machine.
To fix that, I wrote the following Tampermonkey Userscript that allows for disabling the auto-Away "feature" by spoofing mouse movement in the window once per minute. I'll share it here in case anyone else is in the same case as me where they need to use Teams for work, but also have enough control over their machine where Userscripts are allowed.
Basically what is does is start a timer that, once per minute while enabled, spoofs a mousemove event on the "Chat" button on the left-hand side of the screen. This is enough to trick Teams into thinking that you're there. It also spawns an Enable/Disable button in the top bar to allow disabling the functionality if you are in fact leaving your desk and want it to allow you do go Away.