Skip to content

Instantly share code, notes, and snippets.

@alimohammad1995
Created August 6, 2022 08:59
Show Gist options
  • Save alimohammad1995/a1fb2b5db3a059c581a91d8077798cf6 to your computer and use it in GitHub Desktop.
Save alimohammad1995/a1fb2b5db3a059c581a91d8077798cf6 to your computer and use it in GitHub Desktop.
Whatsapp message removal
/*
[USE IT WELL]
This script will remove your messages in the Whatsapp. First it removes your old messages and then checking for new messages (Every 15 seconds) and remove them too.
1. Open https://web.whatsapp.com/ and follow the login instruction
2. Open chrome console (Use F12)
3. Copy the code below and paste it in the console and press `Enter`
4. Click on the thread that you want to delete your messages
CAUTION:
1. If you're clicking on a new thread, your messages there are gonna be removed!
2. This script will also remove all the new the new messages you're sending as long as you're keeping the Whatsapp tab open on your browser.
NOTE:
For disabling the script, just close the browser or refresh the page.
*/
const message_container_selector = '.message-out';
const message_text_selector = '[data-testid="msg-container"]';
const message_options_selector = '[data-testid="down-context"]';
const message_delete_option_selector = '[data-testid="mi-msg-delete"]';
const message_reply_option_selector = '[data-testid="mi-msg-reply"]';
const message_delete_confirmation_parent_selector = '[data-testid="popup-controls-revoke"]'
const message_delete_confirmation_button_selector = '[data-testid="content"]';
const sleep_time = 100;
function sleep(time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
function list_selector(selector) {
return Array.from(document.querySelectorAll(selector))
}
function selector(parent, selector) {
return parent.querySelector(selector)
}
async function delete_messages(start, count) {
let message_containers = list_selector(message_container_selector);
let total_count = 0;
for (let i = message_containers.length - 1; i >= 0; i--) {
let message_container = message_containers[i];
let message_text = selector(message_container, message_text_selector);
let event = new MouseEvent('mouseover', {
'view': window,
'bubbles': true,
'cancelable': true
});
message_text.dispatchEvent(event);
await sleep(sleep_time);
let message_options = selector(message_text, message_options_selector);
message_options.click();
await sleep(sleep_time);
let reply_option_menu = list_selector(message_reply_option_selector);
if (reply_option_menu.length === 0) {
continue;
}
let delete_option_menu = selector(document, message_delete_option_selector);
delete_option_menu.click();
await sleep(sleep_time);
let delete_button = selector(document, message_delete_confirmation_parent_selector);
if (delete_button == null) {
continue;
}
delete_button = selector(delete_button, message_delete_confirmation_button_selector);
delete_button.click();
await sleep(sleep_time);
if (total_count++ >= count) {
break;
}
}
}
setInterval(function () { delete_messages(100); }, 15 * 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment