Skip to content

Instantly share code, notes, and snippets.

@alexreardon
Last active August 21, 2024 23:21
Show Gist options
  • Save alexreardon/6f48c58720c682ed752d6215c6b9d10b to your computer and use it in GitHub Desktop.
Save alexreardon/6f48c58720c682ed752d6215c6b9d10b to your computer and use it in GitHub Desktop.
Clear all unread slack notifications
// A simple script to clear all notifications in Slack.
// 1. Open Slack on the web (not in the app as you cannot open the dev tools console)
// 2. Copy paste into your console
(async () => {
function goToNotifications() {
const button = document.querySelector('[data-qa="tab_rail_activity_button"]');
if (!(button instanceof HTMLElement)) {
throw Error('Count not find activities button');
}
button.click();
}
function showUnreadNotifications() {
const button = document.querySelector('.p-unreads_toggle');
if (!(button instanceof HTMLElement)) {
throw Error('Count not find unreads toggle');
}
button.click();
}
async function sleep(ms) {
return new Promise(resolve => {
setTimeout(() => resolve(), ms);
});
}
async function clickNextNotification() {
const next = document.querySelector('.c-message_kit__hover');
if (!next) {
return;
}
// looks like the event listener is registered on this element
const child = next.firstElementChild;
if (!(child instanceof HTMLElement)) {
throw new Error('Could not find notification target');
}
child.click();
// giving time for re-render
await sleep(200);
await clickNextNotification();
}
console.log('Going to notifications');
goToNotifications();
await sleep(200);
console.log('Showing unreads');
showUnreadNotifications();
console.log('Exhausting notifications');
await sleep(200);
await clickNextNotification();
console.log('DONE');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment