Skip to content

Instantly share code, notes, and snippets.

@phixion
Created September 20, 2026 00:28
Show Gist options
  • Select an option

  • Save phixion/81ccadfb6b1b1915f3188b06839d8ffd to your computer and use it in GitHub Desktop.

Select an option

Save phixion/81ccadfb6b1b1915f3188b06839d8ffd to your computer and use it in GitHub Desktop.
delete-insta-comments
// Instagram doesn't allow to select all your posts, or all your comments, etc. to delete them.
// You can only select them one by one. This is slow as hell.
// Use this to select all the photos, comments, etc.
// 1. Open this page: https://www.instagram.com/your_activity/interactions/comments
// 2. Press the F12 key to open the developer tools
// 3. open the console tab in the developer tools
// 4. copy-paste the following code in the command prompt of the console and press enter
(async function autoLoopDeleteComments() {
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const triggerClick = (el) => {
['mousedown', 'mouseup', 'click'].forEach((eventType) => {
el.dispatchEvent(new MouseEvent(eventType, { bubbles: true, cancelable: true, view: window }));
});
};
const findButtonByText = (text) => {
return Array.from(document.querySelectorAll('div, button, span'))
.find(el => el.children.length === 0 && el.textContent.trim().toLowerCase() === text.toLowerCase());
};
while (true) {
console.log('starting new run');
const selectBtn = findButtonByText('Auswählen') || findButtonByText('Select');
if (selectBtn) {
triggerClick(selectBtn.closest('div[role="button"]') || selectBtn);
await delay(200);
}
const icons = Array.from(document.querySelectorAll('div.wbloks_1'))
.filter(el => {
const style = el.getAttribute('style') || '';
return style.includes('circle__outline__24-4x.png') || style.includes('circle__outline');
});
if (icons.length === 0) {
console.log('wait 7 seconds...');
await delay(7000);
continue;
}
for (const icon of icons) {
const target = icon.closest('div[role="button"]') || icon.closest('div[tabindex="0"]') || icon.parentElement?.parentElement;
if (target) {
let retries = 0;
while ((icon.getAttribute('style') || '').includes('circle__outline') && retries < 3) {
triggerClick(target);
retries++;
await delay(40);
}
}
}
await delay(150);
const initialDelete = findButtonByText('Löschen') || findButtonByText('Delete');
if (initialDelete) {
triggerClick(initialDelete.closest('button, div[role="button"]') || initialDelete);
}
let attempts = 0;
while (attempts < 5) {
await delay(200);
const popupBtn = document.querySelector('button._a9--._ap36._a9_1') ||
document.querySelector('button._a9--') ||
findButtonByText('Löschen') ||
findButtonByText('Delete');
if (!popupBtn) break;
triggerClick(popupBtn);
attempts++;
}
console.log('finished! wait 7 seconds...');
await delay(7000);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment