Guest User

ig delete story reply

a guest
May 13th, 2026
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.83 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Instagram Story Reply Deleter
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Automatically deletes all Instagram story replies
  6. // @author you
  7. // @match https://www.instagram.com/your_activity/interactions/story_replies*
  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_storyreply_running', 'true');
  23. sessionStorage.setItem('ig_storyreply_batch', batchCount);
  24. sessionStorage.setItem('ig_storyreply_total', totalDeleted);
  25. };
  26.  
  27. const loadProgress = () => {
  28. return {
  29. running: sessionStorage.getItem('ig_storyreply_running') === 'true',
  30. batchCount: parseInt(sessionStorage.getItem('ig_storyreply_batch') || '0'),
  31. totalDeleted: parseInt(sessionStorage.getItem('ig_storyreply_total') || '0')
  32. };
  33. };
  34.  
  35. const clearProgress = () => {
  36. sessionStorage.removeItem('ig_storyreply_running');
  37. sessionStorage.removeItem('ig_storyreply_batch');
  38. sessionStorage.removeItem('ig_storyreply_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. const nativeBtn = Array.from(document.querySelectorAll('button'))
  81. .find(el => el.textContent.trim() === 'Delete');
  82. if (nativeBtn) return nativeBtn;
  83.  
  84. const bloksBtn = Array.from(document.querySelectorAll('[data-bloks-name="bk.components.Flexbox"]'))
  85. .find(el => {
  86. const style = el.getAttribute('style') || '';
  87. return el.textContent.trim() === 'Delete' && style.includes('cursor: pointer');
  88. });
  89. if (bloksBtn) return bloksBtn;
  90.  
  91. return null;
  92. };
  93.  
  94. const checkForErrorPopup = () => {
  95. const okBtn = Array.from(document.querySelectorAll('button'))
  96. .find(el => el.textContent.trim() === 'OK');
  97. if (okBtn) {
  98. console.log('⚠️ Error popup detected! Clicking OK and continuing...');
  99. humanClick(okBtn);
  100. return true;
  101. }
  102. return false;
  103. };
  104.  
  105. const waitForSelectButton = async () => {
  106. const startTime = Date.now();
  107. console.log('⏳ Waiting for Select button...');
  108.  
  109. while (true) {
  110. if (checkForErrorPopup()) {
  111. await sleep(3000);
  112. }
  113.  
  114. const selectBtn = findSelectButton();
  115. if (selectBtn) return selectBtn;
  116.  
  117. if (Date.now() - startTime > STUCK_TIMEOUT) {
  118. console.log('⚠️ Page stuck! Saving progress and refreshing...');
  119. return null;
  120. }
  121.  
  122. const waited = Math.round((Date.now() - startTime) / 1000);
  123. console.log(`⏳ Still waiting for Select button... ${waited}s elapsed`);
  124. await sleep(1000);
  125. }
  126. };
  127.  
  128. const getReplyRows = () => {
  129. return Array.from(document.querySelectorAll('[role="button"][data-bloks-name="bk.components.Flexbox"]'))
  130. .filter(el => {
  131. return el.getAttribute('aria-label') === 'Image with button';
  132. });
  133. };
  134.  
  135. (async function deleteLoop() {
  136. await sleep(5000);
  137.  
  138. const progress = loadProgress();
  139. let batchCount = progress.batchCount;
  140. let totalDeleted = progress.totalDeleted;
  141.  
  142. if (progress.running) {
  143. console.log(`♻️ Resuming after page refresh — Batch ${batchCount + 1}, ${totalDeleted} deleted so far`);
  144. } else {
  145. console.log('🚀 Instagram Story Reply Deleter starting...');
  146. }
  147.  
  148. while (batchCount < MAX_BATCHES) {
  149. console.log(`\n--- Batch ${batchCount + 1} | Total deleted so far: ${totalDeleted} ---`);
  150.  
  151. if (checkForErrorPopup()) {
  152. await sleep(3000);
  153. }
  154.  
  155. const selectBtn = await waitForSelectButton();
  156.  
  157. if (!selectBtn) {
  158. saveProgress(batchCount, totalDeleted);
  159. console.log('Refreshing page, will auto-resume...');
  160. await sleep(1000);
  161. window.location.reload();
  162. return;
  163. }
  164.  
  165. humanClick(selectBtn);
  166. console.log('✓ Clicked Select, waiting for UI...');
  167. await sleep(1500);
  168.  
  169. if (checkForErrorPopup()) {
  170. await sleep(3000);
  171. continue;
  172. }
  173.  
  174. const rows = getReplyRows();
  175. console.log(`📋 Found ${rows.length} reply rows in DOM`);
  176. if (rows.length === 0) {
  177. console.log('No reply rows found. All done!');
  178. clearProgress();
  179. break;
  180. }
  181.  
  182. let selectedCount = 0;
  183. for (let row of rows) {
  184. if (selectedCount >= BATCH_SIZE) break;
  185. humanClick(row);
  186. selectedCount++;
  187. console.log(` ☑️ Selected reply ${selectedCount}/${BATCH_SIZE}`);
  188. await sleep(300);
  189. }
  190. console.log(`✓ Selected ${selectedCount} replies, looking for Delete button...`);
  191. await sleep(1000);
  192.  
  193. if (checkForErrorPopup()) {
  194. await sleep(3000);
  195. continue;
  196. }
  197.  
  198. const deleteBtn = findDeleteButton();
  199. if (!deleteBtn) {
  200. console.log('Delete button not found. Dumping visible bloks buttons:');
  201. Array.from(document.querySelectorAll('[data-bloks-name="bk.components.Flexbox"]'))
  202. .forEach(el => {
  203. const t = el.textContent.trim();
  204. const s = el.getAttribute('style') || '';
  205. if (t && t.length < 30) console.log(` "${t}" | style="${s.substring(0, 60)}"`);
  206. });
  207. clearProgress();
  208. break;
  209. }
  210.  
  211. humanClick(deleteBtn);
  212. console.log('✓ Clicked Delete, waiting for confirmation popup...');
  213. await sleep(3000);
  214.  
  215. if (checkForErrorPopup()) {
  216. await sleep(3000);
  217. continue;
  218. }
  219.  
  220. let confirmed = false;
  221. for (let attempt = 0; attempt < 5; attempt++) {
  222. if (checkForErrorPopup()) {
  223. await sleep(3000);
  224. confirmed = true;
  225. break;
  226. }
  227.  
  228. const confirmBtn = findConfirmDeleteButton();
  229. if (confirmBtn) {
  230. console.log(`✓ Found confirmation Delete button, clicking... (attempt ${attempt + 1})`);
  231. humanClick(confirmBtn);
  232. await sleep(2000);
  233.  
  234. if (checkForErrorPopup()) {
  235. await sleep(3000);
  236. confirmed = true;
  237. break;
  238. }
  239.  
  240. const stillThere = findConfirmDeleteButton();
  241. if (!stillThere) {
  242. console.log('✓ Popup dismissed successfully!');
  243. confirmed = true;
  244. break;
  245. } else {
  246. console.log('Popup still visible, retrying...');
  247. }
  248. } else {
  249. console.log(`Confirmation button not found (attempt ${attempt + 1}/5). Visible buttons:`);
  250. Array.from(document.querySelectorAll('button')).forEach(el => {
  251. const t = el.textContent.trim();
  252. if (t) console.log(` button: "${t}"`);
  253. });
  254. await sleep(1000);
  255. }
  256. }
  257.  
  258. if (!confirmed) {
  259. console.log('Could not dismiss confirmation popup. Stopping.');
  260. clearProgress();
  261. break;
  262. }
  263.  
  264. totalDeleted += selectedCount;
  265. batchCount++;
  266. console.log(`\n✅ Batch ${batchCount} complete! Total deleted: ${totalDeleted}`);
  267. console.log(`⏳ Pausing ${PAUSE_BETWEEN_BATCHES / 1000}s before next batch...`);
  268. await sleep(PAUSE_BETWEEN_BATCHES);
  269. }
  270.  
  271. console.log(`\n🎉 All done! Batches completed: ${batchCount}, Total deleted: ${totalDeleted}`);
  272. clearProgress();
  273. })();
  274. })();
Advertisement
Add Comment
Please, Sign In to add comment