Last active
August 21, 2024 23:21
-
-
Save alexreardon/6f48c58720c682ed752d6215c6b9d10b to your computer and use it in GitHub Desktop.
Clear all unread slack notifications
This file contains hidden or 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
// 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