Skip to content

Instantly share code, notes, and snippets.

@GoLangCentral
Last active March 19, 2025 15:48
Show Gist options
  • Save GoLangCentral/8e35c1a5385650a7468746ecf122a4df to your computer and use it in GitHub Desktop.
Save GoLangCentral/8e35c1a5385650a7468746ecf122a4df to your computer and use it in GitHub Desktop.
How to Bulk Delete All Your LinkedIn Comments, delete all LinkedIn Comments on 1 click 2024

Instructions

Unleash your inner tech wizard: Open the console log of your browser (yep, the magical "inspect" option).

  • Past and enter.
  • Time for a coffee break: Go get some coffee ☕—you’ve earned it!

No need to worry, there’s absolutely no malicious code here. Feel free to send it to an AI check for extra peace of mind. 😊

The Script

 /**
 * Halts execution for a certain amount of seconds.
 * @param {number} seconds - Number of seconds to sleep.
 * @returns {Promise} - A promise that resolves after the specified time.
 */
function sleep(seconds) {
    return new Promise(resolve => setTimeout(resolve, seconds * 1000));
}

/**
 * Gets all the dropdown elements for comments authored by the user.
 * @returns {Array} - An array of dropdown elements.
 */
function getDeleteCommentDropdowns() {
    return Array.from(document.querySelectorAll(
        ".comment-options-trigger .artdeco-dropdown__trigger"
    ));
}

/**
 * Gets the "Delete" button inside the confirmation dialog.
 * @returns {HTMLElement|null} - The delete confirmation button element.
 */
function getDeleteConfirmationButton() {
    return document.querySelector(
        "button.artdeco-button.artdeco-button--2.artdeco-button--primary.ember-view"
    );
}

/**
 * Gets the "Dismiss" button inside the modal.
 * @returns {HTMLElement|null} - The dismiss button element.
 */
function getDismissButton() {
    return document.querySelector(
        "button.artdeco-button.artdeco-button--circle.artdeco-button--muted.artdeco-button--2.artdeco-button--tertiary.ember-view.artdeco-modal__dismiss"
    );
}

/**
 * Clicks the dismiss button multiple times with an interval.
 */
async function clickDismissButtonMultipleTimes() {
    var dismissButton = getDismissButton();
    if (dismissButton) {
        for (let i = 0; i < 3; i++) {
            dismissButton.click();
            await sleep(1); // Wait for 1 second between clicks
        }
    }
}

/**
 * Deletes a comment by clicking the confirmation button.
 */
async function deleteComment() {
    await sleep(1); // Shorter sleep before clicking

    var deleteConfirmationButton = getDeleteConfirmationButton();
    if (deleteConfirmationButton) {
        deleteConfirmationButton.click();
        await sleep(1); // Wait for the action to register
        await clickDismissButtonMultipleTimes();
    }
}

/**
 * Deletes all comments by iterating through the dropdowns and clicking the delete option.
 */
async function deleteActivity() {
    var deleteDropdowns = getDeleteCommentDropdowns();
    for (var i = 0; i < deleteDropdowns.length; i++) {
        deleteDropdowns[i].click();
        await sleep(1); // Shorter sleep for dropdown to open

        var deleteOption = Array.from(document.querySelectorAll(
            ".dropdown-options .artdeco-dropdown__item"
        )).find(item => item.textContent.includes("Delete"));

        if (deleteOption) {
            deleteOption.click();
            await deleteComment();
        }

        await sleep(2); // Shorter sleep for deletion to complete
    }
}

/**
 * Clicks the "Show more results" button to load additional comments.
 */
async function clickShowMoreResults() {
    var showMoreButton = document.querySelector(
        "button.artdeco-button.artdeco-button--muted.artdeco-button--1.artdeco-button--full.artdeco-button--secondary.ember-view.scaffold-finite-scroll__load-button"
    );
    if (showMoreButton) {
        showMoreButton.click();
        await sleep(2); // Wait for new comments to load
    }
}

/**
 * Initializes the comment deletion process and continues if there are more comments.
 */
async function init() {
    console.log("*** Starting activity deletion ***");
    console.log(">>> Deleting comments");

    while (true) {
        await deleteActivity();

        // Click the "Show more results" button to load more comments
        await clickShowMoreResults();
        
        // Wait before checking for more comments
        await sleep(2); // Adjust if needed for faster or slower page loading
    }
}

// Start the script
init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment