-
-
Save sbolel/a2b2bfde16b3ab185fbc2e2049240abc to your computer and use it in GitHub Desktop.
/** | |
* Deletes all user's comments from a specific Instagram page. | |
* This function automates the process of selecting and deleting user comments | |
* from the "Your Activity" section on Instagram. | |
* | |
* How to use: | |
* 1. Navigate to the Instagram comments page by going to: | |
* https://www.instagram.com/your_activity/interactions/comments | |
* 2. Open the developer console in your web browser: | |
* - Chrome/Firefox: Press Ctrl+Shift+J (Windows/Linux) or Cmd+Option+J (Mac) | |
* - Safari: Enable the Develop menu in Safari's Advanced preferences, then press Cmd+Option+C | |
* 3. Copy and paste this entire script into the console and press Enter to run it. | |
* | |
* How to navigate to the comments page on instagram.com: | |
* 1. Log in to Instagram on a desktop browser. | |
* 2. Go to your profile by clicking on the profile icon at the bottom right. | |
* 3. Click on "Your Activity" in the menu. | |
* 4. Select "Interactions" and then "Comments". | |
* 5. Follow the usage steps above to run this script. | |
* | |
* Note: This script directly manipulates the DOM of the Instagram page and might break if Instagram changes their layout or element attributes. | |
* | |
* @async | |
* @function deleteAllUserComments | |
* @description Selects and deletes all comments made by the user on their posts. | |
*/ | |
async function deleteAllUserComments() { | |
const SELECT_BUTTON_INDEX = 1; | |
const DELAY_BETWEEN_ACTIONS_MS = 1000; | |
const DELAY_BETWEEN_CHECKBOX_CLICKS_MS = 150; | |
const SHORT_DELAY_BEFORE_DELETION_MS = 850; | |
// Click the "Select" button to start selection mode. | |
document.querySelectorAll('[role="button"]')[SELECT_BUTTON_INDEX].click(); | |
await delay(DELAY_BETWEEN_ACTIONS_MS); | |
// Select all comments. | |
const checkboxes = document.querySelectorAll('[aria-label="Toggle checkbox"]'); | |
for (let checkbox of checkboxes) { | |
checkbox.click(); | |
await delay(DELAY_BETWEEN_CHECKBOX_CLICKS_MS); | |
} | |
await delay(SHORT_DELAY_BEFORE_DELETION_MS); | |
// Click the "Delete" button and then confirm the deletion. | |
document.querySelector('[aria-label="Delete"]').click(); | |
await delay(DELAY_BETWEEN_ACTIONS_MS); | |
document.querySelector('button[tabindex="0"]').click(); | |
} | |
/** | |
* Delays the execution for a given amount of time. | |
* @param {number} ms The milliseconds to delay. | |
* @returns {Promise} A promise that resolves after the specified delay. | |
*/ | |
function delay(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
// Execute the function to delete all user comments. | |
deleteAllUserComments(); |
Thank you! It works but I encountered an issue.
Running this script at first deleted almost like 40 comments but then Instagram got stuck on loading animation. I tried refreshing the page and running the script again and it again selected around 37 comments but when it pressed the Delete button, I got this error
"There was a problem with deleting some or all of your content. Try deleting it again."
So I made some changes to the script and turned it into a bookmarklet and set it to delete 10 comments every 10 seconds. So there is a cooldown to let the comments page refresh
javascript:(function(){const SELECT_BUTTON_INDEX=1,DELAY_BETWEEN_ACTIONS_MS=1000,DELAY_BETWEEN_CHECKBOX_CLICKS_MS=150,SHORT_DELAY_BEFORE_DELETION_MS=850;function delay(ms){return new Promise(resolve=>setTimeout(resolve,ms));}async function deleteAllUserComments(){document.querySelectorAll('[role="button"]')[SELECT_BUTTON_INDEX].click();await delay(DELAY_BETWEEN_ACTIONS_MS);while(true){const checkboxes=document.querySelectorAll('[aria-label="Toggle checkbox"]');let count=0;for(let checkbox of checkboxes){if(count>=10)break;checkbox.click();await delay(DELAY_BETWEEN_CHECKBOX_CLICKS_MS);count++;}if(count===0)break;await delay(SHORT_DELAY_BEFORE_DELETION_MS);document.querySelector('[aria-label="Delete"]').click();await delay(DELAY_BETWEEN_ACTIONS_MS);document.querySelector('button[tabindex="0"]').click();await delay(DELAY_BETWEEN_ACTIONS_MS);}}setInterval(deleteAllUserComments,10000);})();
@hooperstu you're welcome! I'm glad it was useful for you. It's pretty crazy that there's no other way to bulk delete one's own activity on Instagram.