Last active
September 23, 2025 17:19
-
-
Save O1O1O1O/d5ed40482cfa1c5e77394aa6ca6c8f3c to your computer and use it in GitHub Desktop.
Instagram comment activity deletion script from here: https://gist.github.com/sbolel/a2b2bfde16b3ab185fbc2e2049240abc?permalink_comment_id=5756319#gistcomment-5756319
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * This script automates the process of deleting your own Instagram comments. | |
| * It deletes comments in batches to avoid hitting rate limits or breaking the page. | |
| * | |
| * To delete Like activity change the two strings in deleteSelectedComment from 'Delete' to 'Unlike' | |
| * | |
| * WARNING: This function directly manipulates the DOM and depends on the current HTML | |
| * structure of Instagram's website to work. If Instagram implements changes to the | |
| * activity page layout, structure, or functionality, this script may break or cause | |
| * unexpected behavior. Use at your own risk and always review code before running it. | |
| * | |
| * 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. | |
| */ | |
| (async function () { | |
| // Constants | |
| /** @const {number} - The number of comments to delete in each batch. */ | |
| const DELETION_BATCH_SIZE = 20 | |
| /** @const {number} - The delay between actions in milliseconds. */ | |
| const DELAY_BETWEEN_ACTIONS_MS = 700 | |
| /** @const {number} - The delay between clicking the checkboxes in milliseconds. */ | |
| const DELAY_BETWEEN_CHECKBOX_CLICKS_MS = 100 | |
| /** @const {number} - The maximum number of retries for waiting operations */ | |
| const MAX_RETRIES = 60 | |
| /** | |
| * Utility function that delays execution for a given amount of time. | |
| * @param {number} ms - The milliseconds to delay. | |
| * @returns {Promise<void>} A promise that resolves after the specified delay. | |
| */ | |
| const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) | |
| /** | |
| * Utility function that waits for an element to appear in the DOM before resolving. | |
| * @param {string} selector - The CSS selector of the element to wait for. | |
| * @param {number} [timeout=30000] - The maximum time to wait in milliseconds. | |
| * @returns {Promise<Element>} A promise that resolves with the found element. | |
| * @throws {Error} If the element is not found within the timeout period. | |
| */ | |
| const waitForElement = async (tag, selector, timeout = 30000) => { | |
| console.log(`Waiting for ${tag} element with selector "${selector}"...`) | |
| const startTime = Date.now() | |
| while (Date.now() - startTime < timeout) { | |
| const element = Array.from(document.querySelectorAll(tag)).find((el) => el.textContent === selector) | |
| if (element) { | |
| console.log(`Found ${tag} element with selector "${selector}"`) | |
| return element | |
| } | |
| await delay(100) | |
| } | |
| throw new Error(`Element with selector "${selector}" not found within ${timeout}ms`) | |
| } | |
| /** | |
| * Utility function that clicks on a given element. | |
| * @param {Element} element - The element to click. | |
| * @throws {Error} If the element is not found. | |
| */ | |
| const clickElement = async (element) => { | |
| if (!element) throw new Error('Element not found') | |
| element.click() | |
| } | |
| /** | |
| * Deletes the currently selected comments. | |
| * @returns {Promise<void>} A promise that resolves when the comments are deleted. | |
| */ | |
| const deleteSelectedComments = async () => { | |
| try { | |
| const deleteButton = await waitForElement('span', 'Delete') | |
| await clickElement(deleteButton) | |
| await delay(DELAY_BETWEEN_ACTIONS_MS) | |
| const confirmButton = await waitForElement('button', 'Delete') | |
| await clickElement(confirmButton) | |
| await delay(5000) | |
| // Handle Instagram's error dialog | |
| const okButton = await waitForElement('button', 'OK', 10000) | |
| await clickElement(okButton) | |
| console.log('Deleted selected comments') | |
| } catch (error) { | |
| console.error('Error during comment deletion:', error.message) | |
| } | |
| } | |
| /** | |
| * Deletes all user comments by selecting comments in batches. | |
| * @returns {Promise<void>} A promise that resolves when all comments are deleted. | |
| */ | |
| const deleteActivity = async () => { | |
| try { | |
| console.log('Starting deletion process...') | |
| const selectButton = await waitForElement('span', 'Select') | |
| if (!selectButton) throw new Error('Select button not found') | |
| await clickElement(selectButton) | |
| await delay(DELAY_BETWEEN_ACTIONS_MS) | |
| const checkboxes = document.querySelectorAll('[aria-label="Toggle checkbox"]') | |
| if (checkboxes.length === 0) { | |
| console.log('No comments to delete... retrying after delay') | |
| await delay(DELAY_BETWEEN_ACTIONS_MS) | |
| return deleteActivity(); | |
| } | |
| for (let i = 0; i < Math.min(DELETION_BATCH_SIZE, checkboxes.length); i++) { | |
| await clickElement(checkboxes[i]) | |
| await delay(DELAY_BETWEEN_CHECKBOX_CLICKS_MS) | |
| } | |
| await delay(DELAY_BETWEEN_ACTIONS_MS) | |
| await deleteSelectedComments() | |
| deleteActivity(); | |
| } catch (error) { | |
| console.error('Error in deleteActivity:', error.message) | |
| } | |
| } | |
| // Start the deletion process | |
| try { | |
| deleteActivity() | |
| } catch (error) { | |
| console.error('Fatal error:', error.message) | |
| } | |
| })() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment