Skip to content

Instantly share code, notes, and snippets.

@mustafadalga
Created January 6, 2025 09:56
Show Gist options
  • Save mustafadalga/6120da330c6452e2b09be75d9ecb7b43 to your computer and use it in GitHub Desktop.
Save mustafadalga/6120da330c6452e2b09be75d9ecb7b43 to your computer and use it in GitHub Desktop.
Linkedin Cancel All Old Invitations
async function cancelOldInvitations() {
const list = document.querySelectorAll(".invitation-card.artdeco-list__item");
const old = [
"Sent 1 months ago", "Sent 2 months ago", "Sent 3 weeks ago",
"Sent 2 weeks ago",
"Sent 3 months ago", "Sent 4 months ago", "Sent 5 months ago"
];
for (let row of [...list]) {
if (old.some(time => row.textContent.includes(time))) {
const btn = row.querySelector(".invitation-card__action-btn");
if (btn){
btn.click();
// Random delay between 500ms and 2000ms
const randomDelay = Math.floor(Math.random() * (2500 - 700 + 1)) + 700;
await new Promise(resolve => setTimeout(resolve, randomDelay));
// Wait for the modal to appear (you might need a better selector)
//this wait is here because it take a little time for the button to appear
await new Promise(resolve => setTimeout(resolve, 100));
const cancelbtn = document.querySelector(".artdeco-button.artdeco-button--2.artdeco-button--primary.ember-view.artdeco-modal__confirm-dialog-btn");
if (cancelbtn){
cancelbtn.click();
}
}
await new Promise(resolve => setTimeout(resolve, 100)); // tiny wait to the dom to update
}
}
}
cancelOldInvitations(); // Start the process
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment