Skip to content

Instantly share code, notes, and snippets.

@ramene
Last active March 21, 2019 19:16
Show Gist options
  • Select an option

  • Save ramene/ede29c9c06fbde05f2aa163998e8a263 to your computer and use it in GitHub Desktop.

Select an option

Save ramene/ede29c9c06fbde05f2aa163998e8a263 to your computer and use it in GitHub Desktop.

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 will happen eventually.

Last tested: Jan, 15, 2019

How

  1. Go to the messages screen: LinkedIn Messages
  2. Open up your Chrome Console*
  3. Paste the following in the console
;(function () {
  setInterval(() => {
    let deleted = false;
    $('artdeco-dropdown-item').each((i, elem) => {
      let txt = $(elem).text().trim();
      if (txt === 'Yes, delete') {
        deleted = true;
        $(elem).click();
      }
    });
    if (deleted){
      setTimeout(() => $('.js-msg-delete').click(), 500)
    } else {
      $('.msg-conversation-card__list-action-icon').eq(1).click();
    }
  }, 1000);
}());

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

Caveats

  • You need to stay on the screen until it completes. It takes about 1 second per message. There is the possibility to speed it up, but this is the time that I found let each request be successful.
  • It can only delete actual messages. All "InMail" will be archived instead.
  • It can only delete messages that are in the current view. You have two options here:
    • Before pasting the script, scroll down your message list to reveal all messages
    • Run the script till the page is empty, then refresh and run it again.
    • Personally, I found that any more than about 200 messages caused the page to run super slow.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment