Skip to content

Instantly share code, notes, and snippets.

@fine-fiddle
Last active February 22, 2024 16:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fine-fiddle/3bfc8d61027a0d7a22c141cfe3feecf5 to your computer and use it in GitHub Desktop.
Save fine-fiddle/3bfc8d61027a0d7a22c141cfe3feecf5 to your computer and use it in GitHub Desktop.
Read All Teams Chats
/*
* MS Teams lacks a "mark all as read" function, and doing it manually is arduous.
* This is the start of userscript to do it automatically. (for teams.microsoft.com)
*
* Teams 'lazy-loads' chats, so click the filter search, then the elipses, and sort by unread.
* Next, scroll to the bottom of your unread chats. Then you can run this script.
*/
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function readAllChats() {
var unreadItems = document.querySelectorAll("a.left-rail-unread.ts-unread-channel");
for (index=0; index < unreadItems.length; index++) {
console.info("autoclicking the chat: %s", unreadItems[index].title);
unreadItems[index].click();
await sleep(1700);
}
}
readAllChats()
/* Why did you write it like this?
* - Why click them one by one?
* The teams client doesn't tell the server to mark the thread 'read' until the contents have loaded in the client.
* It can take over a second to load the thread.
* I havent found how to call the method to tell the server to mark it read directly.
*
* - Why the iteration variable loop?
* if you want to use a promise for sleep, you can't use a .foreach()
* I don't know javascript
*
* - Why do i have to manually click the filter + sort by new thing
* I haven't spent the time to script the filter/sortbynew
*/
@feuertier
Copy link

Where is this executed?

@fine-fiddle
Copy link
Author

in the javascript console of the web browser. I haven't been keeping it up to date so it might need some modifications to get it working, and also I think the new teams has a feature to do this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment