Guest User

ig unliker

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