Skip to content

Instantly share code, notes, and snippets.

@astrarudra
Last active July 1, 2024 01:16
Show Gist options
  • Save astrarudra/1263ffa4953804c4107bb9beb7b1d4da to your computer and use it in GitHub Desktop.
Save astrarudra/1263ffa4953804c4107bb9beb7b1d4da to your computer and use it in GitHub Desktop.
WhatsApp - Delete Ads/Business Chats (No App, No Root - Only Browser) - This script deletes all business chats from WhatsApp Web. It is useful since most business chats are spam and are not useful. This script is to be run in the console of the WhatsApp Web page.
/*
Author: Rudra Roy
Tutodial/Demo: https://www.youtube.com/watch?v=KsMNGolq-Fs
Description:
This script deletes all business chats from WhatsApp Web.
It is usefulsince most business chats are spam and are not useful.
This script is to be run in the console of the WhatsApp Web page.
*/
const contextMenuEvent = new MouseEvent("contextmenu", {
bubbles: true,
cancelable: true,
view: window,
button: 2, // 2 represents the right mouse button
});
const getDeleteButton = async (el) => {
el.dispatchEvent(contextMenuEvent)
await new Promise(resolve => setTimeout(resolve, 200));
let delButton = document.querySelector('[aria-label="Delete chat"')
if(!delButton) {
return getDeleteButton(el) // Retry
}
else return delButton
}
const deleteChats = async () => {
let businessChats = document.querySelectorAll("[data-icon=psa-verified]");
console.log(businessChats, "businessChats")
for await (let chat of businessChats) {
delButton = await getDeleteButton(chat)
delButton.click()
await new Promise(resolve => setTimeout(resolve, 200));
model = document.querySelector('[aria-label="Delete this chat?"')
model.querySelectorAll('button')[1].click()
await new Promise(resolve => setTimeout(resolve, 200));
}
chats.style.overflow = 'auto';
}
chats = document.getElementById('pane-side')
chats.style.overflow = "initial"
setTimeout(deleteChats, 500)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment