Skip to content

Instantly share code, notes, and snippets.

@bradlucas
Forked from timwco/delete.md
Created March 26, 2021 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradlucas/385e5e77549851f2f6c3e4465f3f96ab to your computer and use it in GitHub Desktop.
Save bradlucas/385e5e77549851f2f6c3e4465f3f96ab to your computer and use it in GitHub Desktop.
LinkedIn: Delete Messages (April 2020)

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: April, 29, 2020

Setup & Cavets

  1. Since we use word matching, make sure to update the ARCHIVE and DELETE vars to your language.
  2. Some people only want to Archive and not Delete the messages, select this by updating the METHOD var.
  3. BEFORE pasting the script, make sure you've manually scrolled as far as you can so more messages are loaded, and you've clicked on one of the messages so the message contant pane is visible.
  4. 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. Also, deleting takes a bit longer.
  5. 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.

How

  1. Go to the messages screen: LinkedIn Messages
  2. Open up your Chrome Console*
  3. Paste the following in the console

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

(function() {

  // Set Your Language Here
  const ARCHIVE = "Archive";
  const DELETE = "Delete";


  // Would you like to Archive them or Delete messages?
  // Archive = 1, Delete = 2
  const METHOD = 1;


  const goneFn = () => {
    const timer = setInterval(() => {
      const dropdown = document.querySelector('.msg-thread-actions__control');

      if (!dropdown) return clearInterval(timer);


      dropdown.click(); // Opens Up Menu

      const dropdownItems = document.querySelectorAll('.msg-thread-actions__dropdown-option');

      for (let i = 0; i < dropdownItems.length; i++) {
        let txt = dropdownItems[i].textContent.trim();

        // Delete Items
        if (txt === DELETE && METHOD === 2){
          dropdownItems[i].click();
          setTimeout(() => {
            const frame = document.querySelector('.msg-modal-delete-convo');
            const delBtn = frame.querySelector('.artdeco-button--primary');
            delBtn.click();
          }, 500);
        }

        // Archive Them Instead
        if (txt === ARCHIVE && METHOD === 1) {
          dropdownItems[i].click();
        }
      }
    }, 1000);
  };
  goneFn();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment