Guest User

ig delete comment

a guest
May 13th, 2026
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.73 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Instagram Comment Auto-Deleter
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Automatically deletes all Instagram comments
  6. // @author you
  7. // @match https://www.instagram.com/your_activity/interactions/comments*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. const BATCH_SIZE = 6;
  15. const PAUSE_BETWEEN_BATCHES = 15000;
  16. const MAX_BATCHES = 10000;
  17. const STUCK_TIMEOUT = 20000;
  18.  
  19. const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
  20.  
  21. const saveProgress = (batchCount, totalDeleted) => {
  22. sessionStorage.setItem('ig_delete_running', 'true');
  23. sessionStorage.setItem('ig_delete_batch', batchCount);
  24. sessionStorage.setItem('ig_delete_total', totalDeleted);
  25. };
  26.  
  27. const loadProgress = () => {
  28. return {
  29. running: sessionStorage.getItem('ig_delete_running') === 'true',
  30. batchCount: parseInt(sessionStorage.getItem('ig_delete_batch') || '0'),
  31. totalDeleted: parseInt(sessionStorage.getItem('ig_delete_total') || '0')
  32. };
  33. };
  34.  
  35. const clearProgress = () => {
  36. sessionStorage.removeItem('ig_delete_running');
  37. sessionStorage.removeItem('ig_delete_batch');
  38. sessionStorage.removeItem('ig_delete_total');
  39. };
  40.  
  41. const humanClick = (el) => {
  42. const rect = el.getBoundingClientRect();
  43. const x = rect.left + rect.width / 2;
  44. const y = rect.top + rect.height / 2;
  45. const eventOptions = {
  46. bubbles: true,
  47. cancelable: true,
  48. view: window,
  49. clientX: x,
  50. clientY: y,
  51. screenX: x,
  52. screenY: y,
  53. buttons: 1
  54. };
  55. el.dispatchEvent(new MouseEvent('mouseover', eventOptions));
  56. el.dispatchEvent(new MouseEvent('mouseenter', eventOptions));
  57. el.dispatchEvent(new MouseEvent('mousemove', eventOptions));
  58. el.dispatchEvent(new MouseEvent('mousedown', eventOptions));
  59. el.dispatchEvent(new MouseEvent('mouseup', eventOptions));
  60. el.dispatchEvent(new MouseEvent('click', eventOptions));
  61. };
  62.  
  63. const findSelectButton = () => {
  64. return Array.from(document.querySelectorAll('[data-bloks-name="bk.components.Flexbox"]'))
  65. .find(el => {
  66. const style = el.getAttribute('style') || '';
  67. return el.textContent.trim() === 'Select' && style.includes('cursor: pointer');
  68. });
  69. };
  70.  
  71. const findDeleteButton = () => {
  72. return Array.from(document.querySelectorAll('[data-bloks-name="bk.components.Flexbox"]'))
  73. .find(el => {
  74. const style = el.getAttribute('style') || '';
  75. return el.textContent.trim() === 'Delete' && style.includes('cursor: pointer');
  76. });
  77. };
  78.  
  79. const findConfirmDeleteButton = () => {
  80. return Array.from(document.querySelectorAll('button'))
  81. .find(el => el.textContent.trim() === 'Delete');
  82. };
  83.  
  84. const checkForErrorPopup = () => {
  85. const okBtn = Array.from(document.querySelectorAll('button'))
  86. .find(el => el.textContent.trim() === 'OK');
  87. if (okBtn) {
  88. console.log('⚠️ Error popup detected! Clicking OK and continuing...');
  89. humanClick(okBtn);
  90. return true;
  91. }
  92. return false;
  93. };
  94.  
  95. const waitForSelectButton = async () => {
  96. const startTime = Date.now();
  97. console.log('Waiting for Select button...');
  98.  
  99. while (true) {
  100. if (checkForErrorPopup()) {
  101. await sleep(3000);
  102. }
  103.  
  104. const selectBtn = findSelectButton();
  105. if (selectBtn) return selectBtn;
  106.  
  107. if (Date.now() - startTime > STUCK_TIMEOUT) {
  108. console.log('⚠️ Page stuck! Saving progress and refreshing...');
  109. return null;
  110. }
  111.  
  112. await sleep(1000);
  113. }
  114. };
  115.  
  116. const getCommentRows = () => {
  117. return Array.from(document.querySelectorAll('[role="button"][data-bloks-name="bk.components.Flexbox"]'))
  118. .filter(el => {
  119. const style = el.getAttribute('style') || '';
  120. const text = el.textContent.trim();
  121. return style.includes('flex-grow: 1') &&
  122. style.includes('cursor: pointer') &&
  123. text.length > 0;
  124. });
  125. };
  126.  
  127. async function deleteLoop() {
  128. // Wait for page to fully load before doing anything
  129. await sleep(5000);
  130.  
  131. const progress = loadProgress();
  132. let batchCount = progress.batchCount;
  133. let totalDeleted = progress.totalDeleted;
  134.  
  135. if (progress.running) {
  136. console.log(`♻️ Resuming after page refresh — Batch ${batchCount + 1}, ${totalDeleted} deleted so far`);
  137. } else {
  138. console.log('🚀 Instagram Comment Deleter starting...');
  139. }
  140.  
  141. while (batchCount < MAX_BATCHES) {
  142. console.log(`\n--- Batch ${batchCount + 1} ---`);
  143.  
  144. if (checkForErrorPopup()) {
  145. await sleep(3000);
  146. }
  147.  
  148. const selectBtn = await waitForSelectButton();
  149.  
  150. if (!selectBtn) {
  151. saveProgress(batchCount, totalDeleted);
  152. console.log('Refreshing page, will auto-resume...');
  153. await sleep(1000);
  154. window.location.reload();
  155. return;
  156. }
  157.  
  158. humanClick(selectBtn);
  159. console.log('Clicked Select, waiting for UI...');
  160. await sleep(1500);
  161.  
  162. if (checkForErrorPopup()) {
  163. await sleep(3000);
  164. continue;
  165. }
  166.  
  167. const rows = getCommentRows();
  168. console.log(`Found ${rows.length} comment rows in DOM`);
  169. if (rows.length === 0) {
  170. console.log('No comment rows found. Done.');
  171. clearProgress();
  172. break;
  173. }
  174.  
  175. let selectedCount = 0;
  176. for (let row of rows) {
  177. if (selectedCount >= BATCH_SIZE) break;
  178. humanClick(row);
  179. selectedCount++;
  180. await sleep(300);
  181. }
  182. console.log(`Selected ${selectedCount} comments, clicking Delete...`);
  183. await sleep(1000);
  184.  
  185. if (checkForErrorPopup()) {
  186. await sleep(3000);
  187. continue;
  188. }
  189.  
  190. const deleteBtn = findDeleteButton();
  191. if (!deleteBtn) {
  192. console.log('Delete button not found. Stopping.');
  193. clearProgress();
  194. break;
  195. }
  196. humanClick(deleteBtn);
  197. console.log('Clicked Delete, waiting for confirmation popup...');
  198. await sleep(3000);
  199.  
  200. if (checkForErrorPopup()) {
  201. await sleep(3000);
  202. continue;
  203. }
  204.  
  205. let confirmed = false;
  206. for (let attempt = 0; attempt < 5; attempt++) {
  207. if (checkForErrorPopup()) {
  208. await sleep(3000);
  209. confirmed = true;
  210. break;
  211. }
  212.  
  213. const confirmBtn = findConfirmDeleteButton();
  214. if (confirmBtn) {
  215. console.log(`Found native Delete button, clicking... (attempt ${attempt + 1})`);
  216. humanClick(confirmBtn);
  217. await sleep(2000);
  218.  
  219. if (checkForErrorPopup()) {
  220. await sleep(3000);
  221. confirmed = true;
  222. break;
  223. }
  224.  
  225. const stillThere = findConfirmDeleteButton();
  226. if (!stillThere) {
  227. console.log('Popup dismissed successfully!');
  228. confirmed = true;
  229. break;
  230. } else {
  231. console.log('Popup still visible, retrying...');
  232. }
  233. } else {
  234. console.log(`Confirmation button not found yet, retrying (${attempt + 1}/5)...`);
  235. await sleep(1000);
  236. }
  237. }
  238.  
  239. if (!confirmed) {
  240. console.log('Could not dismiss confirmation popup. Stopping.');
  241. clearProgress();
  242. break;
  243. }
  244.  
  245. totalDeleted += selectedCount;
  246. batchCount++;
  247. console.log(`✓ Batch ${batchCount} done (${totalDeleted} total deleted). Pausing ${PAUSE_BETWEEN_BATCHES/1000}s...`);
  248. await sleep(PAUSE_BETWEEN_BATCHES);
  249. }
  250.  
  251. console.log(`\n✅ Finished! Batches: ${batchCount}, Total deleted: ${totalDeleted}`);
  252. clearProgress();
  253. }
  254.  
  255. deleteLoop();
  256. })();
Advertisement
Add Comment
Please, Sign In to add comment