Skip to content

Instantly share code, notes, and snippets.

@timwco
Last active November 13, 2024 12:39
Show Gist options
  • Save timwco/d4536183c22a2f5a8c7c427df04acc90 to your computer and use it in GitHub Desktop.
Save timwco/d4536183c22a2f5a8c7c427df04acc90 to your computer and use it in GitHub Desktop.
LinkedIn: Delete Messages (June 2022)

What

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 happens often.

Last tested & verified working on: June, 10, 2022

Special Thanks to @noncent for the updated script.

* if you are not sure what this is, then this script is not for you.

/**
 * Warning - this script is made for education purpose only and must be run, executed on your own risk.
 * Author is not responsible for anything.
 * 
 * Delete all your old notifications from Linkedin
 * 
 * Step 1 - open link https://www.linkedin.com/notifications/
 * Step 2 - open browsers console panel by right click and inspect
 * Step 3 - go to console tab and paste script
 * Step 4 - Hit the enter
 */
[...document.querySelectorAll('[type="trash-icon"]')].map(x => x.click());

/**
 * Warning - this script is made for education purpose only and must be run, executed on your own risk.
 * Author is not responsible for anything.
 * 
 * URL - https://www.linkedin.com/messaging/thread/new/
 *
 * Delete all your old & archive messages from Linkedin
 *
 * Step 1 - open link https://www.linkedin.com/messaging/thread/new/
 * Step 2 - open browsers console panel by right click and inspect
 * Step 3 - go to console tab and paste script
 * Step 4 - Hit the enter and click yes when prompt for delete
 */
setInterval(function () {
    [...document.querySelectorAll(".msg-selectable-entity__checkbox-circle")].map(
        function (x) {
            x.click();
            setTimeout(function () {
                [...document.querySelectorAll('[type="trash-icon"]')].map(a => a.click());
            }, 1000);
        })
}, 3000);
@thetroublemaker
Copy link

Thanks for the lovely script :) but here is a very short script to manage things.

/**
 * Warning - this script is made for education purpose only and must be run, executed on your own risk.
 * Author is not responsible for anything.
 * 
 * Delete all your old notifications from Linkedin
 * 
 * Step 1 - open link https://www.linkedin.com/notifications/
 * Step 2 - open browsers console panel by right click and inspect
 * Step 3 - go to console tab and paste script
 * Step 4 - Hit the enter
 */
[...document.querySelectorAll('[type="trash-icon"]')].map(x => x.click());

/**
 * Warning - this script is made for education purpose only and must be run, executed on your own risk.
 * Author is not responsible for anything.
 * 
 * URL - https://www.linkedin.com/messaging/thread/new/
 *
 * Delete all your old & archive messages from Linkedin
 *
 * Step 1 - open link https://www.linkedin.com/messaging/thread/new/
 * Step 2 - open browsers console panel by right click and inspect
 * Step 3 - go to console tab and paste script
 * Step 4 - Hit the enter and click yes when prompt for delete
 */
setInterval(function () {
    [...document.querySelectorAll(".msg-selectable-entity__checkbox-circle")].map(
        function (x) {
            x.click();
            setTimeout(function () {
                [...document.querySelectorAll('[type="trash-icon"]')].map(a => a.click());
            }, 1000);
        })
}, 3000);

Cheers!!

Worked like a charm! Thank you @noncent! I'm pretty annoyed why such a basic functionality does not exist natively. I'm assuming it's some kind of marketing/behavior stunt.

@RELYVA
Copy link

RELYVA commented Jun 2, 2022

Does anybody know of a way to mass delete posts and comments from a LinkedIn account using scripts? Thanks for sharing these great tips.
Edited to add: I was advised by a prospective employer that my posts there are generally too political and that I might be well served to remove them all. Thanks for any help you might be able to offer.

@hajajm
Copy link

hajajm commented Jun 17, 2022

thanks , it worked

@definitelycarter
Copy link

I used this to bulk delete messages that are visible on the messages screen.

setInterval(async () => {
  new Array(...document.querySelectorAll('.ember-checkbox')).slice(0, 30).forEach(x => x.click());
  await new Promise(resolve => setTimeout(resolve, 1000));
  document.querySelector('[type=trash-icon]').click();
  await new Promise(resolve => setTimeout(resolve, 1000));
  document.querySelector('[aria-label="Yes, delete selected conversations"]').click()
}, 4000)

@darvinschmidt
Copy link

I would like to bulk delete messages in my inbox and archives by using a date range or anything on or before a date. Is there a script that can handle the date as a exclusionary criterion?

@mynameisneo7
Copy link

These both work:

/**
 * Warning - this script is made for education purpose only and must be run, executed on your own risk.
 * Author is not responsible for anything.
 * 
 * Delete all your old notifications from Linkedin
 * 
 * Step 1 - open link https://www.linkedin.com/notifications/
 * Step 2 - open browsers console panel by right click and inspect
 * Step 3 - go to console tab and paste script
 * Step 4 - Hit the enter
 */
[...document.querySelectorAll('[type="trash"]')].map(x => x.click());

/**
 * Warning - this script is made for education purpose only and must be run, executed on your own risk.
 * Author is not responsible for anything.
 * 
 * URL - https://www.linkedin.com/messaging/thread/new/
 *
 * Delete all your old & archive messages from Linkedin
 *
 * Step 1 - open link https://www.linkedin.com/messaging/thread/new/
 * Step 2 - open browsers console panel by right click and inspect
 * Step 3 - go to console tab and paste script
 * Step 4 - Hit the enter and click yes when prompt for delete
 */
setInterval(function () {
    [...document.querySelectorAll(".msg-selectable-entity__checkbox-circle")].map(
        function (x) {
            x.click();
            setTimeout(function () {
                [...document.querySelectorAll('[type="trash"]')].map(a => a.click());
            }, 1000);
        })
}, 4000);

I only changed trash-icon to trash and increased the interval from 3 seconds to 4 because the list would sometimes load a bit slow.

YMMV.

@efriedli
Copy link

And if you only want to mass-archive:

/**
 * Warning - this script is made for education purpose only and must be run, executed on your own risk.
 * Author is not responsible for anything.
 * 
 * URL - https://www.linkedin.com/messaging/thread/new/
 *
 * Delete all your old & archive messages from Linkedin
 *
 * Step 1 - open link https://www.linkedin.com/messaging/thread/new/
 * Step 2 - open browsers console panel by right click and inspect
 * Step 3 - go to console tab and paste script
 * Step 4 - Hit the enter and click yes when prompt for delete
 */
setInterval(function () {
    [...document.querySelectorAll(".msg-selectable-entity__checkbox-circle")].map(
        function (x) {
            x.click();
            setTimeout(function () {
                [...document.querySelectorAll('[type="archive-message-icon"]')].map(a => a.click());
            }, 1000);
        })
}, 4000);

@red-mage-admin
Copy link

red-mage-admin commented Mar 4, 2023

Nicely done, ended up following the tweaks @mynameisneo7 made to type "trash" and just needed to click "Delete" in pop-up for however many messages were actually loaded on screen during script-run:

/**
 * Warning - this script is made for education purpose only and must be run, executed on your own risk.
 * Author is not responsible for anything.
 * 
 * URL - https://www.linkedin.com/messaging/thread/new/
 *
 * Delete all your old & archive messages from Linkedin
 *
 * Step 1 - open link https://www.linkedin.com/messaging/thread/new/
 * Step 2 - open browsers console panel by right click and inspect
 * Step 3 - go to console tab and paste script
 * Step 4 - Hit the enter and click yes when prompt for delete
 */
setInterval(function () {
    [...document.querySelectorAll(".msg-selectable-entity__checkbox-circle")].map(
        function (x) {
            x.click();
            setTimeout(function () {
                [...document.querySelectorAll('[type="trash"]')].map(a => a.click());
            }, 1000);
        })
}, 4000);

@airhartm
Copy link

The notification script does not seem to do anything in my Chrome browser console now.

@spec8320
Copy link

spec8320 commented Apr 18, 2023

After some fixes working like a charm:

/**
 * Warning - this script is made for education purpose only and must be run, executed on your own risk.
 * Author is not responsible for anything.
 * 
 * Delete all your old notifications from Linkedin
 * 
 * Step 1 - open link https://www.linkedin.com/notifications/
 * Step 2 - open browsers console panel by right click and inspect
 * Step 3 - go to console tab and paste script
 * Step 4 - Hit the enter
 */
[...document.querySelectorAll('[type="trash-icon"]')].map(x => x.click());

/**
 * Warning - this script is made for education purpose only and must be run, executed on your own risk.
 * Author is not responsible for anything.
 * 
 * URL - https://www.linkedin.com/messaging/thread/new/
 *
 * Delete all your old & archive messages from Linkedin
 *
 * Step 1 - open link https://www.linkedin.com/messaging/thread/new/
 * Step 2 - open browsers console panel by right click and inspect
 * Step 3 - go to console tab and paste script
 * Step 4 - Hit the enter and click yes when prompt for delete
 */
setInterval(function () {
    [...document.querySelectorAll(".msg-selectable-entity__checkbox-circle")].map(
        function (x) {
            x.click();
            setTimeout(function () {
                [...document.querySelectorAll('[type="trash"]')].map(a => a.click());
				setTimeout(function () {
					[...document.querySelectorAll('[aria-label="Yes, delete selected conversations"]')].map(a => a.click());
				}, Math.floor(Math.random() * (5000 - 3000 + 1) + 3000));
            }, Math.floor(Math.random() * (5000 - 3000 + 1) + 3000));
        })
}, Math.floor(Math.random() * (7000 - 5000 + 1) + 5000));

@chrishough
Copy link

chrishough commented May 30, 2023

I had to make modifications to this, and it worked somewhat well, just does take forever with their limits

/**
 * Warning - this script is made for education purpose only and must be run, executed on your own risk.
 * Author is not responsible for anything.
 * 
 * Delete all your old notifications from Linkedin
 * 
 * Step 1 - open link https://www.linkedin.com/notifications/
 * Step 2 - open browsers console panel by right click and inspect
 * Step 3 - go to console tab and paste script
 * Step 4 - Hit the enter
 */
[...document.querySelectorAll('[type="trash-icon"]')].map(x => x.click());

/**
 * Warning - this script is made for education purpose only and must be run, executed on your own risk.
 * Author is not responsible for anything.
 * 
 * URL - https://www.linkedin.com/messaging/thread/new/
 *
 * Delete all your old & archive messages from Linkedin
 *
 * Step 1 - open link https://www.linkedin.com/messaging/thread/new/
 * Step 2 - open browsers console panel by right click and inspect
 * Step 3 - go to console tab and paste script
 * Step 4 - Hit the enter and click yes when prompt for delete
 */
setInterval(function () {
    [...document.querySelectorAll(".msg-selectable-entity__checkbox-circle")].map(
        function (x) {
            x.click();
            setTimeout(function () {
                [...document.querySelectorAll('[type="trash"]')].map(a => a.click());
				setTimeout(function () {
					[...document.querySelectorAll('[aria-label="Yes, delete selected conversations"]')].map(a => a.click());
				}, Math.floor(Math.random() * (6000 - 3000 + 1) + 3000));
            }, Math.floor(Math.random() * (6000 - 3000 + 1) + 3000));
        })
}, Math.floor(Math.random() * (8000 - 5000 + 1) + 5000));```

@kringg
Copy link

kringg commented Sep 30, 2024

Updated for LinkedIn 2024:

setInterval(function () {
    [...document.querySelectorAll(".msg-selectable-entity__checkbox-circle")].map(
        function (x) {
            x.click();
            setTimeout(function () {
                [...document.querySelectorAll('[title="Delete"]')].map(a => a.click());
				setTimeout(function () {
					[...document.querySelectorAll('[aria-label="Yes, delete selected conversations"]')].map(a => a.click());
				}, Math.floor(Math.random() * 2001 + 3000));
            }, Math.floor(Math.random() * 2001 + 3000));
        })
}, Math.floor(Math.random() * 2001 + 5000));

@mkmt22
Copy link

mkmt22 commented Nov 13, 2024

Updated for LinkedIn 2024:

setInterval(function () {
    [...document.querySelectorAll(".msg-selectable-entity__checkbox-circle")].map(
        function (x) {
            x.click();
            setTimeout(function () {
                [...document.querySelectorAll('[title="Delete"]')].map(a => a.click());
				setTimeout(function () {
					[...document.querySelectorAll('[aria-label="Yes, delete selected conversations"]')].map(a => a.click());
				}, Math.floor(Math.random() * 2001 + 3000));
            }, Math.floor(Math.random() * 2001 + 3000));
        })
}, Math.floor(Math.random() * 2001 + 5000));

@kringg Is there a way to update this so that it archives messages instead of deletes them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment