LinkedIn is a valuable resource, but sometimes it sucks. One of those times is when you want to delete messages. You have to select each message one by one. It takes about 4 "clicks" to successfully delete a message.
This script should help. Since LI requires you to perform multiple steps, I decided to automate it for you. Once you initiate the script, it will run every second. If a message has the ability to be deleted, it will be. If not, it will be archived. Some "InMail" messages cannot be deleted on the web app. This script should work as long as LI doesn't change their page layout or element names, which will happen eventually.
Last tested & verified working on: April, 07, 2021
Special Thanks to @lifedup for the updated script.
- You can run this on the messages page.
- It automatically trys to load around 200 messages then it selects them to be deleted. You have to click the trash icon at the top after they are selected.
- It sometimes skips messages or if you have a lot of them you will need to run it again. If someone wanted to fix and join the OG way with the load messages function of this it would technically delete all of the messages by itself.
- Go to the messages screen: LinkedIn Messages
- Open up your Chrome Console*
- Paste the following in the console, and keep an eye on the console.
* if you are not sure what this is, then this script is not for you.
const delMsgs = async () => {
const container = document.querySelector('.msg-conversations-container ul');
if (!container) {
console.log('no messages - are you on the messages page?');
return;
}
const loadAllMessages = async () => {
return await new Promise((resolve) => {
let height = 0;
let attempts = 0;
if (container) {
console.log('loading messages...');
const interval = setInterval(() => {
const { scrollHeight } = container;
if (scrollHeight > 20000) {
console.log(
'limited to around 200 messages...'
);
clearInterval(interval);
resolve();
}
if (scrollHeight === height) {
if (attempts >= 3) {
console.log('messages loaded...');
clearInterval(interval);
resolve();
} else {
console.log('...');
attempts++;
}
}
height = scrollHeight;
container.scrollTop = scrollHeight;
}, 1000);
} else {
console.log('no messages');
}
});
};
await loadAllMessages();
console.log('attempting to select all messages');
const labels = container.getElementsByTagName('label');
for (let i = 0; i < labels.length; i++) {
if (labels[i]) {
labels[i].click();
}
}
console.log('Click the trash can icon at the top to delete all messages.');
console.log('type "delMsgs()" below this and then hit enter to run again.');
};
delMsgs();