Skip to content

Instantly share code, notes, and snippets.

@Vlasterx
Last active March 12, 2025 08:33
Show Gist options
  • Save Vlasterx/b244b9b27ade8a6dd7eb2ffd3aae8d99 to your computer and use it in GitHub Desktop.
Save Vlasterx/b244b9b27ade8a6dd7eb2ffd3aae8d99 to your computer and use it in GitHub Desktop.
Delete all LinkedIn posts version for June 2021.
(() => {
let speedMs = 500
setInterval(() => {
let dropdown = document.querySelector('.feed-shared-update-v2__control-menu .artdeco-dropdown button')
dropdown.click()
setTimeout(() => {
let optionDel = dropdown.parentElement.parentElement.parentElement.querySelector('.option-delete .tap-target')
if (optionDel === null) {
setTimeout(() => { window.scrollTo(0,document.body.scrollHeight) }, speedMs * 4)
} else {
optionDel.click()
setTimeout(() => {
document.querySelector('.artdeco-modal .feed-shared-decision-modal__confirm-button').click()
}, speedMs)
}
}, speedMs)
}, speedMs)
})()
@KHannibal
Copy link

Works like a charm, thanks ! Could you add a refresh function or a click on the "Show more results" button after X iterations ?

@BilalTariq01
Copy link

BilalTariq01 commented Nov 7, 2023

2023 updated version

(() => {
  let speedMs = 500

  setInterval(() => {
    let dropdown = document.querySelector('.feed-shared-update-v2__control-menu .artdeco-dropdown button')

    dropdown.click()

    setTimeout(() => {
      let optionDel = dropdown.parentElement.parentElement.parentElement.querySelector('.option-delete .tap-target')
      
      if (optionDel === null) {
        // setTimeout(() => { window.scrollTo(0,document.body.scrollHeight) }, speedMs * 4)
      } else {
        optionDel.click()
  
        setTimeout(() => {
          document.querySelector('.artdeco-modal .feed-components-shared-decision-modal__confirm-button').click()
        }, speedMs)
      }
    }, speedMs)
  }, speedMs)
})()

@Rideout421
Copy link

Having to click the delete button each time for the post to remove. One click is much better then the alternative. Thank you

@GoLangCentral
Copy link

Added Step:

  • Once you see the delete pop-up modal, hover your mouse over the 'Delete' button and then go grab a coffee  ☕
(() => {
  let speedMs = 500
  let clickDelay = 2000 // 2 seconds delay before right-click

  function performRightClickInsideModal() {
    let deleteButton = document.querySelector('.artdeco-modal .artdeco-button.artdeco-button--primary.artdeco-button--2');

    if (deleteButton) {
      for (let i = 0; i < 3; i++) {
        setTimeout(() => {
          let event = new MouseEvent('contextmenu', {
            bubbles: true,
            cancelable: true,
            view: window
          });
          deleteButton.dispatchEvent(event);
        }, clickDelay * i);
      }
    }
  }

  setInterval(() => {
    let dropdown = document.querySelector('.feed-shared-update-v2__control-menu .artdeco-dropdown button');

    if (dropdown) {
      dropdown.click();

      setTimeout(() => {
        let optionDel = dropdown.parentElement.parentElement.parentElement.querySelector('.option-delete .tap-target');

        if (optionDel === null) {
          // Optionally scroll down if no delete option found
          // setTimeout(() => { window.scrollTo(0, document.body.scrollHeight) }, speedMs * 4);
        } else {
          optionDel.click();

          setTimeout(() => {
            // Wait for the confirmation modal to appear and then click the "Delete" button
            let confirmButton = document.querySelector('.artdeco-modal .feed-components-shared-decision-modal__buttons-container .artdeco-button.artdeco-button--primary.artdeco-button--2');
            if (confirmButton) {
              confirmButton.click();

              // Call the right-click function after clicking the "Delete" button
              setTimeout(() => {
                performRightClickInsideModal();
              }, speedMs);
            }
          }, speedMs);
        }
      }, speedMs);
    }
  }, speedMs);
})();

@tmtri3102
Copy link

It's 2025 and just wanna confirm that the latest version by @rustrider works like a charm. Thank you and Happy New year.

@obar1
Copy link

obar1 commented Mar 12, 2025

@Vlasterx
Copy link
Author

Vlasterx commented Mar 12, 2025

any web fren could do comments too? https://www.linkedin.com/in/{user_id}/recent-activity/comments/ image

Delete LinkedIn comments AND unlike posts

I used to use this one, while I was on LinkedIn. I don't know if it works today.
Open a profile page with your comments and run this bookmarklet. It will delete your comments AND unlike other posts at the same time. You can watch in console log how it goes.

Just be sure to change accountHref and accountName.

(() => {
  let speedMs = 500
  let accountHref = '/in/your-account-url/' // Change this to your account URL
  let accountName = 'Your Account Name' // Change this to your account name
  let nameMatch = new RegExp(accountName, 'gi')
  let commentNo = 0
  let likeNo = 0
  window.scrollTo(0, document.body.scrollHeight)

  setInterval(() => {
    setTimeout(() => {
      window.scrollTo(0, document.body.scrollHeight)
    }, speedMs * 4)

    let dropdown = document
      .querySelector(`.comments-post-meta a[href="${accountHref}"]`)
      .parentElement.parentElement.parentElement.querySelector(
        '.social-details-social-activity .artdeco-dropdown button'
      )

    let liked1 = document.querySelector('[aria-label^="Unlike"]')

    let liked2 = document.querySelector(
      '[aria-label^="Like"][aria-pressed="true"]'
    )

    if (dropdown !== null || liked1 !== null || liked2 !== null) {
      if (dropdown !== null && nameMatch.test(dropdown.innerHTML)) {
        dropdown.click()

        setTimeout(() => {
          let openDropdown =
            dropdown.parentElement.parentElement.parentElement.querySelectorAll(
              '.artdeco-dropdown__content ul li .option-button'
            )

          let deleteBtn = Array.from(openDropdown).filter(
            (item) => item.innerText === 'Delete'
          )

          setTimeout(() => {
            deleteBtn[0].click()

            setTimeout(() => {
              let modalButtons = document.querySelectorAll(
                '.artdeco-modal__actionbar button'
              )

              let modalDeleteBtn = Array.from(modalButtons).filter(
                (item) => item.innerText === 'Delete'
              )

              modalDeleteBtn[0].click()
              commentNo++
              console.log(`Deleted comment ${commentNo}`)
            }, speedMs)
          }, speedMs)
        }, speedMs)
      }

      if (liked1) {
        setTimeout(() => {
          liked1.click()
          liked1.remove()
          likeNo++
          console.info(`Unliked comment ${likeNo}`)
        }, speedMs)
      }

      if (liked2) {
        setTimeout(() => {
          liked2.click()
          liked2.remove()
          likeNo++
          console.info(`Unliked comment ${likeNo}`)
        }, speedMs)
      }
    } else {
      setTimeout(() => {
        window.scrollTo(0, document.body.scrollHeight)
      }, speedMs * 4)
    }
  }, speedMs)
})()

When you change this, minimize JS and then put that code in here and add it to bookmark URL.

javascript:/* PLACE MINIMIZED CODE HERE */;

You will need to run this several times, because LinkedIn doesn't display all of your content at once.

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